Skip to content

Commit e8be97f

Browse files
authored
Merge pull request #2318 from k8s-infra-cherrypick-robot/cherry-pick-2316-to-release-1.30
[release-1.30] fix: switch to data plane API call when create snapshot is throttled
2 parents cc3201d + b290587 commit e8be97f

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
@@ -967,7 +967,7 @@ func (d *Driver) DeleteFileShare(ctx context.Context, subsID, resourceGroup, acc
967967

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

pkg/azurefile/controllerserver.go

+8
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,10 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
877877
}
878878
}
879879

880+
if !useDataPlaneAPI {
881+
useDataPlaneAPI = d.useDataPlaneAPI(sourceVolumeID, accountName)
882+
}
883+
880884
mc := metrics.NewMetricContext(azureFileCSIDriverName, "controller_create_snapshot", rgName, subsID, d.Name)
881885
isOperationSucceeded := false
882886
defer func() {
@@ -926,6 +930,10 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
926930
} else {
927931
snapshotShare, err := d.cloud.FileClient.WithSubscriptionID(subsID).CreateFileShare(ctx, rgName, accountName, &fileclient.ShareOptions{Name: fileShareName, Metadata: map[string]*string{snapshotNameKey: &snapshotName}}, snapshotsExpand)
928932
if err != nil {
933+
if isThrottlingError(err) {
934+
klog.Warningf("switch to use data plane API instead for account %s since it's throttled", accountName)
935+
d.dataPlaneAPIAccountCache.Set(accountName, "")
936+
}
929937
return nil, status.Errorf(codes.Internal, "create snapshot from(%s) failed with %v, accountName: %q", sourceVolumeID, err, accountName)
930938
}
931939

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
@@ -749,3 +749,45 @@ func TestIsReadOnlyFromCapability(t *testing.T) {
749749
}
750750
}
751751
}
752+
753+
func TestIsThrottlingError(t *testing.T) {
754+
tests := []struct {
755+
desc string
756+
err error
757+
expected bool
758+
}{
759+
{
760+
desc: "nil error",
761+
err: nil,
762+
expected: false,
763+
},
764+
{
765+
desc: "no match",
766+
err: errors.New("no match"),
767+
expected: false,
768+
},
769+
{
770+
desc: "match error message",
771+
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\""),
772+
expected: true,
773+
},
774+
{
775+
desc: "match error message exceeds 1200s",
776+
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\""),
777+
expected: true,
778+
},
779+
{
780+
desc: "match error message with TooManyRequests throttling",
781+
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\""),
782+
expected: true,
783+
},
784+
}
785+
786+
for _, test := range tests {
787+
result := isThrottlingError(test.err)
788+
if result != test.expected {
789+
t.Errorf("desc: (%s), input: err(%v), IsThrottlingError returned with bool(%t), not equal to expected(%t)",
790+
test.desc, test.err, result, test.expected)
791+
}
792+
}
793+
}

0 commit comments

Comments
 (0)