diff --git a/pkg/azurefile/azurefile.go b/pkg/azurefile/azurefile.go index c2c2739491..41b43beecc 100644 --- a/pkg/azurefile/azurefile.go +++ b/pkg/azurefile/azurefile.go @@ -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 + getFileShareSizeCache azcache.Resource // sas expiry time for azcopy in volume clone and snapshot restore sasTokenExpirationMinutes int // azcopy timeout for volume clone and snapshot restore @@ -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 } diff --git a/pkg/azurefile/controllerserver.go b/pkg/azurefile/controllerserver.go index 59f3398728..2ed7112eb9 100644 --- a/pkg/azurefile/controllerserver.go +++ b/pkg/azurefile/controllerserver.go @@ -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{