@@ -61,8 +61,6 @@ const (
61
61
MSI = "MSI"
62
62
SPN = "SPN"
63
63
authorizationPermissionMismatch = "AuthorizationPermissionMismatch"
64
-
65
- waitForAzCopyInterval = 2 * time .Second
66
64
)
67
65
68
66
// CreateVolume provisions a volume
@@ -85,7 +83,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
85
83
// logging the job status if it's volume cloning
86
84
if req .GetVolumeContentSource () != nil {
87
85
jobState , percent , err := d .azcopy .GetAzcopyJob (volName , []string {})
88
- klog . V ( 2 ). Infof ( "azcopy job status: %s, copy percent: %s%%, error: %v" , jobState , percent , err )
86
+ return nil , status . Errorf ( codes . Aborted , volumeOperationAlreadyExistsWithAzcopyFmt , volName , jobState , percent , err )
89
87
}
90
88
return nil , status .Errorf (codes .Aborted , volumeOperationAlreadyExistsFmt , volName )
91
89
}
@@ -759,43 +757,41 @@ func (d *Driver) copyBlobContainer(req *csi.CreateVolumeRequest, accountSasToken
759
757
return fmt .Errorf ("srcContainerName(%s) or dstContainerName(%s) is empty" , srcContainerName , dstContainerName )
760
758
}
761
759
762
- timeAfter := time .After (time .Duration (d .waitForAzCopyTimeoutMinutes ) * time .Minute )
763
- timeTick := time .Tick (waitForAzCopyInterval )
764
760
srcPath := fmt .Sprintf ("https://%s.blob.%s/%s%s" , accountName , storageEndpointSuffix , srcContainerName , accountSasToken )
765
761
dstPath := fmt .Sprintf ("https://%s.blob.%s/%s%s" , accountName , storageEndpointSuffix , dstContainerName , accountSasToken )
766
762
767
763
jobState , percent , err := d .azcopy .GetAzcopyJob (dstContainerName , authAzcopyEnv )
768
764
klog .V (2 ).Infof ("azcopy job status: %s, copy percent: %s%%, error: %v" , jobState , percent , err )
769
- if jobState == util .AzcopyJobError || jobState == util .AzcopyJobCompleted {
765
+ switch jobState {
766
+ case util .AzcopyJobError , util .AzcopyJobCompleted :
770
767
return err
771
- }
772
- klog .V (2 ).Infof ("begin to copy blob container %s to %s" , srcContainerName , dstContainerName )
773
- for {
774
- select {
775
- case <- timeTick :
776
- jobState , percent , err := d .azcopy .GetAzcopyJob (dstContainerName , authAzcopyEnv )
777
- klog .V (2 ).Infof ("azcopy job status: %s, copy percent: %s%%, error: %v" , jobState , percent , err )
778
- switch jobState {
779
- case util .AzcopyJobError , util .AzcopyJobCompleted :
780
- return err
781
- case util .AzcopyJobNotFound :
782
- klog .V (2 ).Infof ("copy blob container %s to %s" , srcContainerName , dstContainerName )
783
- cmd := exec .Command ("azcopy" , "copy" , srcPath , dstPath , "--recursive" , "--check-length=false" )
784
- if len (authAzcopyEnv ) > 0 {
785
- cmd .Env = append (os .Environ (), authAzcopyEnv ... )
786
- }
787
- out , copyErr := cmd .CombinedOutput ()
788
- if copyErr != nil {
789
- klog .Warningf ("CopyBlobContainer(%s, %s, %s) failed with error(%v): %v" , resourceGroupName , accountName , dstPath , copyErr , string (out ))
790
- } else {
791
- klog .V (2 ).Infof ("copied blob container %s to %s successfully" , srcContainerName , dstContainerName )
792
- }
793
- return copyErr
768
+ case util .AzcopyJobRunning :
769
+ return fmt .Errorf ("wait for the existing AzCopy job to complete, current copy percentage is %s%%" , percent )
770
+ case util .AzcopyJobNotFound :
771
+ klog .V (2 ).Infof ("copy blob container %s to %s" , srcContainerName , dstContainerName )
772
+ execFunc := func () error {
773
+ cmd := exec .Command ("azcopy" , "copy" , srcPath , dstPath , "--recursive" , "--check-length=false" )
774
+ if len (authAzcopyEnv ) > 0 {
775
+ cmd .Env = append (os .Environ (), authAzcopyEnv ... )
776
+ }
777
+ if out , err := cmd .CombinedOutput (); err != nil {
778
+ return fmt .Errorf ("exec error: %v, output: %v" , err , string (out ))
794
779
}
795
- case <- timeAfter :
796
- return fmt .Errorf ("timeout waiting for copy blob container %s to %s succeed" , srcContainerName , dstContainerName )
780
+ return nil
781
+ }
782
+ timeoutFunc := func () error {
783
+ _ , percent , _ := d .azcopy .GetAzcopyJob (dstContainerName , authAzcopyEnv )
784
+ return fmt .Errorf ("timeout waiting for copy blob container %s to %s complete, current copy percent: %s%%" , srcContainerName , dstContainerName , percent )
785
+ }
786
+ copyErr := util .WaitForExecCompletion (time .Duration (d .waitForAzCopyTimeoutMinutes )* time .Minute , execFunc , timeoutFunc )
787
+ if copyErr != nil {
788
+ klog .Warningf ("CopyBlobContainer(%s, %s, %s) failed with error: %v" , resourceGroupName , accountName , dstPath , copyErr )
789
+ } else {
790
+ klog .V (2 ).Infof ("copied blob container %s to %s successfully" , srcContainerName , dstContainerName )
797
791
}
792
+ return copyErr
798
793
}
794
+ return err
799
795
}
800
796
801
797
// copyVolume copies a volume form volume or snapshot, snapshot is not supported now
0 commit comments