77
77
Mode : csi .VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER ,
78
78
},
79
79
}
80
+ skipMatchingTag = map [string ]* string {azure .SkipMatchingTag : pointer .String ("" )}
80
81
)
81
82
82
83
// CreateVolume provisions an azure file
@@ -452,6 +453,20 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
452
453
if err != nil {
453
454
return nil , status .Errorf (codes .Internal , "failed to ensure storage account: %v" , err )
454
455
}
456
+ totalQuotaGB , fileshareNum , err := d .GetTotalQuotaGB (ctx , subsID , resourceGroup , accountName )
457
+ if err != nil {
458
+ return nil , status .Errorf (codes .Internal , "failed to get total quota on account(%s), error: %v" , accountName , err )
459
+ }
460
+ klog .V (2 ).Infof ("total used quota on account(%s) is %d GB, file share number: %d" , accountName , totalQuotaGB , fileshareNum )
461
+ if totalQuotaGB > 81920 {
462
+ klog .Warningf ("account(%s) used quota(%d GB) is over 81920 GB, skip matching current account" , accountName , totalQuotaGB )
463
+ if rerr := d .cloud .AddStorageAccountTags (ctx , subsID , resourceGroup , accountName , skipMatchingTag ); rerr != nil {
464
+ klog .Warningf ("AddStorageAccountTags(%v) on account(%s) subsID(%s) rg(%s) failed with error: %v" , tags , accountName , subsID , resourceGroup , rerr .Error ())
465
+ }
466
+ // release volume lock first to prevent deadlock
467
+ d .volumeLocks .Release (volName )
468
+ return d .CreateVolume (ctx , req )
469
+ }
455
470
d .accountSearchCache .Set (lockKey , accountName )
456
471
d .volMap .Store (volName , accountName )
457
472
if accountKey != "" {
@@ -502,10 +517,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
502
517
if err := d .CreateFileShare (ctx , accountOptions , shareOptions , secret ); err != nil {
503
518
if strings .Contains (err .Error (), accountLimitExceedManagementAPI ) || strings .Contains (err .Error (), accountLimitExceedDataPlaneAPI ) {
504
519
klog .Warningf ("create file share(%s) on account(%s) type(%s) subID(%s) rg(%s) location(%s) size(%d), error: %v, skip matching current account" , validFileShareName , accountName , sku , subsID , resourceGroup , location , fileShareSize , err )
505
- tags := map [string ]* string {
506
- azure .SkipMatchingTag : pointer .String ("" ),
507
- }
508
- if rerr := d .cloud .AddStorageAccountTags (ctx , subsID , resourceGroup , accountName , tags ); rerr != nil {
520
+ if rerr := d .cloud .AddStorageAccountTags (ctx , subsID , resourceGroup , accountName , skipMatchingTag ); rerr != nil {
509
521
klog .Warningf ("AddStorageAccountTags(%v) on account(%s) subsID(%s) rg(%s) failed with error: %v" , tags , accountName , subsID , resourceGroup , rerr .Error ())
510
522
}
511
523
// release volume lock first to prevent deadlock
@@ -514,7 +526,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
514
526
if err := d .accountSearchCache .Delete (lockKey ); err != nil {
515
527
return nil , status .Errorf (codes .Internal , err .Error ())
516
528
}
517
- // remove the volName from the volMap to stop it matching the same storage account
529
+ // remove the volName from the volMap to stop matching the same storage account
518
530
d .volMap .Delete (volName )
519
531
return d .CreateVolume (ctx , req )
520
532
}
0 commit comments