Merge pull request #87686 from feiskyer/file-client

Fix backoff retries for AzureFile client
This commit is contained in:
Kubernetes Prow Robot 2020-01-31 20:07:48 -08:00 committed by GitHub
commit 18ade93915
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 4 deletions

View File

@ -507,14 +507,14 @@ func (az *Cloud) InitializeCloudFromConfig(config *Config, fromSecret bool) erro
az.SnapshotsClient = snapshotclient.New(azClientConfig.WithRateLimiter(config.SnapshotRateLimit)) az.SnapshotsClient = snapshotclient.New(azClientConfig.WithRateLimiter(config.SnapshotRateLimit))
az.StorageAccountClient = storageaccountclient.New(azClientConfig.WithRateLimiter(config.StorageAccountRateLimit)) 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. // Error "not an active Virtual Machine Scale Set VM" is not retriable for VMSS VM.
vmssVMClientConfig := azClientConfig.WithRateLimiter(config.VirtualMachineScaleSetRateLimit) vmssVMClientConfig := azClientConfig.WithRateLimiter(config.VirtualMachineScaleSetRateLimit)
vmssVMClientConfig.Backoff = vmssVMClientConfig.Backoff.WithNonRetriableErrors([]string{vmssVMNotActiveErrorMessage}) vmssVMClientConfig.Backoff = vmssVMClientConfig.Backoff.WithNonRetriableErrors([]string{vmssVMNotActiveErrorMessage})
az.VirtualMachineScaleSetVMsClient = vmssvmclient.New(vmssVMClientConfig) az.VirtualMachineScaleSetVMsClient = vmssvmclient.New(vmssVMClientConfig)
// TODO(feiskyer): refactor azureFileClient to Interface.
az.FileClient = &azureFileClient{env: *env}
if az.MaximumLoadBalancerRuleCount == 0 { if az.MaximumLoadBalancerRuleCount == 0 {
az.MaximumLoadBalancerRuleCount = maximumLoadBalancerRuleCount az.MaximumLoadBalancerRuleCount = maximumLoadBalancerRuleCount
} }

View File

@ -20,17 +20,30 @@ package azure
import ( import (
"fmt" "fmt"
"net/http"
azs "github.com/Azure/azure-sdk-for-go/storage" azs "github.com/Azure/azure-sdk-for-go/storage"
"github.com/Azure/go-autorest/autorest/azure" "github.com/Azure/go-autorest/autorest/azure"
"k8s.io/klog" "k8s.io/klog"
"k8s.io/legacy-cloud-providers/azure/retry"
) )
const ( const (
useHTTPS = true 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 // FileClient is the interface for creating file shares, interface for test
// injection. // injection.
type FileClient interface { type FileClient interface {
@ -53,7 +66,15 @@ func (az *Cloud) resizeFileShare(accountName, accountKey, name string, sizeGiB i
} }
type azureFileClient struct { 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 { 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 { if err != nil {
return nil, fmt.Errorf("error creating azure client: %v", err) 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() fc := fileClient.GetFileService()
return &fc, nil return &fc, nil
} }