Skip to content

Commit

Permalink
Merge pull request #7983 from anshulahuja98/snapshotsync
Browse files Browse the repository at this point in the history
Reset VolumeSnapshotRef in Backup Sync Flow
  • Loading branch information
Lyndon-Li authored Jul 11, 2024
2 parents 6fb109f + 4a6a362 commit 6a3e226
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pkg/controller/backup_sync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 6a3e226

Please sign in to comment.