diff --git a/pkg/controller/backup_sync_controller.go b/pkg/controller/backup_sync_controller.go index b11ff4db1b..70c8101dd0 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,10 +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 = "" - // For creating static VSContent, we should put snapshothandle in source rather than volume handle. - // Because if VSContent syncs to a different cluster, having volumeHandle will force rePUTs on the snapshot - snapCont.Spec.Source.SnapshotHandle = snapCont.Status.SnapshotHandle - snapCont.Spec.Source.VolumeHandle = nil + // 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):