Skip to content

Commit c5b47e8

Browse files
andyzhangxk8s-infra-cherrypick-robot
authored andcommitted
cleanup: PollImmediate function
fix
1 parent c01b4a5 commit c5b47e8

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

pkg/azurefile/azurefile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ func (d *Driver) copyFileShare(ctx context.Context, req *csi.CreateVolumeRequest
10981098
srcPath := fmt.Sprintf("https://%s.file.%s/%s%s", srcAccountName, storageEndpointSuffix, srcFileShareName, srcAccountSasToken)
10991099
dstPath := fmt.Sprintf("https://%s.file.%s/%s%s", dstAccountName, storageEndpointSuffix, dstFileShareName, dstAccountSasToken)
11001100

1101-
return d.copyFileShareByAzcopy(srcFileShareName, dstFileShareName, srcPath, dstPath, "", srcAccountName, dstAccountName, srcAccountSasToken, authAzcopyEnv, accountOptions)
1101+
return d.copyFileShareByAzcopy(ctx, srcFileShareName, dstFileShareName, srcPath, dstPath, "", srcAccountName, dstAccountName, srcAccountSasToken, authAzcopyEnv, accountOptions)
11021102
}
11031103

11041104
// GetTotalAccountQuota returns the total quota in GB of all file shares in the storage account and the number of file shares

pkg/azurefile/controllerserver.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,10 +1114,10 @@ func (d *Driver) restoreSnapshot(ctx context.Context, req *csi.CreateVolumeReque
11141114
dstPath := fmt.Sprintf("https://%s.file.%s/%s%s", dstAccountName, storageEndpointSuffix, dstFileShareName, dstAccountSasToken)
11151115

11161116
srcFileShareSnapshotName := fmt.Sprintf("%s(snapshot: %s)", srcFileShareName, snapshot)
1117-
return d.copyFileShareByAzcopy(srcFileShareSnapshotName, dstFileShareName, srcPath, dstPath, snapshot, srcAccountName, dstAccountName, srcAccountSasToken, authAzcopyEnv, accountOptions)
1117+
return d.copyFileShareByAzcopy(ctx, srcFileShareSnapshotName, dstFileShareName, srcPath, dstPath, snapshot, srcAccountName, dstAccountName, srcAccountSasToken, authAzcopyEnv, accountOptions)
11181118
}
11191119

1120-
func (d *Driver) copyFileShareByAzcopy(srcFileShareName, dstFileShareName, srcPath, dstPath, snapshot, srcAccountName, dstAccountName, accountSASToken string, authAzcopyEnv []string, accountOptions *storage.AccountOptions) error {
1120+
func (d *Driver) copyFileShareByAzcopy(ctx context.Context, srcFileShareName, dstFileShareName, srcPath, dstPath, snapshot, srcAccountName, dstAccountName, accountSASToken string, authAzcopyEnv []string, accountOptions *storage.AccountOptions) error {
11211121
azcopyCopyOptions := azcopyCloneVolumeOptions
11221122
srcPathAuth := srcPath
11231123
if snapshot != "" {
@@ -1136,7 +1136,7 @@ func (d *Driver) copyFileShareByAzcopy(srcFileShareName, dstFileShareName, srcPa
11361136
case util.AzcopyJobError, util.AzcopyJobCompleted, util.AzcopyJobCompletedWithErrors, util.AzcopyJobCompletedWithSkipped, util.AzcopyJobCompletedWithErrorsAndSkipped:
11371137
return err
11381138
case util.AzcopyJobRunning:
1139-
err = wait.PollImmediate(20*time.Second, time.Duration(d.waitForAzCopyTimeoutMinutes)*time.Minute, func() (bool, error) {
1139+
err = wait.PollUntilContextTimeout(ctx, 20*time.Second, time.Duration(d.waitForAzCopyTimeoutMinutes)*time.Minute, true, func(context.Context) (bool, error) {
11401140
jobState, percent, err := d.azcopy.GetAzcopyJob(dstFileShareName, authAzcopyEnv)
11411141
klog.V(2).Infof("azcopy job status: %s, copy percent: %s%%, error: %v", jobState, percent, err)
11421142
if err != nil {

pkg/azurefile/controllerserver_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
"go.uber.org/mock/gomock"
3737
"google.golang.org/grpc/codes"
3838
"google.golang.org/grpc/status"
39-
"k8s.io/apimachinery/pkg/util/wait"
4039
"k8s.io/client-go/kubernetes"
4140
"k8s.io/client-go/kubernetes/fake"
4241
cloudprovider "k8s.io/cloud-provider"
@@ -1532,7 +1531,7 @@ var _ = ginkgo.Describe("TestCopyVolume", func() {
15321531
d.waitForAzCopyTimeoutMinutes = 1
15331532

15341533
err := d.copyVolume(ctx, req, "", "sastoken", []string{}, "", &ShareOptions{Name: "dstFileshare"}, &accountOptions, "core.windows.net")
1535-
gomega.Expect(err).To(gomega.Equal(wait.ErrWaitTimeout))
1534+
gomega.Expect(err).To(gomega.Equal(context.DeadlineExceeded))
15361535
})
15371536
})
15381537
})

test/e2e/testsuites/testsuites.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ func (t *TestStatefulset) Logs(ctx context.Context) ([]byte, error) {
642642
return podLogs(ctx, t.client, t.podName, t.namespace.Name)
643643
}
644644
func waitForStatefulSetComplete(ctx context.Context, cs clientset.Interface, ns *v1.Namespace, ss *apps.StatefulSet) error {
645-
err := wait.PollImmediate(poll, pollTimeout, func() (bool, error) {
645+
err := wait.PollUntilContextTimeout(ctx, poll, pollTimeout, true, func(context.Context) (bool, error) {
646646
var err error
647647
statefulSet, err := cs.AppsV1().StatefulSets(ns.Name).Get(ctx, ss.Name, metav1.GetOptions{})
648648
if err != nil {
@@ -950,7 +950,7 @@ func (t *TestVolumeSnapshotClass) CreateSnapshot(ctx context.Context, pvc *v1.Pe
950950

951951
func (t *TestVolumeSnapshotClass) ReadyToUse(ctx context.Context, snapshot *snapshotv1.VolumeSnapshot) {
952952
ginkgo.By("waiting for VolumeSnapshot to be ready to use - " + snapshot.Name)
953-
err := wait.Poll(15*time.Second, 5*time.Minute, func() (bool, error) {
953+
err := wait.PollUntilContextTimeout(ctx, 15*time.Second, 5*time.Minute, true, func(context.Context) (bool, error) {
954954
vs, err := snapshotclientset.New(t.client).SnapshotV1().VolumeSnapshots(t.namespace.Name).Get(ctx, snapshot.Name, metav1.GetOptions{})
955955
if err != nil {
956956
return false, fmt.Errorf("did not see ReadyToUse: %v", err)
@@ -1016,7 +1016,7 @@ func getWinImageTag(winServerVer string) string {
10161016

10171017
func pollForStringWorker(namespace string, pod string, command []string, expectedString string, ch chan<- error) {
10181018
args := append([]string{"exec", pod, "--"}, command...)
1019-
err := wait.PollImmediate(poll, pollForStringTimeout, func() (bool, error) {
1019+
err := wait.PollUntilContextTimeout(context.Background(), poll, pollForStringTimeout, true, func(context.Context) (bool, error) {
10201020
stdout, err := e2ekubectl.RunKubectl(namespace, args...)
10211021
if err != nil {
10221022
framework.Logf("Error waiting for output %q in pod %q: %v.", expectedString, pod, err)

0 commit comments

Comments
 (0)