@@ -33,6 +33,7 @@ import (
33
33
"k8s.io/klog/v2"
34
34
35
35
"sigs.k8s.io/blob-csi-driver/pkg/util"
36
+ azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
36
37
"sigs.k8s.io/cloud-provider-azure/pkg/metrics"
37
38
azure "sigs.k8s.io/cloud-provider-azure/pkg/provider"
38
39
)
@@ -189,20 +190,30 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
189
190
var accountKey string
190
191
accountName := account
191
192
if len (req .GetSecrets ()) == 0 && accountName == "" {
192
- lockKey := storageAccountType + accountKind + resourceGroup + location
193
- d .volLockMap .LockEntry (lockKey )
194
- err = wait .ExponentialBackoff (d .cloud .RequestBackoff (), func () (bool , error ) {
195
- var retErr error
196
- accountName , accountKey , retErr = d .cloud .EnsureStorageAccount (ctx , accountOptions , protocol )
197
- if isRetriableError (retErr ) {
198
- klog .Warningf ("EnsureStorageAccount(%s) failed with error(%v), waiting for retrying" , account , retErr )
199
- return false , nil
200
- }
201
- return true , retErr
202
- })
203
- d .volLockMap .UnlockEntry (lockKey )
193
+ lockKey := fmt .Sprintf ("%s%s%s%s%s" , storageAccountType , accountKind , resourceGroup , location , protocol )
194
+ // search in cache first
195
+ cache , err := d .accountSearchCache .Get (lockKey , azcache .CacheReadTypeDefault )
204
196
if err != nil {
205
- return nil , status .Errorf (codes .Internal , "failed to ensure storage account: %v" , err )
197
+ return nil , err
198
+ }
199
+ if cache != nil {
200
+ accountName = cache .(string )
201
+ } else {
202
+ d .volLockMap .LockEntry (lockKey )
203
+ err = wait .ExponentialBackoff (d .cloud .RequestBackoff (), func () (bool , error ) {
204
+ var retErr error
205
+ accountName , accountKey , retErr = d .cloud .EnsureStorageAccount (ctx , accountOptions , protocol )
206
+ if isRetriableError (retErr ) {
207
+ klog .Warningf ("EnsureStorageAccount(%s) failed with error(%v), waiting for retrying" , account , retErr )
208
+ return false , nil
209
+ }
210
+ return true , retErr
211
+ })
212
+ d .volLockMap .UnlockEntry (lockKey )
213
+ if err != nil {
214
+ return nil , status .Errorf (codes .Internal , "failed to ensure storage account: %v" , err )
215
+ }
216
+ d .accountSearchCache .Set (lockKey , accountName )
206
217
}
207
218
}
208
219
accountOptions .Name = accountName
0 commit comments