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

Add a timeout to waitForPodRunning #4243

Merged
merged 1 commit into from
Feb 9, 2015
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
6 changes: 5 additions & 1 deletion test/e2e/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ func TestBasicImage(c *client.Client, test string, image string) bool {
// Wait for the pods to enter the running state. Waiting loops until the pods
// are running so non-running pods cause a timeout for this test.
for _, pod := range pods.Items {
waitForPodRunning(c, pod.Name)
err = waitForPodRunning(c, pod.Name, 300*time.Second)
if err != nil {
glog.Errorf("waitForPodRunningFailed: %v", err.Error())
return false
}
}

// Try to make sure we get a hostIP for each pod.
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ var _ = Describe("Events", func() {
}()

By("waiting for the pod to start running")
waitForPodRunning(c, pod.Name)
err = waitForPodRunning(c, pod.Name, 300*time.Second)
Expect(err).NotTo(HaveOccurred())

By("verifying the pod is in kubernetes")
pods, err := podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})))
Expand Down
9 changes: 6 additions & 3 deletions test/e2e/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ var _ = Describe("Pods", func() {
}()

By("waiting for the pod to start running")
waitForPodRunning(c, pod.Name)
err = waitForPodRunning(c, pod.Name, 300*time.Second)
Expect(err).NotTo(HaveOccurred())

By("verifying the pod is in kubernetes")
pods, err := podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})))
Expand All @@ -168,7 +169,8 @@ var _ = Describe("Pods", func() {
}

By("waiting for the updated pod to start running")
waitForPodRunning(c, pod.Name)
err = waitForPodRunning(c, pod.Name, 300*time.Second)
Expect(err).NotTo(HaveOccurred())

By("verifying the updated pod is in kubernetes")
pods, err = podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})))
Expand Down Expand Up @@ -203,7 +205,8 @@ var _ = Describe("Pods", func() {
defer GinkgoRecover()
c.Pods(api.NamespaceDefault).Delete(serverPod.Name)
}()
waitForPodRunning(c, serverPod.Name)
err = waitForPodRunning(c, serverPod.Name, 300*time.Second)
Expect(err).NotTo(HaveOccurred())

// This service exposes port 8080 of the test pod as a service on port 8765
// TODO(filbranden): We would like to use a unique service name such as:
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ var _ = Describe("Services", func() {
}()

By("waiting for the pod to start running")
waitForPodRunning(c, pod.Name)
err = waitForPodRunning(c, pod.Name, 300*time.Second)
Expect(err).NotTo(HaveOccurred())

By("retrieving the pod")
pod, err = podClient.Get(pod.Name)
Expand Down
16 changes: 10 additions & 6 deletions test/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package e2e

import (
"fmt"
"io/ioutil"
"math/rand"
"path/filepath"
Expand All @@ -29,6 +30,8 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/clientauth"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/golang/glog"

. "github.com/onsi/ginkgo"
)

type testContextType struct {
Expand All @@ -41,19 +44,20 @@ type testContextType struct {

var testContext testContextType

func waitForPodRunning(c *client.Client, id string) {
for {
func waitForPodRunning(c *client.Client, id string, tryFor time.Duration) error {
trySecs := int(tryFor.Seconds())
for i := 0; i <= trySecs; i += 5 {
time.Sleep(5 * time.Second)
pod, err := c.Pods(api.NamespaceDefault).Get(id)
if err != nil {
glog.Warningf("Get pod %s failed: %v", id, err)
continue
return fmt.Errorf("Get pod %s failed: %v", id, err.Error())
}
if pod.Status.Phase == api.PodRunning {
break
return nil
}
glog.Infof("Waiting for pod %s status to be %q (found %q)", id, api.PodRunning, pod.Status.Phase)
By(fmt.Sprintf("Waiting for pod %s status to be %q (found %q) (%d secs)", id, api.PodRunning, pod.Status.Phase, i))
}
return fmt.Errorf("Gave up waiting for pod %s to be running after %d seconds", id, trySecs)
}

// waitForPodNotPending returns false if it took too long for the pod to go out of pending state.
Expand Down