@@ -93,7 +93,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
9393 }
9494 var storageAccountType , subsID , resourceGroup , location , account , containerName , containerNamePrefix , protocol , customTags , secretName , secretNamespace , pvcNamespace , tagValueDelimiter string
9595 var isHnsEnabled , requireInfraEncryption , enableBlobVersioning , createPrivateEndpoint , enableNfsV3 , allowSharedKeyAccess * bool
96- var vnetResourceGroup , vnetName , subnetName , accessTier , networkEndpointType , storageEndpointSuffix , fsGroupChangePolicy string
96+ var vnetResourceGroup , vnetName , subnetName , accessTier , networkEndpointType , storageEndpointSuffix , fsGroupChangePolicy , srcAccountName string
9797 var matchTags , useDataPlaneAPI , getLatestAccountKey bool
9898 var softDeleteBlobs , softDeleteContainers int32
9999 var vnetResourceIDs []string
@@ -309,6 +309,25 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
309309 return nil , status .Errorf (codes .InvalidArgument , "storeAccountKey is not supported for account with shared access key disabled" )
310310 }
311311
312+ requestName := "controller_create_volume"
313+ if volContentSource != nil {
314+ switch volContentSource .Type .(type ) {
315+ case * csi.VolumeContentSource_Snapshot :
316+ return nil , status .Errorf (codes .InvalidArgument , "VolumeContentSource Snapshot is not yet implemented" )
317+ case * csi.VolumeContentSource_Volume :
318+ requestName = "controller_create_volume_from_volume"
319+ if volContentSource .GetVolume () != nil {
320+ sourceID := volContentSource .GetVolume ().VolumeId
321+ _ , srcAccountName , _ , _ , _ , err = GetContainerInfo (sourceID ) //nolint:dogsled
322+ if err != nil {
323+ klog .Errorf ("failed to get source volume info from sourceID(%s), error: %v" , sourceID , err )
324+ } else {
325+ klog .V (2 ).Infof ("source volume account name: %s, sourceID: %s" , srcAccountName , sourceID )
326+ }
327+ }
328+ }
329+ }
330+
312331 accountOptions := & azure.AccountOptions {
313332 Name : account ,
314333 Type : storageAccountType ,
@@ -336,6 +355,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
336355 SoftDeleteBlobs : softDeleteBlobs ,
337356 SoftDeleteContainers : softDeleteContainers ,
338357 GetLatestAccountKey : getLatestAccountKey ,
358+ SourceAccountName : srcAccountName ,
339359 }
340360
341361 containerName = replaceWithMap (containerName , containerNameReplaceMap )
@@ -359,16 +379,6 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
359379 }
360380 defer d .volumeLocks .Release (volName )
361381
362- requestName := "controller_create_volume"
363- if volContentSource != nil {
364- switch volContentSource .Type .(type ) {
365- case * csi.VolumeContentSource_Snapshot :
366- return nil , status .Errorf (codes .InvalidArgument , "VolumeContentSource Snapshot is not yet implemented" )
367- case * csi.VolumeContentSource_Volume :
368- requestName = "controller_create_volume_from_volume"
369- }
370- }
371-
372382 var volumeID string
373383 mc := metrics .NewMetricContext (blobCSIDriverName , requestName , d .cloud .ResourceGroup , d .cloud .SubscriptionID , d .Name )
374384 isOperationSucceeded := false
@@ -440,8 +450,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
440450 if err != nil {
441451 return nil , status .Errorf (codes .Internal , "failed to getAzcopyAuth on account(%s) rg(%s), error: %v" , accountOptions .Name , accountOptions .ResourceGroup , err )
442452 }
443- var copyErr error
444- copyErr = d .copyVolume (ctx , req , accountName , accountSASToken , authAzcopyEnv , validContainerName , secretNamespace , accountOptions , storageEndpointSuffix )
453+ copyErr := d .copyVolume (ctx , req , accountName , accountSASToken , authAzcopyEnv , validContainerName , secretNamespace , accountOptions , storageEndpointSuffix )
445454 if accountSASToken == "" && copyErr != nil && strings .Contains (copyErr .Error (), authorizationPermissionMismatch ) {
446455 klog .Warningf ("azcopy copy failed with AuthorizationPermissionMismatch error, should assign \" Storage Blob Data Contributor\" role to controller identity, fall back to use sas token, original error: %v" , copyErr )
447456 accountSASToken , authAzcopyEnv , err := d .getAzcopyAuth (ctx , accountName , accountKey , storageEndpointSuffix , accountOptions , secrets , secretName , secretNamespace , true )
0 commit comments