Skip to content

Commit 4a8205b

Browse files
authored
Merge pull request kubernetes#85620 from msau42/debug-integration
decrease test pv controller resync period to try to deflake api update conflicts
2 parents bc53b97 + a3a4320 commit 4a8205b

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

test/integration/volumescheduling/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ go_test(
1717
tags = ["integration"],
1818
deps = [
1919
"//pkg/controller/volume/persistentvolume:go_default_library",
20-
"//pkg/controller/volume/persistentvolume/options:go_default_library",
2120
"//pkg/scheduler/algorithm/predicates:go_default_library",
2221
"//pkg/volume:go_default_library",
2322
"//pkg/volume/testing:go_default_library",

test/integration/volumescheduling/volume_binding_test.go

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
clientset "k8s.io/client-go/kubernetes"
4141
"k8s.io/client-go/util/workqueue"
4242
"k8s.io/kubernetes/pkg/controller/volume/persistentvolume"
43-
persistentvolumeoptions "k8s.io/kubernetes/pkg/controller/volume/persistentvolume/options"
4443
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
4544
"k8s.io/kubernetes/pkg/volume"
4645
volumetest "k8s.io/kubernetes/pkg/volume/testing"
@@ -216,6 +215,20 @@ func TestVolumeBinding(t *testing.T) {
216215
}
217216
}
218217

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+
219232
// Create PVCs
220233
for _, pvcConfig := range test.pvcs {
221234
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
926939

927940
func initPVController(t *testing.T, context *testContext, provisionDelaySeconds int) (*persistentvolume.PersistentVolumeController, informers.SharedInformerFactory, error) {
928941
clientset := context.clientSet
929-
// Informers factory for controllers, we disable resync period for testing.
942+
// Informers factory for controllers
930943
informerFactory := informers.NewSharedInformerFactory(clientset, 0)
931944

932945
// Start PV controller for volume binding.
@@ -946,10 +959,11 @@ func initPVController(t *testing.T, context *testContext, provisionDelaySeconds
946959
}
947960
plugins := []volume.VolumePlugin{plugin}
948961

949-
controllerOptions := persistentvolumeoptions.NewPersistentVolumeControllerOptions()
950962
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,
953967
VolumePlugins: plugins,
954968
Cloud: nil,
955969
ClusterName: "volume-test-cluster",
@@ -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)