Skip to content

Commit

Permalink
Allow cross-namespace restore of CSI snapshots
Browse files Browse the repository at this point in the history
- Check for namespace mapping information.
- If there is a map, replace VolumeSnapshots namespace to the target namespace

Fixes KUBEDR-364 and KUBEDR-406

Fixes Issues these similar issues from Velero:
1. vmware-tanzu/velero#2143
2. https://github.com/vmware-tanzu/velero-plugin-for-csi/issues/75
  • Loading branch information
sshende-catalogicsoftware committed Sep 20, 2022
1 parent 6256ad2 commit 593972f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ BIN ?= velero-plugin-for-csi

BUILD_IMAGE ?= golang:1.17.11-stretch

REGISTRY ?= velero
REGISTRY ?= catalogicsoftware
IMAGE_NAME ?= $(REGISTRY)/velero-plugin-for-csi
TAG ?= dev
TAG ?= v0.1.2.2

IMAGE ?= $(IMAGE_NAME):$(TAG)

Expand Down
6 changes: 6 additions & 0 deletions internal/restore/pvc_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ func (p *PVCRestoreItemAction) Execute(input *velero.RestoreItemActionExecuteInp
pvc.SetNamespace(val)
}

// 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
2 changes: 1 addition & 1 deletion internal/restore/volumesnapshot_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (p *VolumeSnapshotRestoreItemAction) Execute(input *velero.RestoreItemActio
// TODO: generated name will be like velero-velero-something. Fix that.
vsc := snapshotv1api.VolumeSnapshotContent{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "velero-" + vs.Name + "-",
GenerateName: input.Restore.GetName() + "-" + vs.Name + "-",
Labels: map[string]string{
velerov1api.RestoreNameLabel: label.GetValidName(input.Restore.Name),
},
Expand Down

0 comments on commit 593972f

Please sign in to comment.