Updated sidecar to not require VolumeSnapshotClass for snapshot deletion

This commit is contained in:
Christian Huffman
2020-04-07 15:14:24 -04:00
parent 0a9f3c2181
commit daf0051f2b
3 changed files with 10 additions and 9 deletions

View File

@@ -163,7 +163,7 @@ func TestSyncContent(t *testing.T) {
SnapshotHandle: toStringPointer("sid1-6"), SnapshotHandle: toStringPointer("sid1-6"),
RestoreSize: &defaultSize, RestoreSize: &defaultSize,
ReadyToUse: &False, ReadyToUse: &False,
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\\\"\""), 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\""),
}), }),
expectedEvents: []string{"Warning SnapshotContentCheckandUpdateFailed"}, expectedEvents: []string{"Warning SnapshotContentCheckandUpdateFailed"},
expectedCreateCalls: []createCall{ expectedCreateCalls: []createCall{

View File

@@ -27,6 +27,7 @@ import (
codes "google.golang.org/grpc/codes" codes "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog" "k8s.io/klog"
"k8s.io/kubernetes/pkg/util/slice" "k8s.io/kubernetes/pkg/util/slice"
@@ -329,7 +330,7 @@ func (ctrl *csiSnapshotSideCarController) deleteCSISnapshotOperation(content *cr
klog.V(5).Infof("deleteCSISnapshotOperation [%s] started", content.Name) klog.V(5).Infof("deleteCSISnapshotOperation [%s] started", content.Name)
_, snapshotterCredentials, err := ctrl.getCSISnapshotInput(content) _, snapshotterCredentials, err := ctrl.getCSISnapshotInput(content)
if err != nil { if err != nil && !errors.IsNotFound(err) {
ctrl.eventRecorder.Event(content, v1.EventTypeWarning, "SnapshotDeleteError", "Failed to get snapshot class or credentials") ctrl.eventRecorder.Event(content, v1.EventTypeWarning, "SnapshotDeleteError", "Failed to get snapshot class or credentials")
return fmt.Errorf("failed to get input parameters to delete snapshot for content %s: %q", content.Name, err) return fmt.Errorf("failed to get input parameters to delete snapshot for content %s: %q", content.Name, err)
} }
@@ -441,7 +442,7 @@ func (ctrl *csiSnapshotSideCarController) getSnapshotClass(className string) (*c
class, err := ctrl.classLister.Get(className) class, err := ctrl.classLister.Get(className)
if err != nil { if err != nil {
klog.Errorf("failed to retrieve snapshot class %s from the informer: %q", className, err) klog.Errorf("failed to retrieve snapshot class %s from the informer: %q", className, err)
return nil, fmt.Errorf("failed to retrieve snapshot class %s from the informer: %q", className, err) return nil, err
} }
return class, nil return class, nil

View File

@@ -221,10 +221,11 @@ func TestDeleteSync(t *testing.T) {
test: testSyncContent, test: testSyncContent,
}, },
{ {
name: "1-4 - fail to delete with a snapshot class which has invalid secret parameter, bound finalizer should remain", name: "1-4 - fail to delete with a snapshot class which has invalid secret parameter, bound finalizer should remain",
initialContents: newContentArrayWithDeletionTimestamp("content1-1", "snapuid1-1", "snap1-1", "sid1-1", "invalid", "", "snap1-4-volumehandle", deletionPolicy, nil, nil, true, &timeNowMetav1), initialContents: newContentArrayWithDeletionTimestamp("content1-1", "snapuid1-1", "snap1-1", "sid1-1", "invalid", "", "snap1-4-volumehandle", deletionPolicy, nil, nil, true, &timeNowMetav1),
expectedContents: newContentArrayWithDeletionTimestamp("content1-1", "snapuid1-1", "snap1-1", "sid1-1", "invalid", "", "snap1-4-volumehandle", deletionPolicy, nil, nil, true, &timeNowMetav1), expectedContents: newContentArrayWithDeletionTimestamp("content1-1", "snapuid1-1", "snap1-1", "sid1-1", "invalid", "", "snap1-4-volumehandle", deletionPolicy, nil, nil, true, &timeNowMetav1),
expectedEvents: noevents, expectedEvents: noevents,
expectedDeleteCalls: []deleteCall{{"sid1-1", nil, fmt.Errorf("mock csi driver delete error")}},
errors: []reactorError{ errors: []reactorError{
// Inject error to the first client.VolumesnapshotV1beta1().VolumeSnapshotContents().Delete call. // Inject error to the first client.VolumesnapshotV1beta1().VolumeSnapshotContents().Delete call.
// All other calls will succeed. // All other calls will succeed.
@@ -336,10 +337,9 @@ func TestDeleteSync(t *testing.T) {
test: testSyncContent, test: testSyncContent,
}, },
{ {
name: "1-15 - (dynamic)deletion of content with no snapshotclass should produce error", name: "1-15 - (dynamic)deletion of content with no snapshotclass should succeed",
initialContents: newContentArrayWithDeletionTimestamp("content1-15", "sid1-15", "snap1-15", "sid1-15", "", "", "snap1-15-volumehandle", deletePolicy, nil, &defaultSize, true, &timeNowMetav1), initialContents: newContentArrayWithDeletionTimestamp("content1-15", "sid1-15", "snap1-15", "sid1-15", "", "", "snap1-15-volumehandle", deletePolicy, nil, &defaultSize, true, &timeNowMetav1),
expectedContents: newContentArrayWithDeletionTimestamp("content1-15", "sid1-15", "snap1-15", "sid1-15", "", "", "snap1-15-volumehandle", deletePolicy, nil, &defaultSize, true, &timeNowMetav1), expectedContents: newContentArrayWithDeletionTimestamp("content1-15", "sid1-15", "snap1-15", "sid1-15", "", "", "snap1-15-volumehandle", deletePolicy, nil, &defaultSize, true, &timeNowMetav1),
expectedEvents: []string{"Warning SnapshotDeleteError"},
errors: noerrors, errors: noerrors,
expectedDeleteCalls: []deleteCall{{"sid1-15", nil, nil}}, expectedDeleteCalls: []deleteCall{{"sid1-15", nil, nil}},
test: testSyncContent, test: testSyncContent,