Skip to content

Commit 77da214

Browse files
authored
fix: revert return codes in controllerserver to codes.Internal (#226)
* fix: revert return codes in controllerserver to codes.Internal * cleanup * fix
1 parent 8c435dd commit 77da214

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

pkg/csi/blockstorage/controllerserver.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
162162

163163
snap, err := cloud.GetSnapshotByID(ctx, sourceSnapshotID)
164164
if stackiterrors.IgnoreNotFound(err) != nil {
165-
return nil, status.Errorf(codes.NotFound, "Failed to retrieve the source snapshot %s: %v", sourceSnapshotID, err)
165+
return nil, status.Errorf(codes.Internal, "Failed to retrieve the source snapshot %s: %v", sourceSnapshotID, err)
166166
}
167167
// If the snapshot exists but is not yet available, fail.
168168
if err == nil && *snap.Status != stackit.SnapshotReadyStatus {
@@ -206,7 +206,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
206206
if stackiterrors.IsNotFound(err) {
207207
return nil, status.Errorf(codes.NotFound, "Source Volume %s not found", sourceVolID)
208208
}
209-
return nil, status.Errorf(codes.NotFound, "Failed to retrieve the source volume %s: %v", sourceVolID, err)
209+
return nil, status.Errorf(codes.Internal, "Failed to retrieve the source volume %s: %v", sourceVolID, err)
210210
}
211211
if volAvailability != *sourceVolume.AvailabilityZone {
212212
return nil, status.Errorf(codes.ResourceExhausted, "Volume must be in the same availability zone as source Volume. Got %s Required: %s", volAvailability, *sourceVolume.AvailabilityZone)
@@ -357,15 +357,15 @@ func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *cs
357357
if stackiterrors.IsNotFound(err) {
358358
return nil, status.Errorf(codes.NotFound, "[ControllerPublishVolume] Volume %s not found", volumeID)
359359
}
360-
return nil, status.Errorf(codes.NotFound, "[ControllerPublishVolume] get volume failed with error %v", err)
360+
return nil, status.Errorf(codes.Internal, "[ControllerPublishVolume] get volume failed with error %v", err)
361361
}
362362

363363
_, err = cloud.GetInstanceByID(ctx, instanceID)
364364
if err != nil {
365365
if stackiterrors.IsNotFound(err) {
366366
return nil, status.Errorf(codes.NotFound, "[ControllerPublishVolume] Instance %s not found", instanceID)
367367
}
368-
return nil, status.Errorf(codes.NotFound, "[ControllerPublishVolume] GetInstanceByID failed with error %v", err)
368+
return nil, status.Errorf(codes.Internal, "[ControllerPublishVolume] GetInstanceByID failed with error %v", err)
369369
}
370370

371371
_, err = cloud.AttachVolume(ctx, instanceID, volumeID)
@@ -840,7 +840,7 @@ func (cs *controllerServer) ValidateVolumeCapabilities(ctx context.Context, req
840840
if stackiterrors.IsNotFound(err) {
841841
return nil, status.Errorf(codes.NotFound, "ValidateVolumeCapabilities Volume %s not found", volumeID)
842842
}
843-
return nil, status.Errorf(codes.NotFound, "ValidateVolumeCapabilities %v", err)
843+
return nil, status.Errorf(codes.Internal, "ValidateVolumeCapabilities %v", err)
844844
}
845845

846846
for _, volCap := range reqVolCap {

pkg/csi/blockstorage/controllerserver_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ var _ = Describe("ControllerServer test", Ordered, func() {
536536

537537
_, err := fakeCs.CreateVolume(context.Background(), req)
538538
Expect(err).To(HaveOccurred())
539-
Expect(status.Code(err)).To(Equal(codes.NotFound))
539+
Expect(status.Code(err)).To(Equal(codes.Internal))
540540
Expect(err.Error()).To(ContainSubstring("Failed to retrieve the source volume"))
541541
})
542542
})

pkg/csi/blockstorage/sanity_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212
"github.com/google/uuid"
1313
"github.com/kubernetes-csi/csi-test/v5/pkg/sanity"
1414
. "github.com/onsi/ginkgo/v2"
15-
"google.golang.org/grpc/codes"
16-
"google.golang.org/grpc/status"
1715
mountutils "k8s.io/mount-utils"
1816
exec "k8s.io/utils/exec/testing"
1917
"k8s.io/utils/ptr"
@@ -124,10 +122,6 @@ var _ = Describe("CSI sanity test", Ordered, func() {
124122
return found, nil
125123
}).AnyTimes()
126124

127-
iaasClient.EXPECT().ListVolumes(
128-
gomock.Any(), gomock.Any(), gomock.Eq("invalid-token"),
129-
).Return(nil, "", status.Error(codes.InvalidArgument, "invalid starting token")).AnyTimes()
130-
131125
iaasClient.EXPECT().ListVolumes(
132126
gomock.Any(), gomock.Any(), gomock.Eq(""),
133127
).DoAndReturn(func(_ context.Context, _ int, _ string) ([]iaas.Volume, string, error) {
@@ -321,7 +315,7 @@ var _ = Describe("CSI sanity test", Ordered, func() {
321315
}
322316
server, ok := createdInstances[instanceID]
323317
if !ok {
324-
return nil, status.Error(codes.NotFound, "server not found in mock")
318+
return nil, &oapierror.GenericOpenAPIError{StatusCode: http.StatusNotFound}
325319
}
326320
return server, nil
327321
}).AnyTimes()
@@ -333,7 +327,7 @@ var _ = Describe("CSI sanity test", Ordered, func() {
333327
).DoAndReturn(func(_ context.Context, instanceID string, volumeID string) (string, error) {
334328
vol, ok := createdVolumes[volumeID]
335329
if !ok {
336-
return "", status.Error(codes.NotFound, "volume not found in mock")
330+
return "", &oapierror.GenericOpenAPIError{StatusCode: http.StatusNotFound}
337331
}
338332
vol.ServerId = ptr.To(instanceID)
339333
vol.Status = ptr.To("attached")

0 commit comments

Comments
 (0)