Skip to content

Commit

Permalink
Merge pull request #3519 from marwanad/cherry-pick-3484-1.18
Browse files Browse the repository at this point in the history
Cherry pick #3484 onto 1.18: Serve stale on ongoing throttling
  • Loading branch information
k8s-ci-robot authored Sep 17, 2020
2 parents 3e51cc7 + 6eca014 commit b24a5be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cluster-autoscaler/cloudprovider/azure/azure_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,12 +664,17 @@ func convertResourceGroupNameToLower(resourceID string) (string, error) {
return strings.Replace(resourceID, resourceGroup, strings.ToLower(resourceGroup), 1), nil
}

// isAzureRequestsThrottled returns true when the err is http.StatusTooManyRequests (429).
// isAzureRequestsThrottled returns true when the err is http.StatusTooManyRequests (429),
// and when err shows the requests was not executed due to an ongoing throttling period.
func isAzureRequestsThrottled(rerr *retry.Error) bool {
klog.V(6).Infof("isAzureRequestsThrottled: starts for error %v", rerr)
if rerr == nil {
return false
}

if rerr.HTTPStatusCode == 0 && rerr.RetryAfter.After(time.Now()) {
return true
}

return rerr.HTTPStatusCode == http.StatusTooManyRequests
}
8 changes: 8 additions & 0 deletions cluster-autoscaler/cloudprovider/azure/azure_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"net/http"
"testing"
"time"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -270,6 +271,13 @@ func TestIsAzureRequestsThrottled(t *testing.T) {
},
expected: true,
},
{
desc: "Nul HTTP code and non-expired Retry-After should return true",
rerr: &retry.Error{
RetryAfter: time.Now().Add(time.Hour),
},
expected: true,
},
}

for _, test := range tests {
Expand Down

0 comments on commit b24a5be

Please sign in to comment.