Skip to content

Commit 1eee8ff

Browse files
committed
fix lint
1 parent 19f8a78 commit 1eee8ff

File tree

2 files changed

+32
-75
lines changed

2 files changed

+32
-75
lines changed

test/integration/volume/persistent_volumes_test.go

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,9 @@ func TestPersistentVolumeBindRace(t *testing.T) {
286286

287287
waitForPersistentVolumePhase(testClient, pv.Name, watchPV, v1.VolumeBound)
288288
klog.V(2).Infof("TestPersistentVolumeBindRace pv bound")
289-
waitForAnyPersistentVolumeClaimPhase(watchPVC, v1.ClaimBound)
289+
if err := waitForAnyPersistentVolumeClaimPhase(watchPVC, v1.ClaimBound); err != nil {
290+
t.Fatalf("Unexpected error waiting for any pvc to be bound: %v", err)
291+
}
290292
klog.V(2).Infof("TestPersistentVolumeBindRace pvc bound")
291293

292294
pv, err = testClient.CoreV1().PersistentVolumes().Get(context.TODO(), pv.Name, metav1.GetOptions{})
@@ -873,10 +875,11 @@ func TestPersistentVolumeMultiPVsPVCs(t *testing.T) {
873875
}()
874876

875877
// wait until the binder pairs all claims
876-
for i := 0; i < objCount; i++ {
877-
waitForAnyPersistentVolumeClaimPhase(watchPVC, v1.ClaimBound)
878-
klog.V(1).Infof("%d claims bound", i+1)
878+
err := waitForSomePersistentVolumeClaimPhase(tCtx, testClient, namespaceName, objCount, watchPVC, v1.ClaimBound)
879+
if err != nil {
880+
t.Fatalf("Failed to wait for all claims to be bound: %v", err)
879881
}
882+
880883
// wait until the binder pairs all volumes
881884
for i := 0; i < objCount; i++ {
882885
waitForPersistentVolumePhase(testClient, pvs[i].Name, watchPV, v1.VolumeBound)
@@ -954,7 +957,9 @@ func TestPersistentVolumeControllerStartup(t *testing.T) {
954957
// Drain watchPVC with all events generated by the PVC until it's bound
955958
// We don't want to catch "PVC created with Status.Phase == Pending"
956959
// later in this test.
957-
waitForAnyPersistentVolumeClaimPhase(watchPVC, v1.ClaimBound)
960+
if err := waitForAnyPersistentVolumeClaimPhase(watchPVC, v1.ClaimBound); err != nil {
961+
t.Fatalf("Unexpected error waiting for any pvc to be bound: %v", err)
962+
}
958963

959964
pv := createPV(pvName, "/tmp/foo"+strconv.Itoa(i), "1G",
960965
[]v1.PersistentVolumeAccessMode{v1.ReadWriteOnce}, v1.PersistentVolumeReclaimRetain)
@@ -1091,22 +1096,7 @@ func TestPersistentVolumeProvisionMultiPVCs(t *testing.T) {
10911096
}()
10921097

10931098
// Wait until the controller provisions and binds all of them
1094-
err := wait.ExponentialBackoffWithContext(tCtx, retry.DefaultBackoff, func(ctx context.Context) (bool, error) {
1095-
for i := 0; i < objCount; i++ {
1096-
waitErr := waitForAnyPersistentVolumeClaimPhase(watchPVC, v1.ClaimBound)
1097-
if waitErr != nil {
1098-
newWatchPVC, err := testClient.CoreV1().PersistentVolumeClaims(namespaceName).Watch(ctx, metav1.ListOptions{})
1099-
if err != nil {
1100-
return false, err
1101-
}
1102-
watchPVC.Stop()
1103-
watchPVC = newWatchPVC
1104-
return false, waitErr
1105-
}
1106-
klog.V(1).Infof("%d claims bound", i+1)
1107-
}
1108-
return true, nil
1109-
})
1099+
err := waitForSomePersistentVolumeClaimPhase(tCtx, testClient, namespaceName, objCount, watchPVC, v1.ClaimBound)
11101100
if err != nil {
11111101
t.Fatalf("Failed to wait for all claims to be bound: %v", err)
11121102
}
@@ -1477,6 +1467,27 @@ func waitForAnyPersistentVolumePhase(w watch.Interface, phase v1.PersistentVolum
14771467
}
14781468
}
14791469

1470+
func waitForSomePersistentVolumeClaimPhase(ctx context.Context, testClient clientset.Interface, namespace string, objCount int, watchPVC watch.Interface, phase v1.PersistentVolumeClaimPhase) error {
1471+
return wait.ExponentialBackoffWithContext(ctx, retry.DefaultBackoff, func(ctx context.Context) (bool, error) {
1472+
for i := 0; i < objCount; i++ {
1473+
waitErr := waitForAnyPersistentVolumeClaimPhase(watchPVC, v1.ClaimBound)
1474+
if waitErr != nil {
1475+
klog.Errorf("Failed to wait for a claim (%d/%d) to be bound: %v", i+1, objCount, waitErr)
1476+
klog.Info("Recreating a watch for claims and re-checking the count of bound claims")
1477+
newWatchPVC, err := testClient.CoreV1().PersistentVolumeClaims(namespace).Watch(ctx, metav1.ListOptions{})
1478+
if err != nil {
1479+
return false, err
1480+
}
1481+
watchPVC.Stop()
1482+
watchPVC = newWatchPVC
1483+
return false, waitErr
1484+
}
1485+
klog.V(1).Infof("%d claims bound", i+1)
1486+
}
1487+
return true, nil
1488+
})
1489+
}
1490+
14801491
func waitForAnyPersistentVolumeClaimPhase(w watch.Interface, phase v1.PersistentVolumeClaimPhase) error {
14811492
for {
14821493
event, ok := <-w.ResultChan()

test/integration/volume/util_test.go

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)