@@ -286,7 +286,9 @@ func TestPersistentVolumeBindRace(t *testing.T) {
286
286
287
287
waitForPersistentVolumePhase (testClient , pv .Name , watchPV , v1 .VolumeBound )
288
288
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
+ }
290
292
klog .V (2 ).Infof ("TestPersistentVolumeBindRace pvc bound" )
291
293
292
294
pv , err = testClient .CoreV1 ().PersistentVolumes ().Get (context .TODO (), pv .Name , metav1.GetOptions {})
@@ -873,10 +875,11 @@ func TestPersistentVolumeMultiPVsPVCs(t *testing.T) {
873
875
}()
874
876
875
877
// 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 )
879
881
}
882
+
880
883
// wait until the binder pairs all volumes
881
884
for i := 0 ; i < objCount ; i ++ {
882
885
waitForPersistentVolumePhase (testClient , pvs [i ].Name , watchPV , v1 .VolumeBound )
@@ -954,7 +957,9 @@ func TestPersistentVolumeControllerStartup(t *testing.T) {
954
957
// Drain watchPVC with all events generated by the PVC until it's bound
955
958
// We don't want to catch "PVC created with Status.Phase == Pending"
956
959
// 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
+ }
958
963
959
964
pv := createPV (pvName , "/tmp/foo" + strconv .Itoa (i ), "1G" ,
960
965
[]v1.PersistentVolumeAccessMode {v1 .ReadWriteOnce }, v1 .PersistentVolumeReclaimRetain )
@@ -1091,22 +1096,7 @@ func TestPersistentVolumeProvisionMultiPVCs(t *testing.T) {
1091
1096
}()
1092
1097
1093
1098
// 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 )
1110
1100
if err != nil {
1111
1101
t .Fatalf ("Failed to wait for all claims to be bound: %v" , err )
1112
1102
}
@@ -1477,6 +1467,27 @@ func waitForAnyPersistentVolumePhase(w watch.Interface, phase v1.PersistentVolum
1477
1467
}
1478
1468
}
1479
1469
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
+
1480
1491
func waitForAnyPersistentVolumeClaimPhase (w watch.Interface , phase v1.PersistentVolumeClaimPhase ) error {
1481
1492
for {
1482
1493
event , ok := <- w .ResultChan ()
0 commit comments