@@ -365,21 +365,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
365365 }
366366 defer d .volumeLocks .Release (volName )
367367
368- var volumeID string
369368 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- }()
383369
384370 var srcAzcopyAuthEnv []string
385371 var srcSubscriptionID , srcResourceGroupName , srcAccountName , srcContainerName , srcPath , srcAccountSASToken string
@@ -388,6 +374,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
388374 case * csi.VolumeContentSource_Snapshot :
389375 return nil , status .Errorf (codes .InvalidArgument , "VolumeContentSource Snapshot is not yet implemented" )
390376 case * csi.VolumeContentSource_Volume :
377+ requestName = "controller_create_volume_from_volume"
391378 var srcVolumeID string
392379 if volContentSource .GetVolume () != nil {
393380 srcVolumeID = volContentSource .GetVolume ().GetVolumeId ()
@@ -412,6 +399,13 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
412399 }
413400 }
414401
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+
415409 var accountKey string
416410 accountName := account
417411 if len (secrets ) == 0 && accountName == "" {
@@ -467,22 +461,19 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
467461 secrets = createStorageAccountSecret (accountName , accountKey )
468462 }
469463
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+ }
472468 if volContentSource != nil {
473- if srcSubscriptionID != subsID || srcResourceGroupName != resourceGroup || srcAccountName != accountName {
469+ dstAzcopyAuthEnv := srcAzcopyAuthEnv
470+ dstAccountSASToken := srcAccountSASToken
471+ if srcAccountName != accountName {
474472 if dstAccountSASToken , dstAzcopyAuthEnv , err = d .getAzcopyAuth (ctx , accountName , accountKey , storageEndpointSuffix , accountOptions , secrets , secretName , secretNamespace ); err != nil {
475473 return nil , status .Errorf (codes .Internal , "failed to getAzcopyAuth on account(%s) rg(%s), error: %v" , accountOptions .Name , accountOptions .ResourceGroup , err )
476474 }
477475 }
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- }
484476
485- if volContentSource != nil {
486477 dstPath := fmt .Sprintf ("https://%s.blob.%s/%s" , accountName , storageEndpointSuffix , validContainerName )
487478 if err := d .copyBlobContainer (dstAzcopyAuthEnv , srcPath , srcAccountSASToken , dstPath , dstAccountSASToken , validContainerName ); err != nil {
488479 return nil , err
0 commit comments