From 7f2200c61a7e37f016dde2bf121e3a21c99a10bc Mon Sep 17 00:00:00 2001 From: Pengfei Ni Date: Thu, 30 Jan 2020 09:02:07 +0000 Subject: [PATCH] Fix backoff retries for AzureFile client --- .../legacy-cloud-providers/azure/azure.go | 6 ++-- .../azure/azure_file.go | 32 ++++++++++++++++++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go index 466f06bfd33..f6f82ef78ff 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go @@ -500,14 +500,14 @@ func (az *Cloud) InitializeCloudFromConfig(config *Config, fromSecret bool) erro az.SnapshotsClient = snapshotclient.New(azClientConfig.WithRateLimiter(config.SnapshotRateLimit)) az.StorageAccountClient = storageaccountclient.New(azClientConfig.WithRateLimiter(config.StorageAccountRateLimit)) + // fileClient is not based on armclient, but it's still backoff retried. + az.FileClient = newAzureFileClient(env, azClientConfig.Backoff) + // Error "not an active Virtual Machine Scale Set VM" is not retriable for VMSS VM. vmssVMClientConfig := azClientConfig.WithRateLimiter(config.VirtualMachineScaleSetRateLimit) vmssVMClientConfig.Backoff = vmssVMClientConfig.Backoff.WithNonRetriableErrors([]string{vmssVMNotActiveErrorMessage}) az.VirtualMachineScaleSetVMsClient = vmssvmclient.New(vmssVMClientConfig) - // TODO(feiskyer): refactor azureFileClient to Interface. - az.FileClient = &azureFileClient{env: *env} - if az.MaximumLoadBalancerRuleCount == 0 { az.MaximumLoadBalancerRuleCount = maximumLoadBalancerRuleCount } diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_file.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_file.go index bc4106d2fc7..ad158ecc9f9 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_file.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_file.go @@ -20,17 +20,30 @@ package azure import ( "fmt" + "net/http" azs "github.com/Azure/azure-sdk-for-go/storage" "github.com/Azure/go-autorest/autorest/azure" "k8s.io/klog" + "k8s.io/legacy-cloud-providers/azure/retry" ) const ( useHTTPS = true ) +var ( + // refer https://github.com/Azure/azure-sdk-for-go/blob/master/storage/client.go#L88. + defaultValidStatusCodes = []int{ + http.StatusRequestTimeout, // 408 + http.StatusInternalServerError, // 500 + http.StatusBadGateway, // 502 + http.StatusServiceUnavailable, // 503 + http.StatusGatewayTimeout, // 504 + } +) + // FileClient is the interface for creating file shares, interface for test // injection. type FileClient interface { @@ -53,7 +66,15 @@ func (az *Cloud) resizeFileShare(accountName, accountKey, name string, sizeGiB i } type azureFileClient struct { - env azure.Environment + env *azure.Environment + backoff *retry.Backoff +} + +func newAzureFileClient(env *azure.Environment, backoff *retry.Backoff) *azureFileClient { + return &azureFileClient{ + env: env, + backoff: backoff, + } } func (f *azureFileClient) createFileShare(accountName, accountKey, name string, sizeGiB int) error { @@ -106,6 +127,15 @@ func (f *azureFileClient) getFileSvcClient(accountName, accountKey string) (*azs if err != nil { return nil, fmt.Errorf("error creating azure client: %v", err) } + + if f.backoff != nil { + fileClient.Sender = &azs.DefaultSender{ + RetryAttempts: f.backoff.Steps, + ValidStatusCodes: defaultValidStatusCodes, + RetryDuration: f.backoff.Duration, + } + } + fc := fileClient.GetFileService() return &fc, nil }