Skip to content

Commit

Permalink
Merge pull request #1345 from kubernetes-sigs/resizeFileShareFailureC…
Browse files Browse the repository at this point in the history
…ache

fix: stop resize file share when account limit is exceeded
  • Loading branch information
andyzhangx authored Aug 7, 2023
2 parents 8828513 + 0b85e69 commit b1e1302
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/azurefile/azurefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ type Driver struct {
accountSearchCache azcache.Resource
// a timed cache storing tag removing history (solve account update throttling issue)
removeTagCache azcache.Resource
// a timed cache when resize file share failed due to account limit exceeded
resizeFileShareFailureCache azcache.Resource
}

// NewDriver Creates a NewCSIDriver object. Assumes vendor version is equal to driver version &
Expand Down Expand Up @@ -303,6 +305,10 @@ func NewDriver(options *DriverOptions) *Driver {
klog.Fatalf("%v", err)
}

if driver.resizeFileShareFailureCache, err = azcache.NewTimedCache(3*time.Minute, getter, false); err != nil {
klog.Fatalf("%v", err)
}

return &driver
}

Expand Down
15 changes: 15 additions & 0 deletions pkg/azurefile/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,16 @@ func (d *Driver) ControllerExpandVolume(ctx context.Context, req *csi.Controller
subsID = d.cloud.SubscriptionID
}

if accountName != "" {
cache, err := d.resizeFileShareFailureCache.Get(accountName, azcache.CacheReadTypeDefault)
if err != nil {
return nil, status.Errorf(codes.Internal, "resizeFileShareFailureCache(%s) failed with error: %v", accountName, err)
}
if cache != nil {
return nil, status.Errorf(codes.Internal, "account(%s) is in %s, wait for a few minutes to retry", accountName, accountLimitExceedManagementAPI)
}
}

mc := metrics.NewMetricContext(azureFileCSIDriverName, "controller_expand_volume", resourceGroupName, subsID, d.Name)
isOperationSucceeded := false
defer func() {
Expand All @@ -1060,6 +1070,11 @@ func (d *Driver) ControllerExpandVolume(ctx context.Context, req *csi.Controller
}

if err = d.ResizeFileShare(ctx, subsID, resourceGroupName, accountName, fileShareName, int(requestGiB), secrets); err != nil {
if strings.Contains(err.Error(), accountLimitExceedManagementAPI) || strings.Contains(err.Error(), accountLimitExceedDataPlaneAPI) {
if accountName != "" {
d.resizeFileShareFailureCache.Set(accountName, "")
}
}
return nil, status.Errorf(codes.Internal, "expand volume error: %v", err)
}

Expand Down

0 comments on commit b1e1302

Please sign in to comment.