From 593972fc0eff8537f2f7157711694c90961a2b3c Mon Sep 17 00:00:00 2001 From: Swanand Shende Date: Thu, 10 Dec 2020 17:37:02 +0530 Subject: [PATCH] Allow cross-namespace restore of CSI snapshots - 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. https://github.com/vmware-tanzu/velero/issues/2143 2. https://github.com/vmware-tanzu/velero-plugin-for-csi/issues/75 --- Makefile | 4 ++-- internal/restore/pvc_action.go | 6 ++++++ internal/restore/volumesnapshot_action.go | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c9729463..69f71f25 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/internal/restore/pvc_action.go b/internal/restore/pvc_action.go index 5990e3a2..2a5f1b0d 100644 --- a/internal/restore/pvc_action.go +++ b/internal/restore/pvc_action.go @@ -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) diff --git a/internal/restore/volumesnapshot_action.go b/internal/restore/volumesnapshot_action.go index 88935726..6858d84c 100644 --- a/internal/restore/volumesnapshot_action.go +++ b/internal/restore/volumesnapshot_action.go @@ -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), },