Skip to content

Commit 7c2cd67

Browse files
authored
Merge pull request #287 from huffmanca/issue264
Updated sidecar to not require VolumeSnapshotClass for snapshot deletion
2 parents 0a9f3c2 + daf0051 commit 7c2cd67

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
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
@@ -27,6 +27,7 @@ import (
2727
codes "google.golang.org/grpc/codes"
2828
"google.golang.org/grpc/status"
2929
v1 "k8s.io/api/core/v1"
30+
"k8s.io/apimachinery/pkg/api/errors"
3031
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3132
"k8s.io/klog"
3233
"k8s.io/kubernetes/pkg/util/slice"
@@ -329,7 +330,7 @@ func (ctrl *csiSnapshotSideCarController) deleteCSISnapshotOperation(content *cr
329330
klog.V(5).Infof("deleteCSISnapshotOperation [%s] started", content.Name)
330331

331332
_, snapshotterCredentials, err := ctrl.getCSISnapshotInput(content)
332-
if err != nil {
333+
if err != nil && !errors.IsNotFound(err) {
333334
ctrl.eventRecorder.Event(content, v1.EventTypeWarning, "SnapshotDeleteError", "Failed to get snapshot class or credentials")
334335
return fmt.Errorf("failed to get input parameters to delete snapshot for content %s: %q", content.Name, err)
335336
}
@@ -441,7 +442,7 @@ func (ctrl *csiSnapshotSideCarController) getSnapshotClass(className string) (*c
441442
class, err := ctrl.classLister.Get(className)
442443
if err != nil {
443444
klog.Errorf("failed to retrieve snapshot class %s from the informer: %q", className, err)
444-
return nil, fmt.Errorf("failed to retrieve snapshot class %s from the informer: %q", className, err)
445+
return nil, err
445446
}
446447

447448
return class, nil

pkg/sidecar-controller/snapshot_delete_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,11 @@ func TestDeleteSync(t *testing.T) {
221221
test: testSyncContent,
222222
},
223223
{
224-
name: "1-4 - fail to delete with a snapshot class which has invalid secret parameter, bound finalizer should remain",
225-
initialContents: newContentArrayWithDeletionTimestamp("content1-1", "snapuid1-1", "snap1-1", "sid1-1", "invalid", "", "snap1-4-volumehandle", deletionPolicy, nil, nil, true, &timeNowMetav1),
226-
expectedContents: newContentArrayWithDeletionTimestamp("content1-1", "snapuid1-1", "snap1-1", "sid1-1", "invalid", "", "snap1-4-volumehandle", deletionPolicy, nil, nil, true, &timeNowMetav1),
227-
expectedEvents: noevents,
224+
name: "1-4 - fail to delete with a snapshot class which has invalid secret parameter, bound finalizer should remain",
225+
initialContents: newContentArrayWithDeletionTimestamp("content1-1", "snapuid1-1", "snap1-1", "sid1-1", "invalid", "", "snap1-4-volumehandle", deletionPolicy, nil, nil, true, &timeNowMetav1),
226+
expectedContents: newContentArrayWithDeletionTimestamp("content1-1", "snapuid1-1", "snap1-1", "sid1-1", "invalid", "", "snap1-4-volumehandle", deletionPolicy, nil, nil, true, &timeNowMetav1),
227+
expectedEvents: noevents,
228+
expectedDeleteCalls: []deleteCall{{"sid1-1", nil, fmt.Errorf("mock csi driver delete error")}},
228229
errors: []reactorError{
229230
// Inject error to the first client.VolumesnapshotV1beta1().VolumeSnapshotContents().Delete call.
230231
// All other calls will succeed.
@@ -336,10 +337,9 @@ func TestDeleteSync(t *testing.T) {
336337
test: testSyncContent,
337338
},
338339
{
339-
name: "1-15 - (dynamic)deletion of content with no snapshotclass should produce error",
340+
name: "1-15 - (dynamic)deletion of content with no snapshotclass should succeed",
340341
initialContents: newContentArrayWithDeletionTimestamp("content1-15", "sid1-15", "snap1-15", "sid1-15", "", "", "snap1-15-volumehandle", deletePolicy, nil, &defaultSize, true, &timeNowMetav1),
341342
expectedContents: newContentArrayWithDeletionTimestamp("content1-15", "sid1-15", "snap1-15", "sid1-15", "", "", "snap1-15-volumehandle", deletePolicy, nil, &defaultSize, true, &timeNowMetav1),
342-
expectedEvents: []string{"Warning SnapshotDeleteError"},
343343
errors: noerrors,
344344
expectedDeleteCalls: []deleteCall{{"sid1-15", nil, nil}},
345345
test: testSyncContent,

0 commit comments

Comments
 (0)