Wait for PV to be available before creating PVCs in volume binding test

This commit is contained in:
Michelle Au 2019-11-26 16:58:25 -08:00
parent 5b1fb221b6
commit a3a4320aff

View File

@ -215,6 +215,20 @@ func TestVolumeBinding(t *testing.T) {
}
}
// Wait for PVs to become available to avoid race condition in PV controller
// https://github.com/kubernetes/kubernetes/issues/85320
for _, pvConfig := range test.pvs {
if err := waitForPVPhase(config.client, pvConfig.name, v1.VolumeAvailable); err != nil {
t.Fatalf("PersistentVolume %q failed to become available: %v", pvConfig.name, err)
}
}
for _, pvConfig := range test.unboundPvs {
if err := waitForPVPhase(config.client, pvConfig.name, v1.VolumeAvailable); err != nil {
t.Fatalf("PersistentVolume %q failed to become available: %v", pvConfig.name, err)
}
}
// Create PVCs
for _, pvcConfig := range test.pvcs {
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
}
}
func waitForPVPhase(client clientset.Interface, pvName string, phase v1.PersistentVolumePhase) error {
return wait.PollImmediate(time.Second, 30*time.Second, func() (bool, error) {
pv, err := client.CoreV1().PersistentVolumes().Get(pvName, metav1.GetOptions{})
if err != nil {
return false, err
}
if pv.Status.Phase == phase {
return true, nil
}
return false, nil
})
}
func waitForPVCBound(client clientset.Interface, pvc *v1.PersistentVolumeClaim) error {
return wait.Poll(time.Second, 30*time.Second, func() (bool, error) {
claim, err := client.CoreV1().PersistentVolumeClaims(pvc.Namespace).Get(pvc.Name, metav1.GetOptions{})