From 2d7e2eb09ff1884b698ca39dbe63643fd548a7cd Mon Sep 17 00:00:00 2001 From: Prashanth Balasubramanian Date: Wed, 4 May 2016 13:47:34 -0700 Subject: [PATCH] Modify e2e to wait for RC to stabilize before test --- test/e2e/framework/util.go | 30 ++++++++++++++++++++++++++++++ test/e2e/kubectl.go | 1 + 2 files changed, 31 insertions(+) diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index cfb0c201e35..5d689b2d48f 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -1005,6 +1005,36 @@ func waitForRCPodOnNode(c *client.Client, ns, rcName, node string) (*api.Pod, er return p, err } +// WaitForRCToStabilize waits till the RC has a matching generation/replica count between spec and status. +func WaitForRCToStabilize(c *client.Client, ns, name string, timeout time.Duration) error { + options := api.ListOptions{FieldSelector: fields.Set{ + "metadata.name": name, + "metadata.namespace": ns, + }.AsSelector()} + w, err := c.ReplicationControllers(ns).Watch(options) + if err != nil { + return err + } + _, err = watch.Until(timeout, w, func(event watch.Event) (bool, error) { + switch event.Type { + case watch.Deleted: + return false, apierrs.NewNotFound(unversioned.GroupResource{Resource: "replicationcontrollers"}, "") + } + switch rc := event.Object.(type) { + case *api.ReplicationController: + if rc.Name == name && rc.Namespace == ns && + rc.Generation <= rc.Status.ObservedGeneration && + rc.Spec.Replicas == rc.Status.Replicas { + return true, nil + } + Logf("Waiting for rc %s to stabilize, generation %v observed generation %v spec.replicas %d status.replicas %d", + name, rc.Generation, rc.Status.ObservedGeneration, rc.Spec.Replicas, rc.Status.Replicas) + } + return false, nil + }) + return err +} + func WaitForPodToDisappear(c *client.Client, ns, podName string, label labels.Selector, interval, timeout time.Duration) error { return wait.PollImmediate(interval, timeout, func() (bool, error) { Logf("Waiting for pod %s to disappear", podName) diff --git a/test/e2e/kubectl.go b/test/e2e/kubectl.go index 3fe811357bd..31ce0278a8d 100644 --- a/test/e2e/kubectl.go +++ b/test/e2e/kubectl.go @@ -1052,6 +1052,7 @@ var _ = framework.KubeDescribe("Kubectl client", func() { if containers == nil || len(containers) != 1 || containers[0].Image != nginxImage { framework.Failf("Failed creating rc %s for 1 pod with expected image %s", rcName, nginxImage) } + framework.WaitForRCToStabilize(c, ns, rcName, framework.PodStartTimeout) By("rolling-update to same image controller") framework.RunKubectlOrDie("rolling-update", rcName, "--update-period=1s", "--image="+nginxImage, "--image-pull-policy="+string(api.PullIfNotPresent), nsFlag)