@@ -93,7 +93,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
93
93
}
94
94
var storageAccountType , subsID , resourceGroup , location , account , containerName , containerNamePrefix , protocol , customTags , secretName , secretNamespace , pvcNamespace , tagValueDelimiter string
95
95
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
97
97
var matchTags , useDataPlaneAPI , getLatestAccountKey bool
98
98
var softDeleteBlobs , softDeleteContainers int32
99
99
var vnetResourceIDs []string
@@ -309,6 +309,25 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
309
309
return nil , status .Errorf (codes .InvalidArgument , "storeAccountKey is not supported for account with shared access key disabled" )
310
310
}
311
311
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
+
312
331
accountOptions := & azure.AccountOptions {
313
332
Name : account ,
314
333
Type : storageAccountType ,
@@ -336,6 +355,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
336
355
SoftDeleteBlobs : softDeleteBlobs ,
337
356
SoftDeleteContainers : softDeleteContainers ,
338
357
GetLatestAccountKey : getLatestAccountKey ,
358
+ SourceAccountName : srcAccountName ,
339
359
}
340
360
341
361
containerName = replaceWithMap (containerName , containerNameReplaceMap )
@@ -359,16 +379,6 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
359
379
}
360
380
defer d .volumeLocks .Release (volName )
361
381
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
-
372
382
var volumeID string
373
383
mc := metrics .NewMetricContext (blobCSIDriverName , requestName , d .cloud .ResourceGroup , d .cloud .SubscriptionID , d .Name )
374
384
isOperationSucceeded := false
@@ -440,8 +450,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
440
450
if err != nil {
441
451
return nil , status .Errorf (codes .Internal , "failed to getAzcopyAuth on account(%s) rg(%s), error: %v" , accountOptions .Name , accountOptions .ResourceGroup , err )
442
452
}
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 )
445
454
if accountSASToken == "" && copyErr != nil && strings .Contains (copyErr .Error (), authorizationPermissionMismatch ) {
446
455
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 )
447
456
accountSASToken , authAzcopyEnv , err := d .getAzcopyAuth (ctx , accountName , accountKey , storageEndpointSuffix , accountOptions , secrets , secretName , secretNamespace , true )
0 commit comments