Add container lifecycle hook test.

This commit is contained in:
Random-Liu
2016-09-23 13:36:37 -07:00
parent 72524e45b5
commit 5eb41e9acb
4 changed files with 201 additions and 2 deletions

View File

@@ -149,3 +149,19 @@ func (c *PodClient) mungeSpec(pod *api.Pod) {
}
// TODO(random-liu): Move pod wait function into this file
// WaitForSuccess waits for pod to success.
func (c *PodClient) WaitForSuccess(name string, timeout time.Duration) {
f := c.f
Expect(waitForPodCondition(f.Client, f.Namespace.Name, name, "success or failure", timeout,
func(pod *api.Pod) (bool, error) {
switch pod.Status.Phase {
case api.PodFailed:
return true, fmt.Errorf("pod %q failed with reason: %q, message: %q", name, pod.Status.Reason, pod.Status.Message)
case api.PodSucceeded:
return true, nil
default:
return false, nil
}
},
)).To(Succeed(), "wait for pod %q to success", name)
}

View File

@@ -1456,6 +1456,7 @@ func waitForPodTerminatedInNamespace(c *client.Client, podName, reason, namespac
func waitForPodSuccessInNamespaceTimeout(c *client.Client, podName string, contName string, namespace string, timeout time.Duration) error {
return waitForPodCondition(c, namespace, podName, "success or failure", timeout, func(pod *api.Pod) (bool, error) {
// Cannot use pod.Status.Phase == api.PodSucceeded/api.PodFailed due to #2632
// TODO: This was not true from long time ago. We can use api.PodSucceeded now.
ci, ok := api.GetContainerStatus(pod.Status.ContainerStatuses, contName)
if !ok {
Logf("No Status.Info for container '%s' in pod '%s' yet", contName, podName)