Skip to content

Commit 3c4ec63

Browse files
authored
Merge pull request #1443 from huww98/create-disk-code
disk: refine create volume error code
2 parents 373562c + c825e79 commit 3c4ec63

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
@@ -959,11 +959,11 @@ func createDisk(ecsClient cloud.ECSInterface, diskName, snapshotID string, diskV
959959
if errors.Is(err, ErrParameterMismatch) {
960960
if createDiskRequest.ClientToken == "" {
961961
// protect us from infinite loop
962-
return "", attempt, fmt.Errorf("unexpected parameter mismatch")
962+
return "", attempt, status.Error(codes.Internal, "unexpected parameter mismatch")
963963
}
964964
existingDisk, err := findDiskByName(diskName, ecsClient)
965965
if err != nil {
966-
return "", attempt, fmt.Errorf("parameter mismatch detected, but fetch existing node failed: %w", err)
966+
return "", attempt, status.Errorf(codes.Internal, "parameter mismatch detected, but fetch existing disk failed: %v", err)
967967
}
968968
if existingDisk == nil {
969969
// No existing disk, retry without client token
@@ -982,7 +982,7 @@ func createDisk(ecsClient cloud.ECSInterface, diskName, snapshotID string, diskV
982982
}
983983
return diskID, attempt, nil
984984
}
985-
return "", createAttempt{}, status.Errorf(codes.Internal, "all attempts failed: %s", strings.Join(messages, "; "))
985+
return "", createAttempt{}, status.Errorf(codes.InvalidArgument, "all attempts failed: %s", strings.Join(messages, "; "))
986986
}
987987

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

pkg/disk/controllerserver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
191191
switch aliErr.ErrorCode() {
192192
case SnapshotNotFound:
193193
return nil, status.Errorf(codes.NotFound, "snapshot %s not found", snapshotID)
194+
default:
195+
return nil, status.Error(codes.Internal, err.Error())
194196
}
195197
}
196198
return nil, err

0 commit comments

Comments
 (0)