Skip to content

Commit 12c5399

Browse files
committed
fix: delay removing skipMatchingTag when account is full
1 parent 0c39cd4 commit 12c5399

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

pkg/azurefile/azurefile.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ type DriverOptions struct {
198198
KubeAPIQPS float64
199199
KubeAPIBurst int
200200
AppendNoShareSockOption bool
201+
SkipMatchingTagCacheExpireInMinutes int
201202
}
202203

203204
// Driver implements all interfaces of CSI drivers
@@ -238,8 +239,8 @@ type Driver struct {
238239
dataPlaneAPIAccountCache *azcache.TimedCache
239240
// a timed cache storing account search history (solve account list throttling issue)
240241
accountSearchCache *azcache.TimedCache
241-
// a timed cache storing tag removing history (solve account update throttling issue)
242-
removeTagCache *azcache.TimedCache
242+
// a timed cache storing whether skipMatchingTag is added or removed recently
243+
skipMatchingTagCache *azcache.TimedCache
243244
// a timed cache when resize file share failed due to account limit exceeded
244245
resizeFileShareFailureCache *azcache.TimedCache
245246
}
@@ -279,7 +280,10 @@ func NewDriver(options *DriverOptions) *Driver {
279280
klog.Fatalf("%v", err)
280281
}
281282

282-
if driver.removeTagCache, err = azcache.NewTimedcache(3*time.Minute, getter); err != nil {
283+
if options.SkipMatchingTagCacheExpireInMinutes <= 0 {
284+
options.SkipMatchingTagCacheExpireInMinutes = 30 // default expire in 30 minutes
285+
}
286+
if driver.skipMatchingTagCache, err = azcache.NewTimedcache(time.Duration(options.SkipMatchingTagCacheExpireInMinutes)*time.Minute, getter); err != nil {
283287
klog.Fatalf("%v", err)
284288
}
285289

@@ -866,17 +870,17 @@ func (d *Driver) GetTotalAccountQuota(ctx context.Context, subsID, resourceGroup
866870
// RemoveStorageAccountTag remove tag from storage account
867871
func (d *Driver) RemoveStorageAccountTag(ctx context.Context, subsID, resourceGroup, account, key string) error {
868872
// search in cache first
869-
cache, err := d.removeTagCache.Get(account, azcache.CacheReadTypeDefault)
873+
cache, err := d.skipMatchingTagCache.Get(account, azcache.CacheReadTypeDefault)
870874
if err != nil {
871875
return err
872876
}
873877
if cache != nil {
874-
klog.V(6).Infof("skip remove tag(%s) on account(%s) subsID(%s) resourceGroup(%s) since tag already removed in a short time", key, account, subsID, resourceGroup)
878+
klog.V(6).Infof("skip remove tag(%s) on account(%s) subsID(%s) resourceGroup(%s) since tag is added or removed in a short time", key, account, subsID, resourceGroup)
875879
return nil
876880
}
877881

878882
klog.V(2).Infof("remove tag(%s) on account(%s) subsID(%s), resourceGroup(%s)", key, account, subsID, resourceGroup)
879-
defer d.removeTagCache.Set(account, key)
883+
defer d.skipMatchingTagCache.Set(account, "")
880884
if rerr := d.cloud.RemoveStorageAccountTag(ctx, subsID, resourceGroup, account, key); rerr != nil {
881885
return rerr.Error()
882886
}

pkg/azurefile/controllerserver.go

+2
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
486486
if rerr := d.cloud.AddStorageAccountTags(ctx, subsID, resourceGroup, accountName, skipMatchingTag); rerr != nil {
487487
klog.Warningf("AddStorageAccountTags(%v) on account(%s) subsID(%s) rg(%s) failed with error: %v", tags, accountName, subsID, resourceGroup, rerr.Error())
488488
}
489+
// do not remove skipMatchingTag in a period of time
490+
d.skipMatchingTagCache.Set(accountName, "")
489491
// release volume lock first to prevent deadlock
490492
d.volumeLocks.Release(volName)
491493
// clean search cache

pkg/azurefileplugin/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ var (
5555
kubeAPIQPS = flag.Float64("kube-api-qps", 25.0, "QPS to use while communicating with the kubernetes apiserver.")
5656
kubeAPIBurst = flag.Int("kube-api-burst", 50, "Burst to use while communicating with the kubernetes apiserver.")
5757
appendNoShareSockOption = flag.Bool("append-nosharesock-option", true, "Whether appending nosharesock option to smb mount command")
58+
skipMatchingTagCacheExpireInMinutes = flag.Int("skip-matching-tag-cache-expire-in-minutes", 30, "The cache expire time in minutes for skipMatchingTagCache")
5859
)
5960

6061
func main() {
@@ -95,6 +96,7 @@ func handle() {
9596
KubeAPIQPS: *kubeAPIQPS,
9697
KubeAPIBurst: *kubeAPIBurst,
9798
AppendNoShareSockOption: *appendNoShareSockOption,
99+
SkipMatchingTagCacheExpireInMinutes: *skipMatchingTagCacheExpireInMinutes,
98100
}
99101
driver := azurefile.NewDriver(&driverOptions)
100102
if driver == nil {

0 commit comments

Comments
 (0)