From 53489b10ad92ea4da66f8e640e5c827dc50d9809 Mon Sep 17 00:00:00 2001 From: Lyndon-Li Date: Wed, 13 Sep 2023 16:11:35 +0800 Subject: [PATCH] issue 6786:always delete VSC regardless of the deletion policy Signed-off-by: Lyndon-Li --- changelogs/unreleased/6827-Lyndon-Li | 1 + pkg/exposer/csi_snapshot.go | 2 +- pkg/util/csi/volume_snapshot.go | 2 +- pkg/util/csi/volume_snapshot_test.go | 8 ++++++++ 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/6827-Lyndon-Li diff --git a/changelogs/unreleased/6827-Lyndon-Li b/changelogs/unreleased/6827-Lyndon-Li new file mode 100644 index 0000000000..1aac387e08 --- /dev/null +++ b/changelogs/unreleased/6827-Lyndon-Li @@ -0,0 +1 @@ +Fix issue #6786, always delete VSC regardless of the deletion policy \ No newline at end of file diff --git a/pkg/exposer/csi_snapshot.go b/pkg/exposer/csi_snapshot.go index bc6f00e9ce..e0842f5f13 100644 --- a/pkg/exposer/csi_snapshot.go +++ b/pkg/exposer/csi_snapshot.go @@ -282,7 +282,7 @@ func (e *csiSnapshotExposer) createBackupVSC(ctx context.Context, ownerObject co Source: snapshotv1api.VolumeSnapshotContentSource{ SnapshotHandle: snapshotVSC.Status.SnapshotHandle, }, - DeletionPolicy: snapshotVSC.Spec.DeletionPolicy, + DeletionPolicy: snapshotv1api.VolumeSnapshotContentDelete, Driver: snapshotVSC.Spec.Driver, VolumeSnapshotClassName: snapshotVSC.Spec.VolumeSnapshotClassName, }, diff --git a/pkg/util/csi/volume_snapshot.go b/pkg/util/csi/volume_snapshot.go index b9b134fde7..99845d78f8 100644 --- a/pkg/util/csi/volume_snapshot.go +++ b/pkg/util/csi/volume_snapshot.go @@ -101,7 +101,7 @@ func GetVolumeSnapshotContentForVolumeSnapshot(volSnap *snapshotv1api.VolumeSnap func RetainVSC(ctx context.Context, snapshotClient snapshotter.SnapshotV1Interface, vsc *snapshotv1api.VolumeSnapshotContent) (*snapshotv1api.VolumeSnapshotContent, error) { if vsc.Spec.DeletionPolicy == snapshotv1api.VolumeSnapshotContentRetain { - return nil, nil + return vsc, nil } origBytes, err := json.Marshal(vsc) if err != nil { diff --git a/pkg/util/csi/volume_snapshot_test.go b/pkg/util/csi/volume_snapshot_test.go index 66e76b10cb..43ed9a3162 100644 --- a/pkg/util/csi/volume_snapshot_test.go +++ b/pkg/util/csi/volume_snapshot_test.go @@ -558,6 +558,14 @@ func TestRetainVSC(t *testing.T) { DeletionPolicy: snapshotv1api.VolumeSnapshotContentRetain, }, }, + updated: &snapshotv1api.VolumeSnapshotContent{ + ObjectMeta: metav1.ObjectMeta{ + Name: "fake-vsc", + }, + Spec: snapshotv1api.VolumeSnapshotContentSpec{ + DeletionPolicy: snapshotv1api.VolumeSnapshotContentRetain, + }, + }, }, { name: "path vsc fail",