mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #87686 from feiskyer/file-client
Fix backoff retries for AzureFile client
This commit is contained in:
commit
18ade93915
@ -507,14 +507,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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user