From 89be8e00d336729e8e9f245850218b513ff8b463 Mon Sep 17 00:00:00 2001 From: Anshul Ahuja Date: Fri, 12 Jul 2024 13:20:13 +0530 Subject: [PATCH] Reset VolumeSnapshotRef in Backup Sync Flow (#8005) Signed-off-by: Anshul Ahuja Co-authored-by: Anshul Ahuja --- pkg/controller/backup_sync_controller.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/controller/backup_sync_controller.go b/pkg/controller/backup_sync_controller.go index e8588a807..70c8101dd 100644 --- a/pkg/controller/backup_sync_controller.go +++ b/pkg/controller/backup_sync_controller.go @@ -40,6 +40,7 @@ import ( "github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt" "github.com/vmware-tanzu/velero/pkg/util/kube" + corev1api "k8s.io/api/core/v1" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -272,6 +273,20 @@ func (b *backupSyncReconciler) Reconcile(ctx context.Context, req ctrl.Request) for _, snapCont := range snapConts { // TODO: Reset ResourceVersion prior to persisting VolumeSnapshotContents snapCont.ResourceVersion = "" + // Make the VolumeSnapshotContent static + snapCont.Spec.Source = snapshotv1api.VolumeSnapshotContentSource{ + SnapshotHandle: snapCont.Status.SnapshotHandle, + } + // Set VolumeSnapshotRef to none exist one, because VolumeSnapshotContent + // validation webhook will check whether name and namespace are nil. + // external-snapshotter needs Source pointing to snapshot and VolumeSnapshot + // reference's UID to nil to determine the VolumeSnapshotContent is deletable. + snapCont.Spec.VolumeSnapshotRef = corev1api.ObjectReference{ + APIVersion: snapshotv1api.SchemeGroupVersion.String(), + Kind: "VolumeSnapshot", + Namespace: "ns-" + string(snapCont.UID), + Name: "name-" + string(snapCont.UID), + } err := b.client.Create(ctx, snapCont, &client.CreateOptions{}) switch { case err != nil && apierrors.IsAlreadyExists(err):