@@ -215,6 +215,20 @@ func TestVolumeBinding(t *testing.T) {
215
215
}
216
216
}
217
217
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
+
218
232
// Create PVCs
219
233
for _ , pvcConfig := range test .pvcs {
220
234
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
1180
1194
}
1181
1195
}
1182
1196
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
+
1183
1211
func waitForPVCBound (client clientset.Interface , pvc * v1.PersistentVolumeClaim ) error {
1184
1212
return wait .Poll (time .Second , 30 * time .Second , func () (bool , error ) {
1185
1213
claim , err := client .CoreV1 ().PersistentVolumeClaims (pvc .Namespace ).Get (pvc .Name , metav1.GetOptions {})
0 commit comments