Skip to content

Commit

Permalink
Merge pull request #2239 from kubernetes-sigs/add-getfilesharesize-ca…
Browse files Browse the repository at this point in the history
…che-1.30

[release-1.30] fix: GetFileShare throttling in CreateSnapshot
  • Loading branch information
andyzhangx authored Dec 3, 2024
2 parents 3c4be75 + 72bd2c6 commit 233877e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pkg/azurefile/azurefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ type Driver struct {
azcopySasTokenCache azcache.Resource
// a timed cache storing subnet operations
subnetCache azcache.Resource
// a timed cache storing file share size <accountName-fileShareName, size(int32)>
getFileShareSizeCache azcache.Resource
// sas expiry time for azcopy in volume clone and snapshot restore
sasTokenExpirationMinutes int
// azcopy timeout for volume clone and snapshot restore
Expand Down Expand Up @@ -353,6 +355,10 @@ func NewDriver(options *DriverOptions) *Driver {
klog.Fatalf("%v", err)
}

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

return &driver
}

Expand Down
18 changes: 15 additions & 3 deletions pkg/azurefile/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -939,11 +939,23 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ

klog.V(2).Infof("created share snapshot: %s, time: %v, quota: %dGiB", itemSnapshot, itemSnapshotTime, itemSnapshotQuota)
if itemSnapshotQuota == 0 {
fileshare, err := d.cloud.FileClient.WithSubscriptionID(subsID).GetFileShare(ctx, rgName, accountName, fileShareName, "")
key := fmt.Sprintf("%s-%s", accountName, fileShareName)
cache, err := d.getFileShareSizeCache.Get(key, azcache.CacheReadTypeDefault)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get file share(%s) quota: %v", fileShareName, err)
return nil, status.Errorf(codes.Internal, "failed to get file share size cache(%s): %v", key, err)
}
if cache != nil {
klog.V(2).Infof("get file share(%s) account(%s) quota from cache", fileShareName, accountName)
itemSnapshotQuota = cache.(int32)
} else {
klog.V(2).Infof("get file share(%s) account(%s) quota from cloud", fileShareName, accountName)
fileshare, err := d.cloud.FileClient.WithSubscriptionID(subsID).GetFileShare(ctx, rgName, accountName, fileShareName, "")
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get file share(%s) quota: %v", fileShareName, err)
}
itemSnapshotQuota = pointer.Int32Deref(fileshare.ShareQuota, defaultAzureFileQuota)
d.getFileShareSizeCache.Set(key, itemSnapshotQuota)
}
itemSnapshotQuota = pointer.Int32Deref(fileshare.ShareQuota, defaultAzureFileQuota)
}
createResp := &csi.CreateSnapshotResponse{
Snapshot: &csi.Snapshot{
Expand Down

0 comments on commit 233877e

Please # to comment.