Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick of 15813: Fix races in ClusterDns e2e test #16037

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion test/e2e/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,13 @@ var _ = Describe("Examples e2e", func() {
for _, ns := range namespaces {
newKubectlCommand("create", "-f", "-", getNsCmdFlag(ns)).withStdinData(updatedPodYaml).exec()
}
// remember that we cannot wait for the pods to be running because our pods terminate by themselves.

// wait until the pods have been scheduler, i.e. are not Pending anymore. Remember
// that we cannot wait for the pods to be running because our pods terminate by themselves.
for _, ns := range namespaces {
err := waitForPodNotPending(c, ns.Name, frontendPodName)
expectNoError(err)
}

// wait for pods to print their result
for _, ns := range namespaces {
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/kube-ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util/wait"

. "github.com/onsi/ginkgo"
Expand All @@ -30,7 +31,7 @@ import (
var _ = Describe("kube-ui", func() {
const (
uiServiceName = "kube-ui"
uiRcName = uiServiceName
uiAppName = uiServiceName
uiNamespace = api.NamespaceSystem

serverStartTimeout = 1 * time.Minute
Expand All @@ -44,7 +45,8 @@ var _ = Describe("kube-ui", func() {
Expect(err).NotTo(HaveOccurred())

By("Checking to make sure the kube-ui pods are running")
err = waitForRCPodsRunning(f.Client, uiNamespace, uiRcName)
selector := labels.SelectorFromSet(labels.Set(map[string]string{"k8s-app": uiAppName}))
err = waitForPodsWithLabelRunning(f.Client, uiNamespace, selector)
Expect(err).NotTo(HaveOccurred())

By("Checking to make sure we get a response from the kube-ui.")
Expand Down
20 changes: 17 additions & 3 deletions test/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1438,15 +1438,29 @@ func ScaleRC(c *client.Client, ns, name string, size uint, wait bool) error {
return waitForRCPodsRunning(c, ns, name)
}

// Wait up to 10 minutes for pods to become Running.
// Wait up to 10 minutes for pods to become Running. Assume that the pods of the
// rc are labels with {"name":rcName}.
func waitForRCPodsRunning(c *client.Client, ns, rcName string) error {
selector := labels.SelectorFromSet(labels.Set(map[string]string{"name": rcName}))
err := waitForPodsWithLabelRunning(c, ns, selector)
if err != nil {
return fmt.Errorf("Error while waiting for replication controller %s pods to be running: %v", rcName, err)
}
return nil
}

// Wait up to 10 minutes for all matching pods to become Running and at least one
// matching pod exists.
func waitForPodsWithLabelRunning(c *client.Client, ns string, label labels.Selector) error {
running := false
label := labels.SelectorFromSet(labels.Set(map[string]string{"name": rcName}))
podStore := newPodStore(c, ns, label, fields.Everything())
defer podStore.Stop()
waitLoop:
for start := time.Now(); time.Since(start) < 10*time.Minute; time.Sleep(5 * time.Second) {
pods := podStore.List()
if len(pods) == 0 {
continue waitLoop
}
for _, p := range pods {
if p.Status.Phase != api.PodRunning {
continue waitLoop
Expand All @@ -1456,7 +1470,7 @@ waitLoop:
break
}
if !running {
return fmt.Errorf("Timeout while waiting for replication controller %s pods to be running", rcName)
return fmt.Errorf("Timeout while waiting for pods with labels %q to be running", label.String())
}
return nil
}
Expand Down