Skip to content

Commit 36e1f99

Browse files
authored
Merge pull request #2317 from k8s-infra-cherrypick-robot/cherry-pick-2316-to-release-1.31
[release-1.31] fix: switch to data plane API call when create snapshot is throttled
2 parents 8d3124c + d21f2a6 commit 36e1f99

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

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

pkg/azurefile/controllerserver.go

+8
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,10 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
886886
}
887887
}
888888

889+
if !useDataPlaneAPI {
890+
useDataPlaneAPI = d.useDataPlaneAPI(ctx, sourceVolumeID, accountName)
891+
}
892+
889893
mc := metrics.NewMetricContext(azureFileCSIDriverName, "controller_create_snapshot", rgName, subsID, d.Name)
890894
isOperationSucceeded := false
891895
defer func() {
@@ -935,6 +939,10 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
935939
} else {
936940
snapshotShare, err := d.cloud.FileClient.WithSubscriptionID(subsID).CreateFileShare(ctx, rgName, accountName, &fileclient.ShareOptions{Name: fileShareName, Metadata: map[string]*string{snapshotNameKey: &snapshotName}}, snapshotsExpand)
937941
if err != nil {
942+
if isThrottlingError(err) {
943+
klog.Warningf("switch to use data plane API instead for account %s since it's throttled", accountName)
944+
d.dataPlaneAPIAccountCache.Set(accountName, "")
945+
}
938946
return nil, status.Errorf(codes.Internal, "create snapshot from(%s) failed with %v, accountName: %q", sourceVolumeID, err, accountName)
939947
}
940948

pkg/azurefile/utils.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,16 @@ func isRetriableError(err error) bool {
138138
return false
139139
}
140140

141-
func sleepIfThrottled(err error, defaultSleepSec int) {
142-
if err == nil {
143-
return
141+
func isThrottlingError(err error) bool {
142+
if err != nil {
143+
errMsg := strings.ToLower(err.Error())
144+
return strings.Contains(errMsg, strings.ToLower(tooManyRequests)) || strings.Contains(errMsg, clientThrottled)
144145
}
145-
if strings.Contains(strings.ToLower(err.Error()), strings.ToLower(tooManyRequests)) || strings.Contains(strings.ToLower(err.Error()), clientThrottled) {
146+
return false
147+
}
148+
149+
func sleepIfThrottled(err error, defaultSleepSec int) {
150+
if isThrottlingError(err) {
146151
retryAfter := getRetryAfterSeconds(err)
147152
if retryAfter == 0 {
148153
retryAfter = defaultSleepSec

pkg/azurefile/utils_test.go

+42
Original file line numberDiff line numberDiff line change
@@ -856,3 +856,45 @@ func TestGetSnapshotID(t *testing.T) {
856856
}
857857
}
858858
}
859+
860+
func TestIsThrottlingError(t *testing.T) {
861+
tests := []struct {
862+
desc string
863+
err error
864+
expected bool
865+
}{
866+
{
867+
desc: "nil error",
868+
err: nil,
869+
expected: false,
870+
},
871+
{
872+
desc: "no match",
873+
err: errors.New("no match"),
874+
expected: false,
875+
},
876+
{
877+
desc: "match error message",
878+
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\""),
879+
expected: true,
880+
},
881+
{
882+
desc: "match error message exceeds 1200s",
883+
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\""),
884+
expected: true,
885+
},
886+
{
887+
desc: "match error message with TooManyRequests throttling",
888+
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\""),
889+
expected: true,
890+
},
891+
}
892+
893+
for _, test := range tests {
894+
result := isThrottlingError(test.err)
895+
if result != test.expected {
896+
t.Errorf("desc: (%s), input: err(%v), IsThrottlingError returned with bool(%t), not equal to expected(%t)",
897+
test.desc, test.err, result, test.expected)
898+
}
899+
}
900+
}

0 commit comments

Comments
 (0)