Skip to content

Commit a3a4320

Browse files
committed
Wait for PV to be available before creating PVCs in volume binding test
1 parent 5b1fb22 commit a3a4320

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/integration/volumescheduling/volume_binding_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,20 @@ func TestVolumeBinding(t *testing.T) {
215215
}
216216
}
217217

218+
// Wait for PVs to become available to avoid race condition in PV controller
219+
// https://github.com/kubernetes/kubernetes/issues/85320
220+
for _, pvConfig := range test.pvs {
221+
if err := waitForPVPhase(config.client, pvConfig.name, v1.VolumeAvailable); err != nil {
222+
t.Fatalf("PersistentVolume %q failed to become available: %v", pvConfig.name, err)
223+
}
224+
}
225+
226+
for _, pvConfig := range test.unboundPvs {
227+
if err := waitForPVPhase(config.client, pvConfig.name, v1.VolumeAvailable); err != nil {
228+
t.Fatalf("PersistentVolume %q failed to become available: %v", pvConfig.name, err)
229+
}
230+
}
231+
218232
// Create PVCs
219233
for _, pvcConfig := range test.pvcs {
220234
pvc := makePVC(pvcConfig.name, config.ns, &classes[pvcConfig.scName].Name, pvcConfig.preboundPV)
@@ -1180,6 +1194,20 @@ func validatePVPhase(t *testing.T, client clientset.Interface, pvName string, ph
11801194
}
11811195
}
11821196

1197+
func waitForPVPhase(client clientset.Interface, pvName string, phase v1.PersistentVolumePhase) error {
1198+
return wait.PollImmediate(time.Second, 30*time.Second, func() (bool, error) {
1199+
pv, err := client.CoreV1().PersistentVolumes().Get(pvName, metav1.GetOptions{})
1200+
if err != nil {
1201+
return false, err
1202+
}
1203+
1204+
if pv.Status.Phase == phase {
1205+
return true, nil
1206+
}
1207+
return false, nil
1208+
})
1209+
}
1210+
11831211
func waitForPVCBound(client clientset.Interface, pvc *v1.PersistentVolumeClaim) error {
11841212
return wait.Poll(time.Second, 30*time.Second, func() (bool, error) {
11851213
claim, err := client.CoreV1().PersistentVolumeClaims(pvc.Namespace).Get(pvc.Name, metav1.GetOptions{})

0 commit comments

Comments
 (0)