Skip to content

Commit

Permalink
Allow cross-namespace restore of PVC's with CSI volumes
Browse files Browse the repository at this point in the history
- Check for namespace mapping information.
- If there is a valid mapping found, then, replace the original namespace in VolumeSnapshot and PVC Objects to the mapped namespace before restoring
- Fixes PR 2143(vmware-tanzu/velero#2143)

Signed-off-by: Swanand Shende <[email protected]>
  • Loading branch information
sshende-catalogicsoftware committed Dec 10, 2020
1 parent 8140dc9 commit 813ca07
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/restore/pvc_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ func (p *PVCRestoreItemAction) Execute(input *velero.RestoreItemActionExecuteInp

resetPVCAnnotations(&pvc, []string{velerov1api.BackupNameLabel, util.VolumeSnapshotLabel})

// If cross-namespace restore is configured, change the namespace
// for PVC object to be restored
if val, ok := input.Restore.Spec.NamespaceMapping[pvc.GetNamespace()]; ok {
pvc.SetNamespace(val)
}

volumeSnapshotName, ok := pvc.Annotations[util.VolumeSnapshotLabel]
if !ok {
p.Log.Infof("Skipping PVCRestoreItemAction for PVC %s/%s, PVC does not have a CSI volumesnapshot.", pvc.Namespace, pvc.Name)
Expand Down
7 changes: 7 additions & 0 deletions internal/restore/volumesnapshot_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ func (p *VolumeSnapshotRestoreItemAction) Execute(input *velero.RestoreItemActio
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), &vs); err != nil {
return &velero.RestoreItemActionExecuteOutput{}, errors.Wrapf(err, "failed to convert input.Item from unstructured")
}

// If cross-namespace restore is configured, change the namespace
// for VolumeSnapshot object to be restored
if val, ok := input.Restore.Spec.NamespaceMapping[vs.GetNamespace()]; ok {
vs.SetNamespace(val)
}

_, snapClient, err := util.GetClients()
if err != nil {
return nil, errors.WithStack(err)
Expand Down

0 comments on commit 813ca07

Please sign in to comment.