@@ -440,7 +440,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
440
440
if err != nil {
441
441
return nil , status .Errorf (codes .Internal , "failed to getAzcopyAuth on account(%s) rg(%s), error: %v" , accountOptions .Name , accountOptions .ResourceGroup , err )
442
442
}
443
- if err := d .copyVolume (req , accountSASToken , authAzcopyEnv , validContainerName , storageEndpointSuffix ); err != nil {
443
+ if err := d .copyVolume (req , accountSASToken , authAzcopyEnv , accountName , validContainerName , storageEndpointSuffix ); err != nil {
444
444
return nil , err
445
445
}
446
446
} else {
@@ -755,23 +755,24 @@ func (d *Driver) DeleteBlobContainer(ctx context.Context, subsID, resourceGroupN
755
755
})
756
756
}
757
757
758
- // CopyBlobContainer copies a blob container in the same storage account
759
- func (d * Driver ) copyBlobContainer (req * csi.CreateVolumeRequest , accountSasToken string , authAzcopyEnv []string , dstContainerName , storageEndpointSuffix string ) error {
758
+ // CopyBlobContainer copies a blob container
759
+ func (d * Driver ) copyBlobContainer (req * csi.CreateVolumeRequest , accountSasToken string , authAzcopyEnv []string , dstAccountName , dstContainerName , storageEndpointSuffix string ) error {
760
760
var sourceVolumeID string
761
761
if req .GetVolumeContentSource () != nil && req .GetVolumeContentSource ().GetVolume () != nil {
762
762
sourceVolumeID = req .GetVolumeContentSource ().GetVolume ().GetVolumeId ()
763
763
764
764
}
765
- resourceGroupName , accountName , srcContainerName , _ , _ , err := GetContainerInfo (sourceVolumeID ) //nolint:dogsled
765
+ _ , srcAccountName , srcContainerName , _ , _ , err := GetContainerInfo (sourceVolumeID ) //nolint:dogsled
766
766
if err != nil {
767
767
return status .Error (codes .NotFound , err .Error ())
768
768
}
769
- if srcContainerName == "" || dstContainerName == "" {
770
- return fmt .Errorf ("srcContainerName(%s) or dstContainerName(%s) is empty" , srcContainerName , dstContainerName )
769
+ if srcAccountName == "" || srcContainerName == "" || dstAccountName == "" || dstContainerName == "" {
770
+ return fmt .Errorf ("One or more of srcAccountName(%s), srcContainerName(%s), dstAccountName(%s), dstContainerName(%s) are empty" , srcAccountName , srcContainerName , dstAccountName , dstContainerName )
771
771
}
772
772
773
- srcPath := fmt .Sprintf ("https://%s.blob.%s/%s%s" , accountName , storageEndpointSuffix , srcContainerName , accountSasToken )
774
- dstPath := fmt .Sprintf ("https://%s.blob.%s/%s%s" , accountName , storageEndpointSuffix , dstContainerName , accountSasToken )
773
+ srcPath := fmt .Sprintf ("https://%s.blob.%s/%s" , srcAccountName , storageEndpointSuffix , srcContainerName )
774
+ dstPath := fmt .Sprintf ("https://%s.blob.%s/%s" , dstAccountName , storageEndpointSuffix , dstContainerName )
775
+
775
776
776
777
jobState , percent , err := d .azcopy .GetAzcopyJob (dstContainerName , authAzcopyEnv )
777
778
klog .V (2 ).Infof ("azcopy job status: %s, copy percent: %s%%, error: %v" , jobState , percent , err )
@@ -781,9 +782,9 @@ func (d *Driver) copyBlobContainer(req *csi.CreateVolumeRequest, accountSasToken
781
782
case util .AzcopyJobRunning :
782
783
return fmt .Errorf ("wait for the existing AzCopy job to complete, current copy percentage is %s%%" , percent )
783
784
case util .AzcopyJobNotFound :
784
- klog .V (2 ).Infof ("copy blob container %s to %s" , srcContainerName , dstContainerName )
785
+ klog .V (2 ).Infof ("copy blob container %s to %s" , srcPath , dstPath )
785
786
execFunc := func () error {
786
- cmd := exec .Command ("azcopy" , "copy" , srcPath , dstPath , "--recursive" , "--check-length=false" )
787
+ cmd := exec .Command ("azcopy" , "copy" , srcPath + accountSasToken , dstPath + accountSasToken , "--recursive" , "--check-length=false" )
787
788
if len (authAzcopyEnv ) > 0 {
788
789
cmd .Env = append (os .Environ (), authAzcopyEnv ... )
789
790
}
@@ -794,11 +795,11 @@ func (d *Driver) copyBlobContainer(req *csi.CreateVolumeRequest, accountSasToken
794
795
}
795
796
timeoutFunc := func () error {
796
797
_ , percent , _ := d .azcopy .GetAzcopyJob (dstContainerName , authAzcopyEnv )
797
- return fmt .Errorf ("timeout waiting for copy blob container %s to %s complete, current copy percent: %s%%" , srcContainerName , dstContainerName , percent )
798
+ return fmt .Errorf ("timeout waiting for copy blob container %s to %s complete, current copy percent: %s%%" , srcPath , dstPath , percent )
798
799
}
799
800
copyErr := util .WaitUntilTimeout (time .Duration (d .waitForAzCopyTimeoutMinutes )* time .Minute , execFunc , timeoutFunc )
800
801
if copyErr != nil {
801
- klog .Warningf ("CopyBlobContainer(%s, %s, %s) failed with error: %v" , resourceGroupName , accountName , dstPath , copyErr )
802
+ klog .Warningf ("CopyBlobContainer(%s, %s, %s, %s ) failed with error: %v" , srcAccountName , srcContainerName , dstAccountName , dstContainerName , copyErr )
802
803
} else {
803
804
klog .V (2 ).Infof ("copied blob container %s to %s successfully" , srcContainerName , dstContainerName )
804
805
}
@@ -808,13 +809,13 @@ func (d *Driver) copyBlobContainer(req *csi.CreateVolumeRequest, accountSasToken
808
809
}
809
810
810
811
// copyVolume copies a volume form volume or snapshot, snapshot is not supported now
811
- func (d * Driver ) copyVolume (req * csi.CreateVolumeRequest , accountSASToken string , authAzcopyEnv []string , dstContainerName , storageEndpointSuffix string ) error {
812
+ func (d * Driver ) copyVolume (req * csi.CreateVolumeRequest , accountSASToken string , authAzcopyEnv []string , dstAccountName , dstContainerName , storageEndpointSuffix string ) error {
812
813
vs := req .VolumeContentSource
813
814
switch vs .Type .(type ) {
814
815
case * csi.VolumeContentSource_Snapshot :
815
816
return status .Errorf (codes .InvalidArgument , "copy volume from volumeSnapshot is not supported" )
816
817
case * csi.VolumeContentSource_Volume :
817
- return d .copyBlobContainer (req , accountSASToken , authAzcopyEnv , dstContainerName , storageEndpointSuffix )
818
+ return d .copyBlobContainer (req , accountSASToken , authAzcopyEnv , dstAccountName , dstContainerName , storageEndpointSuffix )
818
819
default :
819
820
return status .Errorf (codes .InvalidArgument , "%v is not a proper volume source" , vs )
820
821
}
0 commit comments