mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-08-16 20:26:06 +00:00
Restore from PodVolumeBackups (#1723)
* Restore from PodVolumeBackups Signed-off-by: Carlisia <carlisiac@vmware.com> * Partially address code reviews Signed-off-by: Carlisia <carlisiac@vmware.com> * Partially address code reviews #2 Signed-off-by: Carlisia <carlisiac@vmware.com> * Clean up struct Signed-off-by: Carlisia <carlisiac@vmware.com> * Fix log messages Signed-off-by: Carlisia <carlisiac@vmware.com> * Fix tests Signed-off-by: Carlisia <carlisiac@vmware.com> * Clean up Signed-off-by: Carlisia <carlisiac@vmware.com> * Add changelog Signed-off-by: Carlisia <carlisiac@vmware.com>
This commit is contained in:
committed by
Adnan Abdulhussein
parent
4e1b1f9457
commit
4accb8512a
@@ -43,6 +43,7 @@ import (
|
||||
"github.com/heptio/velero/pkg/metrics"
|
||||
"github.com/heptio/velero/pkg/persistence"
|
||||
"github.com/heptio/velero/pkg/plugin/clientmgmt"
|
||||
"github.com/heptio/velero/pkg/restic"
|
||||
pkgrestore "github.com/heptio/velero/pkg/restore"
|
||||
"github.com/heptio/velero/pkg/util/collections"
|
||||
kubeutil "github.com/heptio/velero/pkg/util/kube"
|
||||
@@ -75,7 +76,7 @@ type restoreController struct {
|
||||
|
||||
namespace string
|
||||
restoreClient velerov1client.RestoresGetter
|
||||
backupClient velerov1client.BackupsGetter
|
||||
podVolumeBackupClient velerov1client.PodVolumeBackupsGetter
|
||||
restorer pkgrestore.Restorer
|
||||
backupLister listers.BackupLister
|
||||
restoreLister listers.RestoreLister
|
||||
@@ -94,7 +95,7 @@ func NewRestoreController(
|
||||
namespace string,
|
||||
restoreInformer informers.RestoreInformer,
|
||||
restoreClient velerov1client.RestoresGetter,
|
||||
backupClient velerov1client.BackupsGetter,
|
||||
podVolumeBackupClient velerov1client.PodVolumeBackupsGetter,
|
||||
restorer pkgrestore.Restorer,
|
||||
backupInformer informers.BackupInformer,
|
||||
backupLocationInformer informers.BackupStorageLocationInformer,
|
||||
@@ -110,7 +111,7 @@ func NewRestoreController(
|
||||
genericController: newGenericController("restore", logger),
|
||||
namespace: namespace,
|
||||
restoreClient: restoreClient,
|
||||
backupClient: backupClient,
|
||||
podVolumeBackupClient: podVolumeBackupClient,
|
||||
restorer: restorer,
|
||||
backupLister: backupInformer.Lister(),
|
||||
restoreLister: restoreInformer.Lister(),
|
||||
@@ -435,13 +436,32 @@ func (c *restoreController) runValidatedRestore(restore *api.Restore, info backu
|
||||
}
|
||||
defer closeAndRemoveFile(backupFile, c.logger)
|
||||
|
||||
opts := restic.NewPodVolumeBackupListOptions(restore.Spec.BackupName)
|
||||
podVolumeBackupList, err := c.podVolumeBackupClient.PodVolumeBackups(c.namespace).List(opts)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
volumeSnapshots, err := info.backupStore.GetBackupVolumeSnapshots(restore.Spec.BackupName)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error fetching volume snapshots metadata")
|
||||
}
|
||||
|
||||
restoreLog.Info("starting restore")
|
||||
restoreWarnings, restoreErrors := c.restorer.Restore(restoreLog, restore, info.backup, volumeSnapshots, backupFile, actions, c.snapshotLocationLister, pluginManager)
|
||||
|
||||
var podVolumeBackups []*velerov1api.PodVolumeBackup
|
||||
for i := range podVolumeBackupList.Items {
|
||||
podVolumeBackups = append(podVolumeBackups, &podVolumeBackupList.Items[i])
|
||||
}
|
||||
restoreReq := pkgrestore.Request{
|
||||
Log: restoreLog,
|
||||
Restore: restore,
|
||||
Backup: info.backup,
|
||||
PodVolumeBackups: podVolumeBackups,
|
||||
VolumeSnapshots: volumeSnapshots,
|
||||
BackupReader: backupFile,
|
||||
}
|
||||
restoreWarnings, restoreErrors := c.restorer.Restore(restoreReq, actions, c.snapshotLocationLister, pluginManager)
|
||||
restoreLog.Info("restore completed")
|
||||
|
||||
if logReader, err := restoreLog.done(c.logger); err != nil {
|
||||
|
||||
@@ -19,7 +19,6 @@ package controller
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -608,7 +607,7 @@ func TestProcessQueueItem(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
velerotest.ValidatePatch(t, actions[1], expected, decode)
|
||||
velerotest.ValidatePatch(t, actions[2], expected, decode)
|
||||
|
||||
// explicitly capturing the argument passed to Restore myself because
|
||||
// I want to validate the called arg as of the time of calling, but
|
||||
@@ -822,18 +821,14 @@ type fakeRestorer struct {
|
||||
}
|
||||
|
||||
func (r *fakeRestorer) Restore(
|
||||
log logrus.FieldLogger,
|
||||
restore *api.Restore,
|
||||
backup *api.Backup,
|
||||
volumeSnapshots []*volume.Snapshot,
|
||||
backupReader io.Reader,
|
||||
info pkgrestore.Request,
|
||||
actions []velero.RestoreItemAction,
|
||||
snapshotLocationLister listers.VolumeSnapshotLocationLister,
|
||||
volumeSnapshotterGetter pkgrestore.VolumeSnapshotterGetter,
|
||||
) (pkgrestore.Result, pkgrestore.Result) {
|
||||
res := r.Called(log, restore, backup, backupReader, actions)
|
||||
res := r.Called(info.Log, info.Restore, info.Backup, info.BackupReader, actions)
|
||||
|
||||
r.calledWithArg = *restore
|
||||
r.calledWithArg = *info.Restore
|
||||
|
||||
return res.Get(0).(pkgrestore.Result), res.Get(1).(pkgrestore.Result)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user