Skip to content

Commit

Permalink
Convert waitForPodNotPending from glog to By, and to error form
Browse files Browse the repository at this point in the history
Also change it to take a variable timeout
  • Loading branch information
zmerlynn committed Feb 9, 2015
1 parent 2e4a1e9 commit ff67052
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
5 changes: 3 additions & 2 deletions test/e2e/liveness.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ func runLivenessTest(c *client.Client, podDescr *api.Pod) bool {
// Wait until the pod is not pending. (Here we need to check for something other than
// 'Pending' other than checking for 'Running', since when failures occur, we go to
// 'Terminated' which can cause indefinite blocking.)
if !waitForPodNotPending(c, ns, podDescr.Name) {
glog.Infof("Failed to start pod %s in namespace %s", podDescr.Name, ns)
err = waitForPodNotPending(c, ns, podDescr.Name, 60*time.Second)
if err != nil {
glog.Infof("Failed to start pod %s in namespace %s: %v", podDescr.Name, ns, err)
return false
}
glog.Infof("Started pod %s in namespace %s", podDescr.Name, ns)
Expand Down
16 changes: 8 additions & 8 deletions test/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,24 @@ func waitForPodRunning(c *client.Client, id string, tryFor time.Duration) error
}

// waitForPodNotPending returns false if it took too long for the pod to go out of pending state.
func waitForPodNotPending(c *client.Client, ns, podName string) bool {
for i := 0; i < 10; i++ {
func waitForPodNotPending(c *client.Client, ns, podName string, tryFor time.Duration) error {
trySecs := int(tryFor.Seconds())
for i := 0; i <= trySecs; i += 5 {
if i > 0 {
time.Sleep(5 * time.Second)
}
pod, err := c.Pods(ns).Get(podName)
if err != nil {
glog.Warningf("Get pod %s in namespace %s failed: %v", podName, ns, err)
By(fmt.Sprintf("Get pod %s in namespace %s failed, ignoring for 5s: %v", podName, ns, err))
continue
}
if pod.Status.Phase != api.PodPending {
glog.Infof("Saw pod %s in namespace %s out of pending state (found %q)", podName, ns, pod.Status.Phase)
return true
By(fmt.Sprintf("Saw pod %s in namespace %s out of pending state (found %q)", podName, ns, pod.Status.Phase))
return nil
}
glog.Infof("Waiting for status of pod %s in namespace %s to be !%q (found %q)", podName, ns, api.PodPending, pod.Status.Phase)
By(fmt.Sprintf("Waiting for status of pod %s in namespace %s to be !%q (found %q) (%v secs)", podName, ns, api.PodPending, pod.Status.Phase, i))
}
glog.Warningf("Gave up waiting for status of pod %s in namespace %s to go out of pending", podName, ns)
return false
return fmt.Errorf("Gave up waiting for status of pod %s in namespace %s to go out of pending after %d seconds", podName, ns, trySecs)
}

// waitForPodSuccess returns true if the pod reached state success, or false if it reached failure or ran too long.
Expand Down

0 comments on commit ff67052

Please sign in to comment.