mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-17 07:39:22 +00:00
Convert waitForPodNotPending from glog to By, and to error form
Also change it to take a variable timeout
This commit is contained in:
parent
2e4a1e910b
commit
ff67052408
@ -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
|
// 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
|
// 'Pending' other than checking for 'Running', since when failures occur, we go to
|
||||||
// 'Terminated' which can cause indefinite blocking.)
|
// 'Terminated' which can cause indefinite blocking.)
|
||||||
if !waitForPodNotPending(c, ns, podDescr.Name) {
|
err = waitForPodNotPending(c, ns, podDescr.Name, 60*time.Second)
|
||||||
glog.Infof("Failed to start pod %s in namespace %s", podDescr.Name, ns)
|
if err != nil {
|
||||||
|
glog.Infof("Failed to start pod %s in namespace %s: %v", podDescr.Name, ns, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
glog.Infof("Started pod %s in namespace %s", podDescr.Name, ns)
|
glog.Infof("Started pod %s in namespace %s", podDescr.Name, ns)
|
||||||
|
@ -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.
|
// 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 {
|
func waitForPodNotPending(c *client.Client, ns, podName 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(ns).Get(podName)
|
pod, err := c.Pods(ns).Get(podName)
|
||||||
if err != nil {
|
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
|
continue
|
||||||
}
|
}
|
||||||
if pod.Status.Phase != api.PodPending {
|
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)
|
By(fmt.Sprintf("Saw pod %s in namespace %s out of pending state (found %q)", podName, ns, pod.Status.Phase))
|
||||||
return true
|
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 fmt.Errorf("Gave up waiting for status of pod %s in namespace %s to go out of pending after %d seconds", podName, ns, trySecs)
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
|
Loading…
Reference in New Issue
Block a user