Skip to content

Commit

Permalink
Merge pull request #913 from k8s-infra-cherrypick-robot/cherry-pick-9…
Browse files Browse the repository at this point in the history
…12-to-release-1.6

[release-1.6] Map filestore system limit error to ResourceExhausted error code
  • Loading branch information
k8s-ci-robot authored Jul 23, 2024
2 parents c6c7397 + 9ae5be4 commit 0a9aedb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/cloud_provider/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,19 @@ func containsUserErrStr(err error) *codes.Code {
return nil
}

// isFilestoreLimitError returns a pointer to the grpc error code
// ResourceExhausted if the passed in error contains the
// "System limit for internal resources has been reached" string.
func isFilestoreLimitError(err error) *codes.Code {
if err == nil {
return nil
}
if strings.Contains(err.Error(), "System limit for internal resources has been reached") {
return util.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 Expand Up @@ -763,6 +776,9 @@ func codeForError(err error) *codes.Code {
if errCode := isContextError(err); errCode != nil {
return errCode
}
if errCode := isFilestoreLimitError(err); errCode != nil {
return errCode
}
if errCode := isGoogleAPIError(err); errCode != nil {
return errCode
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/cloud_provider/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,11 @@ func TestCodeForError(t *testing.T) {
err: nil,
expectedErrCode: nil,
},
{
name: "Filestore system limit error",
err: fmt.Errorf("got error: System limit for internal resources has been reached"),
expectedErrCode: util.ErrCodePtr(codes.ResourceExhausted),
},
}

for _, test := range cases {
Expand Down

0 comments on commit 0a9aedb

Please sign in to comment.