@@ -40,7 +40,6 @@ import (
40
40
clientset "k8s.io/client-go/kubernetes"
41
41
"k8s.io/client-go/util/workqueue"
42
42
"k8s.io/kubernetes/pkg/controller/volume/persistentvolume"
43
- persistentvolumeoptions "k8s.io/kubernetes/pkg/controller/volume/persistentvolume/options"
44
43
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
45
44
"k8s.io/kubernetes/pkg/volume"
46
45
volumetest "k8s.io/kubernetes/pkg/volume/testing"
@@ -216,6 +215,20 @@ func TestVolumeBinding(t *testing.T) {
216
215
}
217
216
}
218
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
+
219
232
// Create PVCs
220
233
for _ , pvcConfig := range test .pvcs {
221
234
pvc := makePVC (pvcConfig .name , config .ns , & classes [pvcConfig .scName ].Name , pvcConfig .preboundPV )
@@ -926,7 +939,7 @@ func setupCluster(t *testing.T, nsName string, numberOfNodes int, resyncPeriod t
926
939
927
940
func initPVController (t * testing.T , context * testContext , provisionDelaySeconds int ) (* persistentvolume.PersistentVolumeController , informers.SharedInformerFactory , error ) {
928
941
clientset := context .clientSet
929
- // Informers factory for controllers, we disable resync period for testing.
942
+ // Informers factory for controllers
930
943
informerFactory := informers .NewSharedInformerFactory (clientset , 0 )
931
944
932
945
// Start PV controller for volume binding.
@@ -946,10 +959,11 @@ func initPVController(t *testing.T, context *testContext, provisionDelaySeconds
946
959
}
947
960
plugins := []volume.VolumePlugin {plugin }
948
961
949
- controllerOptions := persistentvolumeoptions .NewPersistentVolumeControllerOptions ()
950
962
params := persistentvolume.ControllerParameters {
951
- KubeClient : clientset ,
952
- SyncPeriod : controllerOptions .PVClaimBinderSyncPeriod ,
963
+ KubeClient : clientset ,
964
+ // Use a frequent resync period to retry API update conflicts due to
965
+ // https://github.com/kubernetes/kubernetes/issues/85320
966
+ SyncPeriod : 5 * time .Second ,
953
967
VolumePlugins : plugins ,
954
968
Cloud : nil ,
955
969
ClusterName : "volume-test-cluster" ,
@@ -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