Skip to content

Commit

Permalink
disk/snapshot: map create error code
Browse files Browse the repository at this point in the history
  • Loading branch information
huww98 committed Dec 19, 2024
1 parent c3fe68f commit d04dd88
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion pkg/disk/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,16 @@ func requestAndCreateSnapshot(ecsClient *ecs.Client, params *createSnapshotParam
// Do Snapshot create
snapshotResponse, err := ecsClient.CreateSnapshot(createSnapshotRequest)
if err != nil {
return nil, fmt.Errorf("create snapshot %s failed: %v", params.SnapshotName, err)
var aliErr *alicloudErr.ServerError
if errors.As(err, &aliErr) {
switch aliErr.ErrorCode() {
case IdempotentParameterMismatch:
return nil, status.Errorf(codes.AlreadyExists, "already created but parameter mismatch (RequestID: %s)", aliErr.RequestId())
case QuotaExceed_Snapshot:
return nil, status.Errorf(codes.ResourceExhausted, "snapshot quota exceeded: %v", err)
}
}
return nil, status.Errorf(codes.Internal, "create snapshot failed: %v", err)
}
return snapshotResponse, nil
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/disk/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ const (
SnapshotNotFound = "InvalidSnapshotId.NotFound"
InstanceNotFound = "InvalidInstanceId.NotFound"

QuotaExceed_Snapshot = "QuotaExceed.Snapshot"

// DiskHighAvail tag
DiskHighAvail = "available"
// MBSIZE tag
Expand Down
2 changes: 1 addition & 1 deletion pkg/disk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
snapshotResponse, err := requestAndCreateSnapshot(ecsClient, params)

if err != nil {
return nil, status.Errorf(codes.Internal, "create snapshot[%s] with sourceId[%s] failed with error: %v", req.Name, req.GetSourceVolumeId(), err)
return nil, err
}

klog.Infof("CreateSnapshot:: Snapshot create successful: snapshotName[%s], sourceId[%s], snapshotId[%s]", req.Name, req.GetSourceVolumeId(), snapshotResponse.SnapshotId)
Expand Down

0 comments on commit d04dd88

Please sign in to comment.