Skip to content

Commit 7719474

Browse files
authored
Merge pull request #2319 from k8s-infra-cherrypick-robot/cherry-pick-2316-to-release-1.29
[release-1.29] fix: switch to data plane API call when create snapshot is throttled
2 parents 198fbf5 + 68b8c16 commit 7719474

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

pkg/azurefile/azurefile.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ func (d *Driver) DeleteFileShare(ctx context.Context, subsID, resourceGroup, acc
968968

969969
if isRetriableError(err) {
970970
klog.Warningf("DeleteFileShare(%s) on account(%s) failed with error(%v), waiting for retrying", shareName, accountName, err)
971-
if strings.Contains(strings.ToLower(err.Error()), strings.ToLower(tooManyRequests)) {
971+
if isThrottlingError(err) {
972972
klog.Warningf("switch to use data plane API instead for account %s since it's throttled", accountName)
973973
d.dataPlaneAPIAccountCache.Set(accountName, "")
974974
return true, err

pkg/azurefile/controllerserver.go

+8
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,10 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
872872
}
873873
}
874874

875+
if !useDataPlaneAPI {
876+
useDataPlaneAPI = d.useDataPlaneAPI(sourceVolumeID, accountName)
877+
}
878+
875879
mc := metrics.NewMetricContext(azureFileCSIDriverName, "controller_create_snapshot", rgName, subsID, d.Name)
876880
isOperationSucceeded := false
877881
defer func() {
@@ -921,6 +925,10 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
921925
} else {
922926
snapshotShare, err := d.cloud.FileClient.WithSubscriptionID(subsID).CreateFileShare(ctx, rgName, accountName, &fileclient.ShareOptions{Name: fileShareName, Metadata: map[string]*string{snapshotNameKey: &snapshotName}}, snapshotsExpand)
923927
if err != nil {
928+
if isThrottlingError(err) {
929+
klog.Warningf("switch to use data plane API instead for account %s since it's throttled", accountName)
930+
d.dataPlaneAPIAccountCache.Set(accountName, "")
931+
}
924932
return nil, status.Errorf(codes.Internal, "create snapshot from(%s) failed with %v, accountName: %q", sourceVolumeID, err, accountName)
925933
}
926934

pkg/azurefile/utils.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,16 @@ func isRetriableError(err error) bool {
135135
return false
136136
}
137137

138-
func sleepIfThrottled(err error, defaultSleepSec int) {
139-
if err == nil {
140-
return
138+
func isThrottlingError(err error) bool {
139+
if err != nil {
140+
errMsg := strings.ToLower(err.Error())
141+
return strings.Contains(errMsg, strings.ToLower(tooManyRequests)) || strings.Contains(errMsg, clientThrottled)
141142
}
142-
if strings.Contains(strings.ToLower(err.Error()), strings.ToLower(tooManyRequests)) || strings.Contains(strings.ToLower(err.Error()), clientThrottled) {
143+
return false
144+
}
145+
146+
func sleepIfThrottled(err error, defaultSleepSec int) {
147+
if isThrottlingError(err) {
143148
retryAfter := getRetryAfterSeconds(err)
144149
if retryAfter == 0 {
145150
retryAfter = defaultSleepSec

pkg/azurefile/utils_test.go

+42
Original file line numberDiff line numberDiff line change
@@ -676,3 +676,45 @@ func TestReplaceWithMap(t *testing.T) {
676676
}
677677
}
678678
}
679+
680+
func TestIsThrottlingError(t *testing.T) {
681+
tests := []struct {
682+
desc string
683+
err error
684+
expected bool
685+
}{
686+
{
687+
desc: "nil error",
688+
err: nil,
689+
expected: false,
690+
},
691+
{
692+
desc: "no match",
693+
err: errors.New("no match"),
694+
expected: false,
695+
},
696+
{
697+
desc: "match error message",
698+
err: errors.New("could not list storage accounts for account type Premium_LRS: Retriable: true, RetryAfter: 217s, HTTPStatusCode: 0, RawError: azure cloud provider throttled for operation StorageAccountListByResourceGroup with reason \"client throttled\""),
699+
expected: true,
700+
},
701+
{
702+
desc: "match error message exceeds 1200s",
703+
err: errors.New("could not list storage accounts for account type Premium_LRS: Retriable: true, RetryAfter: 2170s, HTTPStatusCode: 0, RawError: azure cloud provider throttled for operation StorageAccountListByResourceGroup with reason \"client throttled\""),
704+
expected: true,
705+
},
706+
{
707+
desc: "match error message with TooManyRequests throttling",
708+
err: errors.New("could not list storage accounts for account type Premium_LRS: Retriable: true, RetryAfter: 2170s, HTTPStatusCode: 429, RawError: azure cloud provider throttled for operation StorageAccountListByResourceGroup with reason \"TooManyRequests\""),
709+
expected: true,
710+
},
711+
}
712+
713+
for _, test := range tests {
714+
result := isThrottlingError(test.err)
715+
if result != test.expected {
716+
t.Errorf("desc: (%s), input: err(%v), IsThrottlingError returned with bool(%t), not equal to expected(%t)",
717+
test.desc, test.err, result, test.expected)
718+
}
719+
}
720+
}

0 commit comments

Comments
 (0)