Skip to content

Commit bcb30a7

Browse files
authored
Merge pull request #1231 from Madhu-1/fix-1230
Dont call DeleteSnapshot when VS belong to VGS
2 parents 7a3352f + 34854a6 commit bcb30a7

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

pkg/sidecar-controller/framework_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,15 @@ func newContentArrayWithReadyToUse(contentName, boundToSnapshotUID, boundToSnaps
667667
}
668668
}
669669

670+
func newContentWithVolumeGroupSnapshotHandle(contentName, boundToSnapshotUID, boundToSnapshotName, snapshotHandle, volumeGroupSnapshotHandle, snapshotClassName, desiredSnapshotHandle,
671+
volumeHandle string, deletionPolicy crdv1.DeletionPolicy, creationTime, size *int64, withFinalizer bool, deletionTime *metav1.Time) []*crdv1.VolumeSnapshotContent {
672+
content := newContentArrayWithDeletionTimestamp(contentName, boundToSnapshotUID, boundToSnapshotName, snapshotHandle, snapshotClassName, desiredSnapshotHandle, volumeHandle, deletionPolicy, creationTime, size, withFinalizer, deletionTime)
673+
for _, c := range content {
674+
c.Status.VolumeGroupSnapshotHandle = &volumeGroupSnapshotHandle
675+
}
676+
return content
677+
}
678+
670679
func newContentArrayWithDeletionTimestamp(contentName, boundToSnapshotUID, boundToSnapshotName, snapshotHandle, snapshotClassName, desiredSnapshotHandle, volumeHandle string,
671680
deletionPolicy crdv1.DeletionPolicy, size, creationTime *int64,
672681
withFinalizer bool, deletionTime *metav1.Time) []*crdv1.VolumeSnapshotContent {

pkg/sidecar-controller/snapshot_controller.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ func (ctrl *csiSnapshotSideCarController) syncContent(content *crdv1.VolumeSnaps
6161
if ctrl.shouldDelete(content) {
6262
klog.V(4).Infof("VolumeSnapshotContent[%s]: the policy is %s", content.Name, content.Spec.DeletionPolicy)
6363
if content.Spec.DeletionPolicy == crdv1.VolumeSnapshotContentDelete &&
64-
content.Status != nil && content.Status.SnapshotHandle != nil {
65-
// issue a CSI deletion call if the snapshot has not been deleted yet from
66-
// underlying storage system. Note that the deletion snapshot operation will
67-
// update content SnapshotHandle to nil upon a successful deletion. At this
64+
content.Status != nil && content.Status.SnapshotHandle != nil && content.Status.VolumeGroupSnapshotHandle == nil {
65+
// issue a CSI deletion call if the snapshot does not belong to volumegroupsnapshot
66+
// and it has not been deleted yet from underlying storage system.
67+
// Note that the deletion snapshot operation will update content SnapshotHandle
68+
// to nil upon a successful deletion. At this
6869
// point, the finalizer on content should NOT be removed to avoid leaking.
6970
err := ctrl.deleteCSISnapshot(content)
7071
if err != nil {
@@ -73,9 +74,9 @@ func (ctrl *csiSnapshotSideCarController) syncContent(content *crdv1.VolumeSnaps
7374
return false, nil
7475
}
7576
// otherwise, either the snapshot has been deleted from the underlying
76-
// storage system, or the deletion policy is Retain, remove the finalizer
77-
// if there is one so that API server could delete the object if there is
78-
// no other finalizer.
77+
// storage system, or it belongs to a volumegroupsnapshot, or the deletion policy is Retain,
78+
// remove the finalizer if there is one so that API server could delete
79+
// the object if there is no other finalizer.
7980
err := ctrl.removeContentFinalizer(content)
8081
if err != nil {
8182
return true, err

pkg/sidecar-controller/snapshot_delete_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,25 @@ func TestDeleteSync(t *testing.T) {
354354
expectedDeleteCalls: []deleteCall{{"sid1-15", nil, nil}},
355355
test: testSyncContent,
356356
},
357+
358+
{
359+
name: "1-16 - (dynamic)deletion of content with no VolumeGroupSnapshotHandle should succeed",
360+
initialContents: newContentWithVolumeGroupSnapshotHandle("content1-16", "sid1-16", "snap1-16", "snap1-16", "grp-snap1-16", "", "", "snap1-16-volumehandle", deletePolicy, nil, &defaultSize, true, &nonFractionalTime),
361+
expectedContents: newContentWithVolumeGroupSnapshotHandle("content1-16", "sid1-16", "snap1-16", "snap1-16", "grp-snap1-16", "", "", "snap1-16-volumehandle", deletePolicy, nil, &defaultSize, false, &nonFractionalTime),
362+
expectSuccess: true,
363+
errors: noerrors,
364+
expectedDeleteCalls: []deleteCall{{"sid1-16", nil, nil}},
365+
test: testSyncContent,
366+
},
367+
{
368+
name: "1-17 - (dynamic)deletion of content with VolumeGroupSnapshotHandle should succeed with no call to CSI driver",
369+
initialContents: newContentWithVolumeGroupSnapshotHandle("content1-17", "sid1-17", "snap1-17", "snap1-17", "grp-snap1-17", "", "", "snap1-17-volumehandle", deletePolicy, nil, &defaultSize, true, &nonFractionalTime),
370+
expectedContents: newContentWithVolumeGroupSnapshotHandle("content1-17", "sid1-17", "snap1-17", "snap1-17", "grp-snap1-17", "", "", "snap1-17-volumehandle", deletePolicy, nil, &defaultSize, false, &nonFractionalTime),
371+
expectSuccess: true,
372+
errors: noerrors,
373+
expectedDeleteCalls: []deleteCall{},
374+
test: testSyncContent,
375+
},
357376
}
358377
runSyncContentTests(t, tests, snapshotClasses)
359378
}

0 commit comments

Comments
 (0)