From 04f14b59d962481922b5642ca174a6baa0179cf0 Mon Sep 17 00:00:00 2001 From: David White Date: Tue, 12 Apr 2022 16:18:05 -0600 Subject: [PATCH 1/2] fix(ListSnapshots): Handle -10058 return code when listing snapshots of non-existent volume --- pkg/controller/controller.go | 1 + pkg/controller/snapshotter.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index aefaeaa9..32ce75a6 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -23,6 +23,7 @@ const ( snapshotAlreadyExists = -10186 initiatorNicknameOrIdentifierNotFound = -10386 unmapFailedErrorCode = -10509 + invalidArgumentErrorCode = -10058 ) var volumeCapabilities = []*csi.VolumeCapability{ diff --git a/pkg/controller/snapshotter.go b/pkg/controller/snapshotter.go index 06e813eb..18b58457 100644 --- a/pkg/controller/snapshotter.go +++ b/pkg/controller/snapshotter.go @@ -91,8 +91,8 @@ func (controller *Controller) DeleteSnapshot(ctx context.Context, req *csi.Delet func (controller *Controller) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) { sourceVolumeId, err := common.VolumeIdGetName(req.GetSourceVolumeId()) - response, _, err := controller.client.ShowSnapshots(req.SnapshotId, sourceVolumeId) - if err != nil { + response, respStatus, err := controller.client.ShowSnapshots(req.SnapshotId, sourceVolumeId) + if err != nil && respStatus.ReturnCode != invalidArgumentErrorCode { return nil, err } From bf37b551626f014e69c90789f7bdbd9033c6ff34 Mon Sep 17 00:00:00 2001 From: David White Date: Sat, 16 Apr 2022 15:07:49 -0600 Subject: [PATCH 2/2] fix(ListSnapshots): Explicitly return empty snapshot response on -10058 rc --- pkg/controller/snapshotter.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/controller/snapshotter.go b/pkg/controller/snapshotter.go index 18b58457..24e9b935 100644 --- a/pkg/controller/snapshotter.go +++ b/pkg/controller/snapshotter.go @@ -92,8 +92,17 @@ func (controller *Controller) ListSnapshots(ctx context.Context, req *csi.ListSn sourceVolumeId, err := common.VolumeIdGetName(req.GetSourceVolumeId()) response, respStatus, err := controller.client.ShowSnapshots(req.SnapshotId, sourceVolumeId) - if err != nil && respStatus.ReturnCode != invalidArgumentErrorCode { - return nil, err + // invalidArgumentErrorCode returned from controller when an invalid volume is specified + // return an empty response object in this case + if err != nil { + if respStatus.ReturnCode == invalidArgumentErrorCode { + return &csi.ListSnapshotsResponse{ + Entries: []*csi.ListSnapshotsResponse_Entry{}, + NextToken: "", + }, nil + } else { + return nil, err + } } // StartingToken is an index from 1 to maximum, "" returns 0