@@ -365,21 +365,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
365
365
}
366
366
defer d .volumeLocks .Release (volName )
367
367
368
- var volumeID string
369
368
requestName := "controller_create_volume"
370
- if volContentSource != nil {
371
- switch volContentSource .Type .(type ) {
372
- case * csi.VolumeContentSource_Snapshot :
373
- requestName = "controller_create_volume_from_snapshot"
374
- case * csi.VolumeContentSource_Volume :
375
- requestName = "controller_create_volume_from_volume"
376
- }
377
- }
378
- mc := metrics .NewMetricContext (blobCSIDriverName , requestName , d .cloud .ResourceGroup , d .cloud .SubscriptionID , d .Name )
379
- isOperationSucceeded := false
380
- defer func () {
381
- mc .ObserveOperationWithResult (isOperationSucceeded , VolumeID , volumeID )
382
- }()
383
369
384
370
var srcAzcopyAuthEnv []string
385
371
var srcSubscriptionID , srcResourceGroupName , srcAccountName , srcContainerName , srcPath , srcAccountSASToken string
@@ -388,6 +374,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
388
374
case * csi.VolumeContentSource_Snapshot :
389
375
return nil , status .Errorf (codes .InvalidArgument , "VolumeContentSource Snapshot is not yet implemented" )
390
376
case * csi.VolumeContentSource_Volume :
377
+ requestName = "controller_create_volume_from_volume"
391
378
var srcVolumeID string
392
379
if volContentSource .GetVolume () != nil {
393
380
srcVolumeID = volContentSource .GetVolume ().GetVolumeId ()
@@ -412,6 +399,13 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
412
399
}
413
400
}
414
401
402
+ var volumeID string
403
+ mc := metrics .NewMetricContext (blobCSIDriverName , requestName , d .cloud .ResourceGroup , d .cloud .SubscriptionID , d .Name )
404
+ isOperationSucceeded := false
405
+ defer func () {
406
+ mc .ObserveOperationWithResult (isOperationSucceeded , VolumeID , volumeID )
407
+ }()
408
+
415
409
var accountKey string
416
410
accountName := account
417
411
if len (secrets ) == 0 && accountName == "" {
@@ -467,22 +461,19 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
467
461
secrets = createStorageAccountSecret (accountName , accountKey )
468
462
}
469
463
470
- dstAzcopyAuthEnv := srcAzcopyAuthEnv
471
- dstAccountSASToken := srcAccountSASToken
464
+ klog .V (2 ).Infof ("begin to create container(%s) on account(%s) type(%s) subsID(%s) rg(%s) location(%s) size(%d)" , validContainerName , accountName , storageAccountType , subsID , resourceGroup , location , requestGiB )
465
+ if err := d .CreateBlobContainer (ctx , subsID , resourceGroup , accountName , validContainerName , secrets ); err != nil {
466
+ return nil , status .Errorf (codes .Internal , "failed to create container(%s) on account(%s) type(%s) rg(%s) location(%s) size(%d), error: %v" , validContainerName , accountName , storageAccountType , resourceGroup , location , requestGiB , err )
467
+ }
472
468
if volContentSource != nil {
473
- if srcSubscriptionID != subsID || srcResourceGroupName != resourceGroup || srcAccountName != accountName {
469
+ dstAzcopyAuthEnv := srcAzcopyAuthEnv
470
+ dstAccountSASToken := srcAccountSASToken
471
+ if srcAccountName != accountName {
474
472
if dstAccountSASToken , dstAzcopyAuthEnv , err = d .getAzcopyAuth (ctx , accountName , accountKey , storageEndpointSuffix , accountOptions , secrets , secretName , secretNamespace ); err != nil {
475
473
return nil , status .Errorf (codes .Internal , "failed to getAzcopyAuth on account(%s) rg(%s), error: %v" , accountOptions .Name , accountOptions .ResourceGroup , err )
476
474
}
477
475
}
478
- }
479
-
480
- klog .V (2 ).Infof ("begin to create container(%s) on account(%s) type(%s) subsID(%s) rg(%s) location(%s) size(%d)" , validContainerName , accountName , storageAccountType , subsID , resourceGroup , location , requestGiB )
481
- if err := d .CreateBlobContainer (ctx , subsID , resourceGroup , accountName , validContainerName , secrets ); err != nil {
482
- return nil , status .Errorf (codes .Internal , "failed to create container(%s) on account(%s) type(%s) rg(%s) location(%s) size(%d), error: %v" , validContainerName , accountName , storageAccountType , resourceGroup , location , requestGiB , err )
483
- }
484
476
485
- if volContentSource != nil {
486
477
dstPath := fmt .Sprintf ("https://%s.blob.%s/%s" , accountName , storageEndpointSuffix , validContainerName )
487
478
if err := d .copyBlobContainer (dstAzcopyAuthEnv , srcPath , srcAccountSASToken , dstPath , dstAccountSASToken , validContainerName ); err != nil {
488
479
return nil , err
0 commit comments