Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset VolumeSnapshotRef in Backup Sync Flow #7983

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"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 @@
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,

Check warning on line 278 in pkg/controller/backup_sync_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/backup_sync_controller.go#L277-L278

Added lines #L277 - L278 were not covered by tests
}
// 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),

Check warning on line 288 in pkg/controller/backup_sync_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/backup_sync_controller.go#L284-L288

Added lines #L284 - L288 were not covered by tests
Comment on lines +287 to +288
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this snapshot namespacedname supposed to be non-existing?
Can the string here be anything?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaovilai this is a copy paste from -https://github.com/vmware-tanzu/velero/blame/824bebbad7bc61077c6e80731468fb020d3dfd4f/pkg/util/csi/volume_snapshot.go#L641

My understanidng is that any name should work here.
We are creating a static VSC

}
err := b.client.Create(ctx, snapCont, &client.CreateOptions{})
switch {
case err != nil && apierrors.IsAlreadyExists(err):
Expand Down
Loading