Skip to content

Commit df01f09

Browse files
authored
Merge pull request #2213 from k8s-infra-cherrypick-robot/cherry-pick-2208-to-release-1.21
[release-1.21] Return failed precondition googleapi errors
2 parents c2010bf + 54da57f commit df01f09

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

pkg/common/utils.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,12 @@ var (
103103

104104
// userErrorCodeMap tells how API error types are translated to error codes.
105105
userErrorCodeMap = map[int]codes.Code{
106-
http.StatusForbidden: codes.PermissionDenied,
107-
http.StatusBadRequest: codes.InvalidArgument,
108-
http.StatusTooManyRequests: codes.ResourceExhausted,
109-
http.StatusNotFound: codes.NotFound,
110-
http.StatusConflict: codes.FailedPrecondition,
106+
http.StatusForbidden: codes.PermissionDenied,
107+
http.StatusBadRequest: codes.InvalidArgument,
108+
http.StatusTooManyRequests: codes.ResourceExhausted,
109+
http.StatusNotFound: codes.NotFound,
110+
http.StatusConflict: codes.FailedPrecondition,
111+
http.StatusPreconditionFailed: codes.FailedPrecondition,
111112
}
112113

113114
validDataCacheMode = []string{DataCacheModeWriteBack, DataCacheModeWriteThrough}

pkg/common/utils_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,11 @@ func TestCodeForError(t *testing.T) {
14511451
inputErr: &TemporaryError{code: codes.Aborted, err: context.Canceled},
14521452
expCode: codes.Aborted,
14531453
},
1454+
{
1455+
name: "CMEK precondition failed error, under layers of wrapping",
1456+
inputErr: fmt.Errorf("unknown Insert disk error: %w", &googleapi.Error{Code: http.StatusPreconditionFailed, Message: "CMEK policy violated"}),
1457+
expCode: codes.FailedPrecondition,
1458+
},
14541459
}
14551460

14561461
for _, tc := range testCases {

0 commit comments

Comments
 (0)