Skip to content

Commit 3ca7ef3

Browse files
authored
Merge pull request #466 from ialidzhikov/cherrypick/do-not-require-class
Cherry pick of #287: Updated sidecar to not require VolumeSnapshotClass for snapshot deletion
2 parents 4463663 + 463484f commit 3ca7ef3

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

pkg/sidecar-controller/content_create_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func TestSyncContent(t *testing.T) {
163163
SnapshotHandle: toStringPointer("sid1-6"),
164164
RestoreSize: &defaultSize,
165165
ReadyToUse: &False,
166-
Error: newSnapshotError("Failed to check and update snapshot content: failed to get input parameters to create snapshot for content content1-6: \"failed to retrieve snapshot class bad-class from the informer: \\\"volumesnapshotclass.snapshot.storage.k8s.io \\\\\\\"bad-class\\\\\\\" not found\\\"\""),
166+
Error: newSnapshotError("Failed to check and update snapshot content: failed to get input parameters to create snapshot for content content1-6: \"volumesnapshotclass.snapshot.storage.k8s.io \\\"bad-class\\\" not found\""),
167167
}),
168168
expectedEvents: []string{"Warning SnapshotContentCheckandUpdateFailed"},
169169
expectedCreateCalls: []createCall{

pkg/sidecar-controller/snapshot_controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
codes "google.golang.org/grpc/codes"
2727
"google.golang.org/grpc/status"
2828
v1 "k8s.io/api/core/v1"
29+
"k8s.io/apimachinery/pkg/api/errors"
2930
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3031
"k8s.io/klog"
3132
"k8s.io/kubernetes/pkg/util/goroutinemap"
@@ -367,7 +368,7 @@ func (ctrl *csiSnapshotSideCarController) deleteCSISnapshotOperation(content *cr
367368
klog.V(5).Infof("deleteCSISnapshotOperation [%s] started", content.Name)
368369

369370
_, snapshotterCredentials, err := ctrl.getCSISnapshotInput(content)
370-
if err != nil {
371+
if err != nil && !errors.IsNotFound(err) {
371372
ctrl.eventRecorder.Event(content, v1.EventTypeWarning, "SnapshotDeleteError", "Failed to get snapshot class or credentials")
372373
return fmt.Errorf("failed to get input parameters to delete snapshot for content %s: %q", content.Name, err)
373374
}
@@ -479,7 +480,7 @@ func (ctrl *csiSnapshotSideCarController) getSnapshotClass(className string) (*c
479480
class, err := ctrl.classLister.Get(className)
480481
if err != nil {
481482
klog.Errorf("failed to retrieve snapshot class %s from the informer: %q", className, err)
482-
return nil, fmt.Errorf("failed to retrieve snapshot class %s from the informer: %q", className, err)
483+
return nil, err
483484
}
484485

485486
return class, nil

pkg/sidecar-controller/snapshot_delete_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,13 @@ func TestDeleteSync(t *testing.T) {
219219
test: testSyncContent,
220220
},
221221
{
222-
name: "1-4 - fail to delete with a snapshot class which has invalid secret parameter, bound finalizer should remain",
223-
initialContents: newContentArrayWithDeletionTimestamp("content1-1", "snapuid1-1", "snap1-1", "sid1-1", "invalid", "", "snap1-4-volumehandle", deletionPolicy, nil, nil, true, &timeNowMetav1),
224-
expectedContents: newContentArrayWithDeletionTimestamp("content1-1", "snapuid1-1", "snap1-1", "sid1-1", "invalid", "", "snap1-4-volumehandle", deletionPolicy, nil, nil, true, &timeNowMetav1),
225-
expectedEvents: noevents,
226-
errors: noerrors,
227-
test: testSyncContent,
222+
name: "1-4 - fail to delete with a snapshot class which has invalid secret parameter, bound finalizer should remain",
223+
initialContents: newContentArrayWithDeletionTimestamp("content1-1", "snapuid1-1", "snap1-1", "sid1-1", "invalid", "", "snap1-4-volumehandle", deletionPolicy, nil, nil, true, &timeNowMetav1),
224+
expectedContents: newContentArrayWithDeletionTimestamp("content1-1", "snapuid1-1", "snap1-1", "sid1-1", "invalid", "", "snap1-4-volumehandle", deletionPolicy, nil, nil, true, &timeNowMetav1),
225+
expectedEvents: noevents,
226+
expectedDeleteCalls: []deleteCall{{"sid1-1", nil, fmt.Errorf("mock csi driver delete error")}},
227+
errors: noerrors,
228+
test: testSyncContent,
228229
},
229230
{
230231
name: "1-5 - csi driver delete snapshot returns error, bound finalizer should remain",
@@ -330,10 +331,9 @@ func TestDeleteSync(t *testing.T) {
330331
test: testSyncContent,
331332
},
332333
{
333-
name: "1-15 - (dynamic)deletion of content with no snapshotclass should produce error",
334+
name: "1-15 - (dynamic)deletion of content with no snapshotclass should succeed",
334335
initialContents: newContentArrayWithDeletionTimestamp("content1-15", "sid1-15", "snap1-15", "sid1-15", "", "", "snap1-15-volumehandle", deletePolicy, nil, &defaultSize, true, &timeNowMetav1),
335336
expectedContents: newContentArrayWithDeletionTimestamp("content1-15", "sid1-15", "snap1-15", "sid1-15", "", "", "snap1-15-volumehandle", deletePolicy, nil, &defaultSize, true, &timeNowMetav1),
336-
expectedEvents: []string{"Warning SnapshotDeleteError"},
337337
errors: noerrors,
338338
expectedDeleteCalls: []deleteCall{{"sid1-15", nil, nil}},
339339
test: testSyncContent,

0 commit comments

Comments
 (0)