Skip to content

Commit

Permalink
Fix restore error with flag namespace-mappings
Browse files Browse the repository at this point in the history
Signed-off-by: Ming <mqiu@vmware.com>
  • Loading branch information
qiuming-best committed Sep 22, 2022
1 parent c0920b8 commit 6a79206
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/5377-qiuming-best
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix restore error with flag namespace-mappings
5 changes: 5 additions & 0 deletions config/crd/v1/bases/velero.io_podvolumerestores.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ spec:
snapshotID:
description: SnapshotID is the ID of the volume snapshot to be restored.
type: string
sourceNamespace:
description: SourceNamespace is the original namespace for namaspace
mapping.
type: string
uploaderType:
description: UploaderType is the type of the uploader to handle the
data transfer.
Expand All @@ -133,6 +137,7 @@ spec:
- pod
- repoIdentifier
- snapshotID
- sourceNamespace
- volume
type: object
status:
Expand Down
2 changes: 1 addition & 1 deletion config/crd/v1/crds/crds.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions pkg/apis/velero/v1/pod_volume_restore_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ type PodVolumeRestoreSpec struct {

// SnapshotID is the ID of the volume snapshot to be restored.
SnapshotID string `json:"snapshotID"`

// SourceNamespace is the original namespace for namaspace mapping.
SourceNamespace string `json:"sourceNamespace"`
}

// PodVolumeRestorePhase represents the lifecycle phase of a PodVolumeRestore.
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/pod_volume_restore_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,10 @@ func (c *PodVolumeRestoreReconciler) processRestore(ctx context.Context, req *ve
return errors.Wrap(err, "error getting backup storage location")
}

// need to check backup repository in source namespace rather than in pod namespace
// such as in case of namespace mapping issue
backupRepo, err := repository.GetBackupRepository(ctx, c.Client, req.Namespace, repository.BackupRepositoryKey{
VolumeNamespace: req.Spec.Pod.Namespace,
VolumeNamespace: req.Spec.SourceNamespace,
BackupLocation: req.Spec.BackupStorageLocation,
RepositoryType: podvolume.GetPvrRepositoryType(req),
})
Expand Down
5 changes: 3 additions & 2 deletions pkg/podvolume/restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (r *restorer) RestorePodVolumes(data RestoreData) []error {
}
}

volumeRestore := newPodVolumeRestore(data.Restore, data.Pod, data.BackupLocation, volume, backupInfo.snapshotID, repo.Spec.ResticIdentifier, backupInfo.uploaderType, pvc)
volumeRestore := newPodVolumeRestore(data.Restore, data.Pod, data.BackupLocation, volume, backupInfo.snapshotID, repo.Spec.ResticIdentifier, backupInfo.uploaderType, data.SourceNamespace, pvc)

if err := errorOnly(r.veleroClient.VeleroV1().PodVolumeRestores(volumeRestore.Namespace).Create(context.TODO(), volumeRestore, metav1.CreateOptions{})); err != nil {
errs = append(errs, errors.WithStack(err))
Expand Down Expand Up @@ -181,7 +181,7 @@ ForEachVolume:
return errs
}

func newPodVolumeRestore(restore *velerov1api.Restore, pod *corev1api.Pod, backupLocation, volume, snapshot, repoIdentifier, uploaderType string, pvc *corev1api.PersistentVolumeClaim) *velerov1api.PodVolumeRestore {
func newPodVolumeRestore(restore *velerov1api.Restore, pod *corev1api.Pod, backupLocation, volume, snapshot, repoIdentifier, uploaderType, sourceNamespace string, pvc *corev1api.PersistentVolumeClaim) *velerov1api.PodVolumeRestore {
pvr := &velerov1api.PodVolumeRestore{
ObjectMeta: metav1.ObjectMeta{
Namespace: restore.Namespace,
Expand Down Expand Up @@ -213,6 +213,7 @@ func newPodVolumeRestore(restore *velerov1api.Restore, pod *corev1api.Pod, backu
BackupStorageLocation: backupLocation,
RepoIdentifier: repoIdentifier,
UploaderType: uploaderType,
SourceNamespace: sourceNamespace,
},
}
if pvc != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/uploader/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"github.com/vmware-tanzu/velero/pkg/repository/provider"
"github.com/vmware-tanzu/velero/pkg/uploader"
"github.com/vmware-tanzu/velero/pkg/util/filesystem"
)

const restoreProgressCheckInterval = 10 * time.Second
Expand Down Expand Up @@ -81,7 +82,7 @@ func NewUploaderProvider(
}
return NewKopiaUploaderProvider(ctx, credGetter, backupRepo, log)
} else {
if err := provider.NewResticRepositoryProvider(credGetter.FromFile, nil, log).ConnectToRepo(ctx, provider.RepoParam{BackupLocation: bsl, BackupRepo: backupRepo}); err != nil {
if err := provider.NewResticRepositoryProvider(credGetter.FromFile, filesystem.NewFileSystem(), log).ConnectToRepo(ctx, provider.RepoParam{BackupLocation: bsl, BackupRepo: backupRepo}); err != nil {
return nil, errors.Wrap(err, "failed to connect repository")
}
return NewResticUploaderProvider(repoIdentifier, bsl, credGetter, repoKeySelector, log)
Expand Down

0 comments on commit 6a79206

Please sign in to comment.