Skip to content

Commit 0a496e3

Browse files
authored
Merge pull request kubernetes#86685 from yangl900/stop-retry-bad-request
Azure cloud provider should not retry on bad request
2 parents d605766 + 6359080 commit 0a496e3

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

staging/src/k8s.io/legacy-cloud-providers/azure/retry/azure_error.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ func getHTTPStatusCode(resp *http.Response) int {
125125
// shouldRetryHTTPRequest determines if the request is retriable.
126126
func shouldRetryHTTPRequest(resp *http.Response, err error) bool {
127127
if resp != nil {
128-
// HTTP 412 (StatusPreconditionFailed) means etag mismatch, hence we shouldn't retry.
129-
if resp.StatusCode == http.StatusPreconditionFailed {
128+
// HTTP 412 (StatusPreconditionFailed) means etag mismatch
129+
// HTTP 400 (BadRequest) means the request cannot be accepted, hence we shouldn't retry.
130+
if resp.StatusCode == http.StatusPreconditionFailed || resp.StatusCode == http.StatusBadRequest {
130131
return false
131132
}
132133

staging/src/k8s.io/legacy-cloud-providers/azure/retry/azure_error_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestGetError(t *testing.T) {
5454
{
5555
code: http.StatusBadRequest,
5656
expected: &Error{
57-
Retriable: true,
57+
Retriable: false,
5858
HTTPStatusCode: http.StatusBadRequest,
5959
RawError: fmt.Errorf("HTTP response: 400"),
6060
},
@@ -136,7 +136,7 @@ func TestGetStatusNotFoundAndForbiddenIgnoredError(t *testing.T) {
136136
{
137137
code: http.StatusBadRequest,
138138
expected: &Error{
139-
Retriable: true,
139+
Retriable: false,
140140
HTTPStatusCode: http.StatusBadRequest,
141141
RawError: fmt.Errorf("HTTP response: 400"),
142142
},
@@ -191,7 +191,7 @@ func TestShouldRetryHTTPRequest(t *testing.T) {
191191
}{
192192
{
193193
code: http.StatusBadRequest,
194-
expected: true,
194+
expected: false,
195195
},
196196
{
197197
code: http.StatusInternalServerError,

0 commit comments

Comments
 (0)