Wait for all pods to be running before checking PDB status.

Hoping to avoid timeout errors as in #34032.
pull/6/head
Matt Liggett 2016-10-18 18:01:27 -07:00
parent b844a0722c
commit c04ab43df5
1 changed files with 30 additions and 0 deletions

View File

@ -61,6 +61,7 @@ var _ = framework.KubeDescribe("DisruptionController", func() {
createPodDisruptionBudgetOrDie(cs, ns, intstr.FromInt(2))
createPodsOrDie(cs, ns, 3)
waitForPodsOrDie(cs, ns, 3)
// Since disruptionAllowed starts out false, if we see it ever become true,
// that means the controller is working.
@ -218,6 +219,35 @@ func createPodsOrDie(cs *kubernetes.Clientset, ns string, n int) {
}
}
func waitForPodsOrDie(cs *kubernetes.Clientset, ns string, n int) {
By("Waiting for all pods to be running")
err := wait.PollImmediate(framework.Poll, schedulingTimeout, func() (bool, error) {
pods, err := cs.Core().Pods(ns).List(api.ListOptions{LabelSelector: "foo=bar"})
if err != nil {
return false, err
}
if pods == nil {
return false, fmt.Errorf("pods is nil")
}
if len(pods.Items) < n {
framework.Logf("pods: %v < %v", len(pods.Items), n)
return false, nil
}
ready := 0
for i := 0; i < n; i++ {
if pods.Items[i].Status.Phase == api.PodRunning {
ready++
}
}
if ready < n {
framework.Logf("running pods: %v < %v", ready, n)
return false, nil
}
return true, nil
})
framework.ExpectNoError(err, "Waiting for pods in namespace %q to be ready", ns)
}
func createReplicaSetOrDie(cs *kubernetes.Clientset, ns string, size int32, exclusive bool) {
container := api.Container{
Name: "busybox",