Skip to content

Commit 68880a2

Browse files
authored
Merge pull request #249 from xing-yang/retain
Add VolumeSnapshotBeingDeleted annotation to content
2 parents 5b4d006 + b154cc7 commit 68880a2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

pkg/common-controller/snapshot_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ func (ctrl *csiSnapshotCommonController) checkandRemoveSnapshotFinalizersAndChec
249249
}
250250

251251
klog.V(5).Infof("checkandRemoveSnapshotFinalizersAndCheckandDeleteContent[%s]: set DeletionTimeStamp on content.", utils.SnapshotKey(snapshot))
252+
252253
// If content exists, set DeletionTimeStamp on the content;
253254
// content won't be deleted immediately due to the finalizer
254255
if content != nil && deleteContent && !inUse {
@@ -261,6 +262,9 @@ func (ctrl *csiSnapshotCommonController) checkandRemoveSnapshotFinalizersAndChec
261262
}
262263

263264
if !inUse {
265+
klog.V(5).Infof("checkandRemoveSnapshotFinalizersAndCheckandDeleteContent: Set VolumeSnapshotBeingDeleted annotation on the content [%s]", content.Name)
266+
ctrl.setAnnVolumeSnapshotBeingDeleted(content)
267+
264268
klog.V(5).Infof("checkandRemoveSnapshotFinalizersAndCheckandDeleteContent: Remove Finalizer for VolumeSnapshot[%s]", utils.SnapshotKey(snapshot))
265269
doesContentExist := false
266270
if content != nil {

pkg/common-controller/snapshot_update_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222
"time"
2323

24+
crdv1 "github.com/kubernetes-csi/external-snapshotter/v2/pkg/apis/volumesnapshot/v1beta1"
2425
"github.com/kubernetes-csi/external-snapshotter/v2/pkg/utils"
2526
v1 "k8s.io/api/core/v1"
2627
storagev1beta1 "k8s.io/api/storage/v1beta1"
@@ -336,6 +337,20 @@ func TestSync(t *testing.T) {
336337
expectSuccess: false,
337338
test: testSyncContentError,
338339
},
340+
{
341+
name: "5-5 - snapshot deletion candidate marked for deletion by syncSnapshot",
342+
initialSnapshots: newSnapshotArray("snap5-5", "snapuid5-5", "claim5-5", "", validSecretClass, "content5-5", &False, nil, nil, nil, false, true, &timeNowMetav1),
343+
expectedSnapshots: withSnapshotFinalizers(newSnapshotArray("snap5-5", "snapuid5-5", "claim5-5", "", validSecretClass, "content5-5", &False, nil, nil, nil, false, false, &timeNowMetav1),
344+
utils.VolumeSnapshotBoundFinalizer,
345+
),
346+
initialContents: newContentArray("content5-5", "snapuid5-5", "snap5-5", "sid5-5", validSecretClass, "", "", crdv1.VolumeSnapshotContentRetain, nil, nil, true),
347+
expectedContents: withContentAnnotations(newContentArray("content5-5", "snapuid5-5", "snap5-5", "sid5-5", validSecretClass, "", "", crdv1.VolumeSnapshotContentRetain, nil, nil, true), map[string]string{utils.AnnVolumeSnapshotBeingDeleted: "yes"}),
348+
initialClaims: newClaimArray("claim5-5", "pvc-uid5-5", "1Gi", "volume5-5", v1.ClaimBound, &classEmpty),
349+
initialVolumes: newVolumeArray("volume5-5", "pv-uid5-5", "pv-handle5-5", "1Gi", "pvc-uid5-5", "claim5-5", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
350+
initialSecrets: []*v1.Secret{secret()},
351+
expectSuccess: true,
352+
test: testSyncSnapshot,
353+
},
339354
}
340355

341356
runSyncTests(t, tests, snapshotClasses)

0 commit comments

Comments
 (0)