Fix the wait for pod success in test framework.

pull/6/head
Random-Liu 2016-10-12 11:33:40 -07:00
parent 7d8c0fa0c9
commit bab971d002
8 changed files with 27 additions and 32 deletions

View File

@ -53,7 +53,7 @@ var _ = framework.KubeDescribe("Cluster level logging using Elasticsearch [Featu
By("Running synthetic logger") By("Running synthetic logger")
createSynthLogger(f, expectedLinesCount) createSynthLogger(f, expectedLinesCount)
defer f.PodClient().Delete(synthLoggerPodName, &api.DeleteOptions{}) defer f.PodClient().Delete(synthLoggerPodName, &api.DeleteOptions{})
err = framework.WaitForPodSuccessInNamespace(f.Client, synthLoggerPodName, synthLoggerPodName, f.Namespace.Name) err = framework.WaitForPodSuccessInNamespace(f.Client, synthLoggerPodName, f.Namespace.Name)
framework.ExpectNoError(err, fmt.Sprintf("Should've successfully waited for pod %s to succeed", synthLoggerPodName)) framework.ExpectNoError(err, fmt.Sprintf("Should've successfully waited for pod %s to succeed", synthLoggerPodName))
By("Waiting for logs to ingest") By("Waiting for logs to ingest")

View File

@ -43,7 +43,7 @@ var _ = framework.KubeDescribe("Cluster level logging using GCL", func() {
By("Running synthetic logger") By("Running synthetic logger")
createSynthLogger(f, expectedLinesCount) createSynthLogger(f, expectedLinesCount)
defer f.PodClient().Delete(synthLoggerPodName, &api.DeleteOptions{}) defer f.PodClient().Delete(synthLoggerPodName, &api.DeleteOptions{})
err := framework.WaitForPodSuccessInNamespace(f.Client, synthLoggerPodName, synthLoggerPodName, f.Namespace.Name) err := framework.WaitForPodSuccessInNamespace(f.Client, synthLoggerPodName, f.Namespace.Name)
framework.ExpectNoError(err, fmt.Sprintf("Should've successfully waited for pod %s to succeed", synthLoggerPodName)) framework.ExpectNoError(err, fmt.Sprintf("Should've successfully waited for pod %s to succeed", synthLoggerPodName))
By("Waiting for logs to ingest") By("Waiting for logs to ingest")

View File

@ -45,6 +45,7 @@ func createSynthLogger(f *framework.Framework, linesCount int) {
Namespace: f.Namespace.Name, Namespace: f.Namespace.Name,
}, },
Spec: api.PodSpec{ Spec: api.PodSpec{
RestartPolicy: api.RestartPolicyOnFailure,
Containers: []api.Container{ Containers: []api.Container{
{ {
Name: synthLoggerPodName, Name: synthLoggerPodName,

View File

@ -1465,35 +1465,31 @@ func waitForPodTerminatedInNamespace(c *client.Client, podName, reason, namespac
} }
// waitForPodSuccessInNamespaceTimeout returns nil if the pod reached state success, or an error if it reached failure or ran too long. // waitForPodSuccessInNamespaceTimeout returns nil if the pod reached state success, or an error if it reached failure or ran too long.
func waitForPodSuccessInNamespaceTimeout(c *client.Client, podName string, contName string, namespace string, timeout time.Duration) error { func waitForPodSuccessInNamespaceTimeout(c *client.Client, podName string, namespace string, timeout time.Duration) error {
return waitForPodCondition(c, namespace, podName, "success or failure", timeout, func(pod *api.Pod) (bool, 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 if pod.Spec.RestartPolicy == api.RestartPolicyAlways {
// TODO: This was not true from long time ago. We can use api.PodSucceeded now. return false, fmt.Errorf("pod %q will never terminate with a succeeded state since its restart policy is Always", podName)
ci, ok := api.GetContainerStatus(pod.Status.ContainerStatuses, contName) }
if !ok { switch pod.Status.Phase {
Logf("No Status.Info for container '%s' in pod '%s' yet", contName, podName) case api.PodSucceeded:
} else { By("Saw pod success")
if ci.State.Terminated != nil { return true, nil
if ci.State.Terminated.ExitCode == 0 { case api.PodFailed:
By("Saw pod success") return true, fmt.Errorf("pod %q failed with status: %+v", podName, pod.Status)
return true, nil default:
} return false, nil
return true, fmt.Errorf("pod '%s' terminated with failure: %+v", podName, ci.State.Terminated)
}
Logf("Nil State.Terminated for container '%s' in pod '%s' in namespace '%s' so far", contName, podName, namespace)
} }
return false, nil
}) })
} }
// WaitForPodSuccessInNamespace returns nil if the pod reached state success, or an error if it reached failure or until podStartupTimeout. // WaitForPodSuccessInNamespace returns nil if the pod reached state success, or an error if it reached failure or until podStartupTimeout.
func WaitForPodSuccessInNamespace(c *client.Client, podName string, contName string, namespace string) error { func WaitForPodSuccessInNamespace(c *client.Client, podName string, namespace string) error {
return waitForPodSuccessInNamespaceTimeout(c, podName, contName, namespace, PodStartTimeout) return waitForPodSuccessInNamespaceTimeout(c, podName, namespace, PodStartTimeout)
} }
// WaitForPodSuccessInNamespaceSlow returns nil if the pod reached state success, or an error if it reached failure or until slowPodStartupTimeout. // WaitForPodSuccessInNamespaceSlow returns nil if the pod reached state success, or an error if it reached failure or until slowPodStartupTimeout.
func WaitForPodSuccessInNamespaceSlow(c *client.Client, podName string, contName string, namespace string) error { func WaitForPodSuccessInNamespaceSlow(c *client.Client, podName string, namespace string) error {
return waitForPodSuccessInNamespaceTimeout(c, podName, contName, namespace, slowPodStartTimeout) return waitForPodSuccessInNamespaceTimeout(c, podName, namespace, slowPodStartTimeout)
} }
// waitForRCPodOnNode returns the pod from the given replication controller (described by rcName) which is scheduled on the given node. // waitForRCPodOnNode returns the pod from the given replication controller (described by rcName) which is scheduled on the given node.
@ -2307,11 +2303,9 @@ func (f *Framework) MatchContainerOutput(
defer podClient.Delete(pod.Name, api.NewDeleteOptions(0)) defer podClient.Delete(pod.Name, api.NewDeleteOptions(0))
podClient.Create(pod) podClient.Create(pod)
// Wait for client pod to complete. All containers should succeed. // Wait for client pod to complete.
for _, container := range pod.Spec.Containers { if err := WaitForPodSuccessInNamespace(f.Client, pod.Name, ns); err != nil {
if err := WaitForPodSuccessInNamespace(f.Client, pod.Name, container.Name, ns); err != nil { return fmt.Errorf("expected pod %q success: %v", pod.Name, err)
return fmt.Errorf("expected container %s success: %v", container.Name, err)
}
} }
// Grab its logs. Get host first. // Grab its logs. Get host first.
@ -4986,7 +4980,7 @@ func CheckConnectivityToHost(f *Framework, nodeName, podName, host string, timeo
return err return err
} }
defer podClient.Delete(podName, nil) defer podClient.Delete(podName, nil)
err = WaitForPodSuccessInNamespace(f.Client, podName, contName, f.Namespace.Name) err = WaitForPodSuccessInNamespace(f.Client, podName, f.Namespace.Name)
if err != nil { if err != nil {
logs, logErr := GetPodLogs(f.Client, f.Namespace.Name, pod.Name, contName) logs, logErr := GetPodLogs(f.Client, f.Namespace.Name, pod.Name, contName)

View File

@ -277,7 +277,7 @@ func testPodSuccessOrFail(f *framework.Framework, c *client.Client, ns string, p
By("Pod should terminate with exitcode 0 (success)") By("Pod should terminate with exitcode 0 (success)")
err := framework.WaitForPodSuccessInNamespace(c, pod.Name, pod.Spec.Containers[0].Name, ns) err := framework.WaitForPodSuccessInNamespace(c, pod.Name, ns)
if err != nil { if err != nil {
return fmt.Errorf("Pod %v returned non-zero exitcode: %+v", pod.Name, err) return fmt.Errorf("Pod %v returned non-zero exitcode: %+v", pod.Name, err)
} }

View File

@ -228,7 +228,7 @@ func runInPodWithVolume(c *client.Client, ns, claimName, command string) {
framework.ExpectNoError(c.Pods(ns).Delete(pod.Name, nil)) framework.ExpectNoError(c.Pods(ns).Delete(pod.Name, nil))
}() }()
framework.ExpectNoError(err, "Failed to create pod: %v", err) framework.ExpectNoError(err, "Failed to create pod: %v", err)
framework.ExpectNoError(framework.WaitForPodSuccessInNamespaceSlow(c, pod.Name, pod.Spec.Containers[0].Name, pod.Namespace)) framework.ExpectNoError(framework.WaitForPodSuccessInNamespaceSlow(c, pod.Name, pod.Namespace))
} }
func newStorageClass() *storage.StorageClass { func newStorageClass() *storage.StorageClass {

View File

@ -319,7 +319,7 @@ func injectHtml(client *client.Client, config VolumeTestConfig, volume api.Volum
injectPod, err := podClient.Create(injectPod) injectPod, err := podClient.Create(injectPod)
framework.ExpectNoError(err, "Failed to create injector pod: %v", err) framework.ExpectNoError(err, "Failed to create injector pod: %v", err)
err = framework.WaitForPodSuccessInNamespace(client, injectPod.Name, injectPod.Spec.Containers[0].Name, injectPod.Namespace) err = framework.WaitForPodSuccessInNamespace(client, injectPod.Name, injectPod.Namespace)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
} }

View File

@ -68,7 +68,7 @@ var _ = framework.KubeDescribe("Kubelet Cgroup Manager [Skip]", func() {
} }
podClient := f.PodClient() podClient := f.PodClient()
podClient.Create(pod) podClient.Create(pod)
err := framework.WaitForPodSuccessInNamespace(f.Client, podName, contName, f.Namespace.Name) err := framework.WaitForPodSuccessInNamespace(f.Client, podName, f.Namespace.Name)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
}) })