Skip to content

Commit c825e79

Browse files
committed
disk: refine create volume error code
Avoid unknown code. Use InvalidArgument for anything needs user adjusting.
1 parent a708837 commit c825e79

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pkg/disk/cloud.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -984,11 +984,11 @@ func createDisk(ecsClient cloud.ECSInterface, diskName, snapshotID string, diskV
984984
if errors.Is(err, ErrParameterMismatch) {
985985
if createDiskRequest.ClientToken == "" {
986986
// protect us from infinite loop
987-
return "", attempt, fmt.Errorf("unexpected parameter mismatch")
987+
return "", attempt, status.Error(codes.Internal, "unexpected parameter mismatch")
988988
}
989989
existingDisk, err := findDiskByName(diskName, ecsClient)
990990
if err != nil {
991-
return "", attempt, fmt.Errorf("parameter mismatch detected, but fetch existing node failed: %w", err)
991+
return "", attempt, status.Errorf(codes.Internal, "parameter mismatch detected, but fetch existing disk failed: %v", err)
992992
}
993993
if existingDisk == nil {
994994
// No existing disk, retry without client token
@@ -1007,7 +1007,7 @@ func createDisk(ecsClient cloud.ECSInterface, diskName, snapshotID string, diskV
10071007
}
10081008
return diskID, attempt, nil
10091009
}
1010-
return "", createAttempt{}, status.Errorf(codes.Internal, "all attempts failed: %s", strings.Join(messages, "; "))
1010+
return "", createAttempt{}, status.Errorf(codes.InvalidArgument, "all attempts failed: %s", strings.Join(messages, "; "))
10111011
}
10121012

10131013
func buildCreateDiskRequest(diskVol *diskVolumeArgs) *ecs.CreateDiskRequest {

pkg/disk/controllerserver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
200200
switch aliErr.ErrorCode() {
201201
case SnapshotNotFound:
202202
return nil, status.Errorf(codes.NotFound, "snapshot %s not found", snapshotID)
203+
default:
204+
return nil, status.Error(codes.Internal, err.Error())
203205
}
204206
}
205207
return nil, err

0 commit comments

Comments
 (0)