Convert waitForPodSuccess to error form, glog->By

* Also add variable timeout as well
* And nail in coffin for glog in this file!
pull/6/head
Zach Loafman 2015-02-09 07:48:07 -08:00
parent ff67052408
commit fe838fca64
2 changed files with 13 additions and 16 deletions

View File

@ -275,10 +275,8 @@ var _ = Describe("Pods", func() {
}() }()
// Wait for client pod to complete. // Wait for client pod to complete.
success := waitForPodSuccess(c, clientPod.Name, clientPod.Spec.Containers[0].Name) err = waitForPodSuccess(c, clientPod.Name, clientPod.Spec.Containers[0].Name, 60*time.Second)
if !success { Expect(err).NotTo(HaveOccurred())
Fail(fmt.Sprintf("Failed to run client pod to detect service env vars."))
}
// Grab its logs. Get host first. // Grab its logs. Get host first.
clientPodStatus, err := c.Pods(api.NamespaceDefault).Get(clientPod.Name) clientPodStatus, err := c.Pods(api.NamespaceDefault).Get(clientPod.Name)

View File

@ -26,7 +26,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/clientauth" "github.com/GoogleCloudPlatform/kubernetes/pkg/clientauth"
"github.com/golang/glog"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
) )
@ -79,36 +78,36 @@ func waitForPodNotPending(c *client.Client, ns, podName string, tryFor time.Dura
} }
// waitForPodSuccess returns true if the pod reached state success, or false if it reached failure or ran too long. // waitForPodSuccess returns true if the pod reached state success, or false if it reached failure or ran too long.
func waitForPodSuccess(c *client.Client, podName string, contName string) bool { func waitForPodSuccess(c *client.Client, podName string, contName string, tryFor time.Duration) error {
for i := 0; i < 10; i++ { trySecs := int(tryFor.Seconds())
for i := 0; i <= trySecs; i += 5 {
if i > 0 { if i > 0 {
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
} }
pod, err := c.Pods(api.NamespaceDefault).Get(podName) pod, err := c.Pods(api.NamespaceDefault).Get(podName)
if err != nil { if err != nil {
glog.Warningf("Get pod failed: %v", err) By(fmt.Sprintf("Get pod failed, ignoring for 5s: %v", err))
continue continue
} }
// Cannot use pod.Status.Phase == api.PodSucceeded/api.PodFailed due to #2632 // Cannot use pod.Status.Phase == api.PodSucceeded/api.PodFailed due to #2632
ci, ok := pod.Status.Info[contName] ci, ok := pod.Status.Info[contName]
if !ok { if !ok {
glog.Infof("No Status.Info for container %s in pod %s yet", contName, podName) By(fmt.Sprintf("No Status.Info for container %s in pod %s yet", contName, podName))
} else { } else {
if ci.State.Termination != nil { if ci.State.Termination != nil {
if ci.State.Termination.ExitCode == 0 { if ci.State.Termination.ExitCode == 0 {
glog.Infof("Saw pod success") By("Saw pod success")
return true return nil
} else { } else {
glog.Infof("Saw pod failure: %+v", ci.State.Termination) By(fmt.Sprintf("Saw pod failure: %+v", ci.State.Termination))
} }
glog.Infof("Waiting for pod %q status to be success or failure", podName) By(fmt.Sprintf("Waiting for pod %q status to be success or failure", podName))
} else { } else {
glog.Infof("Nil State.Termination for container %s in pod %s so far", contName, podName) By(fmt.Sprintf("Nil State.Termination for container %s in pod %s so far", contName, podName))
} }
} }
} }
glog.Warningf("Gave up waiting for pod %q status to be success or failure", podName) return fmt.Errorf("Gave up waiting for pod %q status to be success or failure after %d seconds", podName, trySecs)
return false
} }
func loadClient() (*client.Client, error) { func loadClient() (*client.Client, error) {