From 4673731c0bc70aa813ab264e911b0042df8a5f91 Mon Sep 17 00:00:00 2001 From: Morten Torkildsen Date: Tue, 14 Jan 2020 10:33:43 -0800 Subject: [PATCH] Make sure PDB has observed pods before doing eviction in e2e test --- test/e2e/apps/disruption.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/e2e/apps/disruption.go b/test/e2e/apps/disruption.go index b71e52d9269..4b4ad4ae983 100644 --- a/test/e2e/apps/disruption.go +++ b/test/e2e/apps/disruption.go @@ -223,6 +223,7 @@ var _ = SIGDescribe("DisruptionController", func() { ginkgo.By("Trying to evict the same pod we tried earlier which should now be evictable") waitForPodsOrDie(cs, ns, 3) + waitForPdbToObserveHealthyPods(cs, ns, 3) err = cs.CoreV1().Pods(ns).Evict(e) framework.ExpectNoError(err) // the eviction is now allowed }) @@ -402,3 +403,18 @@ func waitForPdbToBeProcessed(cs kubernetes.Interface, ns string) { }) framework.ExpectNoError(err, "Waiting for the pdb to be processed in namespace %s", ns) } + +func waitForPdbToObserveHealthyPods(cs kubernetes.Interface, ns string, healthyCount int32) { + ginkgo.By("Waiting for the pdb to observed all healthy pods") + err := wait.PollImmediate(framework.Poll, wait.ForeverTestTimeout, func() (bool, error) { + pdb, err := cs.PolicyV1beta1().PodDisruptionBudgets(ns).Get("foo", metav1.GetOptions{}) + if err != nil { + return false, err + } + if pdb.Status.CurrentHealthy != healthyCount { + return false, nil + } + return true, nil + }) + framework.ExpectNoError(err, "Waiting for the pdb in namespace %s to observed %d healthy pods", ns, healthyCount) +}