diff --git a/cluster-autoscaler/cloudprovider/azure/azure_util.go b/cluster-autoscaler/cloudprovider/azure/azure_util.go index c0f625b7e68c..bfc19d5f1462 100644 --- a/cluster-autoscaler/cloudprovider/azure/azure_util.go +++ b/cluster-autoscaler/cloudprovider/azure/azure_util.go @@ -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 } diff --git a/cluster-autoscaler/cloudprovider/azure/azure_util_test.go b/cluster-autoscaler/cloudprovider/azure/azure_util_test.go index 56a1cffd9cb4..9d3ceba8720b 100644 --- a/cluster-autoscaler/cloudprovider/azure/azure_util_test.go +++ b/cluster-autoscaler/cloudprovider/azure/azure_util_test.go @@ -20,6 +20,7 @@ import ( "fmt" "net/http" "testing" + "time" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute" "github.com/stretchr/testify/assert" @@ -271,6 +272,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 {