Commit e4796bcf authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #43091 from gnufied/fix-dswp-flake

Automatic merge from submit-queue (batch tested with PRs 40964, 42967, 43091, 43115) fixes dswp flake Sometimes a pod may not appear in desired state of world immediately, we poll before failing. It only adds additional 30s to tests in worst case. Fixes #42990 cc @jingxu97
parents 6d2defbc 1a6c36da
...@@ -33,6 +33,7 @@ import ( ...@@ -33,6 +33,7 @@ import (
informers "k8s.io/kubernetes/pkg/client/informers/informers_generated/externalversions" informers "k8s.io/kubernetes/pkg/client/informers/informers_generated/externalversions"
fakecloud "k8s.io/kubernetes/pkg/cloudprovider/providers/fake" fakecloud "k8s.io/kubernetes/pkg/cloudprovider/providers/fake"
"k8s.io/kubernetes/pkg/controller/volume/attachdetach" "k8s.io/kubernetes/pkg/controller/volume/attachdetach"
volumecache "k8s.io/kubernetes/pkg/controller/volume/attachdetach/cache"
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
volumetest "k8s.io/kubernetes/pkg/volume/testing" volumetest "k8s.io/kubernetes/pkg/volume/testing"
"k8s.io/kubernetes/pkg/volume/util/volumehelper" "k8s.io/kubernetes/pkg/volume/util/volumehelper"
...@@ -128,11 +129,7 @@ func TestPodDeletionWithDswp(t *testing.T) { ...@@ -128,11 +129,7 @@ func TestPodDeletionWithDswp(t *testing.T) {
t.Fatalf("Pod not found in Pod Informer cache : %v", err) t.Fatalf("Pod not found in Pod Informer cache : %v", err)
} }
podsToAdd := ctrl.GetDesiredStateOfWorld().GetPodToAdd() waitForPodsInDSWP(t, ctrl.GetDesiredStateOfWorld())
if len(podsToAdd) == 0 {
t.Fatalf("Pod not added to desired state of world")
}
// let's stop pod events from getting triggered // let's stop pod events from getting triggered
close(podStopCh) close(podStopCh)
...@@ -144,7 +141,7 @@ func TestPodDeletionWithDswp(t *testing.T) { ...@@ -144,7 +141,7 @@ func TestPodDeletionWithDswp(t *testing.T) {
waitToObservePods(t, podInformer, 0) waitToObservePods(t, podInformer, 0)
// the populator loop turns every 1 minute // the populator loop turns every 1 minute
time.Sleep(80 * time.Second) time.Sleep(80 * time.Second)
podsToAdd = ctrl.GetDesiredStateOfWorld().GetPodToAdd() podsToAdd := ctrl.GetDesiredStateOfWorld().GetPodToAdd()
if len(podsToAdd) != 0 { if len(podsToAdd) != 0 {
t.Fatalf("All pods should have been removed") t.Fatalf("All pods should have been removed")
} }
...@@ -168,6 +165,19 @@ func waitToObservePods(t *testing.T, podInformer cache.SharedIndexInformer, podN ...@@ -168,6 +165,19 @@ func waitToObservePods(t *testing.T, podInformer cache.SharedIndexInformer, podN
} }
} }
// wait for pods to be observed in desired state of world
func waitForPodsInDSWP(t *testing.T, dswp volumecache.DesiredStateOfWorld) {
if err := wait.Poll(time.Millisecond*500, wait.ForeverTestTimeout, func() (bool, error) {
pods := dswp.GetPodToAdd()
if len(pods) > 0 {
return true, nil
}
return false, nil
}); err != nil {
t.Fatalf("Pod not added to desired state of world : %v", err)
}
}
func createAdClients(ns *v1.Namespace, t *testing.T, server *httptest.Server, syncPeriod time.Duration) (*clientset.Clientset, attachdetach.AttachDetachController, informers.SharedInformerFactory) { func createAdClients(ns *v1.Namespace, t *testing.T, server *httptest.Server, syncPeriod time.Duration) (*clientset.Clientset, attachdetach.AttachDetachController, informers.SharedInformerFactory) {
config := restclient.Config{ config := restclient.Config{
Host: server.URL, Host: server.URL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment