Skip to content

Classify QUOTA_EXCEEDED errors as ResourceExhausted rather than Internal errors #1263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pkg/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ const (
// Full or partial URL of the machine type resource, in the format:
// zones/zone/machineTypes/machine-type
machineTypePattern = "zones/[^/]+/machineTypes/([^/]+)$"

// User-caused quota exceeded messages
stockoutError = "QUOTA_EXCEEDED"
)

var (
Expand Down Expand Up @@ -340,6 +343,9 @@ func CodeForError(err error) *codes.Code {
if code := isContextError(err); code != nil {
return code
}
if code := isStockoutError(err); code != nil {
return code
}

internalErrorCode := codes.Internal
// Upwrap the error
Expand All @@ -361,6 +367,19 @@ func CodeForError(err error) *codes.Code {
return &internalErrorCode
}

// isStockout returns a pointer to the grpc error code ResourceExhausted
// if the passed in error contains the "ZONE_RESOURCE_POOL_EXHAUSTED"
func isStockoutError(err error) *codes.Code {
if err == nil {
return nil
}

if strings.Contains(err.Error(), stockoutError) {
return errCodePtr(codes.ResourceExhausted)
}
return nil
}

// isContextError returns a pointer to the grpc error code DeadlineExceeded
// if the passed in error contains the "context deadline exceeded" string and returns
// the grpc error code Canceled if the error contains the "context canceled" string.
Expand Down
5 changes: 5 additions & 0 deletions pkg/common/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,11 @@ func TestCodeForError(t *testing.T) {
inputErr: context.DeadlineExceeded,
expCode: errCodePtr(codes.DeadlineExceeded),
},
{
name: "user-caused stockout error",
inputErr: fmt.Errorf("csi.v1.Controller/CreateVolume returned with error: rpc error: code = Internal desc = CreateVolume failed to create single zonal disk test-pvc: failed to insert zonal disk: unknown Insert disk operation error: operation CreateDisk failed (QUOTA_EXCEEDED): Quota 'SSD_TOTAL_GB' exceeded. Limit: 100.00 in region us-central1."),
expCode: errCodePtr(codes.ResourceExhausted),
},
{
name: "status error with Aborted error code",
inputErr: status.Error(codes.Aborted, "aborted error"),
Expand Down