@@ -92,7 +92,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
92
92
}
93
93
var storageAccountType , subsID , resourceGroup , location , account , containerName , containerNamePrefix , protocol , customTags , secretName , secretNamespace , pvcNamespace , tagValueDelimiter string
94
94
var isHnsEnabled , requireInfraEncryption , enableBlobVersioning , createPrivateEndpoint , enableNfsV3 , allowSharedKeyAccess * bool
95
- var vnetResourceGroup , vnetName , subnetName , accessTier , networkEndpointType , storageEndpointSuffix , fsGroupChangePolicy string
95
+ var vnetResourceGroup , vnetName , subnetName , accessTier , networkEndpointType , storageEndpointSuffix , fsGroupChangePolicy , srcAccountName string
96
96
var matchTags , useDataPlaneAPI , getLatestAccountKey bool
97
97
var softDeleteBlobs , softDeleteContainers int32
98
98
var vnetResourceIDs []string
@@ -308,6 +308,25 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
308
308
return nil , status .Errorf (codes .InvalidArgument , "storeAccountKey is not supported for account with shared access key disabled" )
309
309
}
310
310
311
+ requestName := "controller_create_volume"
312
+ if volContentSource != nil {
313
+ switch volContentSource .Type .(type ) {
314
+ case * csi.VolumeContentSource_Snapshot :
315
+ return nil , status .Errorf (codes .InvalidArgument , "VolumeContentSource Snapshot is not yet implemented" )
316
+ case * csi.VolumeContentSource_Volume :
317
+ requestName = "controller_create_volume_from_volume"
318
+ if volContentSource .GetVolume () != nil {
319
+ sourceID := volContentSource .GetVolume ().VolumeId
320
+ _ , srcAccountName , _ , _ , _ , err = GetContainerInfo (sourceID ) //nolint:dogsled
321
+ if err != nil {
322
+ klog .Errorf ("failed to get source volume info from sourceID(%s), error: %v" , sourceID , err )
323
+ } else {
324
+ klog .V (2 ).Infof ("source volume account name: %s, sourceID: %s" , srcAccountName , sourceID )
325
+ }
326
+ }
327
+ }
328
+ }
329
+
311
330
accountOptions := & azure.AccountOptions {
312
331
Name : account ,
313
332
Type : storageAccountType ,
@@ -335,6 +354,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
335
354
SoftDeleteBlobs : softDeleteBlobs ,
336
355
SoftDeleteContainers : softDeleteContainers ,
337
356
GetLatestAccountKey : getLatestAccountKey ,
357
+ SourceAccountName : srcAccountName ,
338
358
}
339
359
340
360
containerName = replaceWithMap (containerName , containerNameReplaceMap )
@@ -358,16 +378,6 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
358
378
}
359
379
defer d .volumeLocks .Release (volName )
360
380
361
- requestName := "controller_create_volume"
362
- if volContentSource != nil {
363
- switch volContentSource .Type .(type ) {
364
- case * csi.VolumeContentSource_Snapshot :
365
- return nil , status .Errorf (codes .InvalidArgument , "VolumeContentSource Snapshot is not yet implemented" )
366
- case * csi.VolumeContentSource_Volume :
367
- requestName = "controller_create_volume_from_volume"
368
- }
369
- }
370
-
371
381
var volumeID string
372
382
mc := metrics .NewMetricContext (blobCSIDriverName , requestName , d .cloud .ResourceGroup , d .cloud .SubscriptionID , d .Name )
373
383
isOperationSucceeded := false
@@ -439,8 +449,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
439
449
if err != nil {
440
450
return nil , status .Errorf (codes .Internal , "failed to getAzcopyAuth on account(%s) rg(%s), error: %v" , accountOptions .Name , accountOptions .ResourceGroup , err )
441
451
}
442
- var copyErr error
443
- copyErr = d .copyVolume (ctx , req , accountName , accountSASToken , authAzcopyEnv , validContainerName , secretNamespace , accountOptions , storageEndpointSuffix )
452
+ copyErr := d .copyVolume (ctx , req , accountName , accountSASToken , authAzcopyEnv , validContainerName , secretNamespace , accountOptions , storageEndpointSuffix )
444
453
if accountSASToken == "" && copyErr != nil && strings .Contains (copyErr .Error (), authorizationPermissionMismatch ) {
445
454
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 )
446
455
accountSASToken , authAzcopyEnv , err := d .getAzcopyAuth (ctx , accountName , accountKey , storageEndpointSuffix , accountOptions , secrets , secretName , secretNamespace , true )
0 commit comments