Skip to content

Commit 822d18f

Browse files
authored
Merge pull request #1764 from k8s-infra-cherrypick-robot/cherry-pick-1761-to-release-1.24
[release-1.24] fix: wait for azcopy job running in volume clone
2 parents 0c5e464 + f5048f4 commit 822d18f

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

pkg/blob/controllerserver.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,17 @@ func (d *Driver) copyBlobContainer(ctx context.Context, req *csi.CreateVolumeReq
793793
case util.AzcopyJobError, util.AzcopyJobCompleted:
794794
return err
795795
case util.AzcopyJobRunning:
796-
return fmt.Errorf("wait for the existing AzCopy job to complete, current copy percentage is %s%%", percent)
796+
err = wait.PollImmediate(20*time.Second, time.Duration(d.waitForAzCopyTimeoutMinutes)*time.Minute, func() (bool, error) {
797+
jobState, percent, err := d.azcopy.GetAzcopyJob(dstContainerName, authAzcopyEnv)
798+
klog.V(2).Infof("azcopy job status: %s, copy percent: %s%%, error: %v", jobState, percent, err)
799+
if err != nil {
800+
return false, err
801+
}
802+
if jobState == util.AzcopyJobRunning {
803+
return false, nil
804+
}
805+
return true, nil
806+
})
797807
case util.AzcopyJobNotFound:
798808
klog.V(2).Infof("copy blob container %s:%s to %s:%s", srcAccountName, srcContainerName, dstAccountName, dstContainerName)
799809
execFunc := func() error {
@@ -806,13 +816,12 @@ func (d *Driver) copyBlobContainer(ctx context.Context, req *csi.CreateVolumeReq
806816
_, percent, _ := d.azcopy.GetAzcopyJob(dstContainerName, authAzcopyEnv)
807817
return fmt.Errorf("timeout waiting for copy blob container %s to %s complete, current copy percent: %s%%", srcContainerName, dstContainerName, percent)
808818
}
809-
copyErr := util.WaitUntilTimeout(time.Duration(d.waitForAzCopyTimeoutMinutes)*time.Minute, execFunc, timeoutFunc)
810-
if copyErr != nil {
811-
klog.Warningf("CopyBlobContainer(%s, %s, %s) failed with error: %v", accountOptions.ResourceGroup, dstAccountName, dstContainerName, copyErr)
812-
} else {
813-
klog.V(2).Infof("copied blob container %s to %s successfully", srcContainerName, dstContainerName)
814-
}
815-
return copyErr
819+
err = util.WaitUntilTimeout(time.Duration(d.waitForAzCopyTimeoutMinutes)*time.Minute, execFunc, timeoutFunc)
820+
}
821+
if err != nil {
822+
klog.Warningf("CopyBlobContainer(%s, %s, %s) failed with error: %v", accountOptions.ResourceGroup, dstAccountName, dstContainerName, err)
823+
} else {
824+
klog.V(2).Infof("copied blob container %s to %s successfully", srcContainerName, dstContainerName)
816825
}
817826
return err
818827
}

pkg/blob/controllerserver_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,7 @@ func TestCopyVolume(t *testing.T) {
16781678
name: "azcopy job is in progress",
16791679
testFunc: func(t *testing.T) {
16801680
ctx := context.Background()
1681+
accountOptions := azure.AccountOptions{}
16811682
d := NewFakeDriver()
16821683
mp := map[string]string{}
16831684

@@ -1703,14 +1704,14 @@ func TestCopyVolume(t *testing.T) {
17031704

17041705
m := util.NewMockEXEC(ctrl)
17051706
listStr1 := "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: InProgress\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false"
1706-
m.EXPECT().RunCommand(gomock.Eq("azcopy jobs list | grep dstContainer -B 3"), gomock.Any()).Return(listStr1, nil).Times(1)
1707-
m.EXPECT().RunCommand(gomock.Not("azcopy jobs list | grep dstBlobContainer -B 3"), gomock.Any()).Return("Percent Complete (approx): 50.0", nil)
1707+
m.EXPECT().RunCommand(gomock.Eq("azcopy jobs list | grep dstContainer -B 3"), gomock.Any()).Return(listStr1, nil).AnyTimes()
1708+
m.EXPECT().RunCommand(gomock.Not("azcopy jobs list | grep dstBlobContainer -B 3"), gomock.Any()).Return("Percent Complete (approx): 50.0", nil).AnyTimes()
17081709

17091710
d.azcopy.ExecCmd = m
1711+
d.waitForAzCopyTimeoutMinutes = 1
17101712

1711-
expectedErr := fmt.Errorf("wait for the existing AzCopy job to complete, current copy percentage is 50.0%%")
1712-
err := d.copyVolume(ctx, req, "", "sastoken", nil, "dstContainer", "", nil, "core.windows.net")
1713-
if !reflect.DeepEqual(err, expectedErr) {
1713+
err := d.copyVolume(ctx, req, "", "sastoken", nil, "dstContainer", "", &accountOptions, "core.windows.net")
1714+
if !reflect.DeepEqual(err, wait.ErrWaitTimeout) {
17141715
t.Errorf("Unexpected error: %v", err)
17151716
}
17161717
},

0 commit comments

Comments
 (0)