From bc06c636d11f26f13312cf93979d95f254e27486 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Fri, 10 Mar 2017 10:08:57 +0100 Subject: [PATCH] e2e test: Log container output on TestContainerOutput error When a pod started with TestContainerOutput or TestContainerOutputRegexp fails from unknown reason, we should log all output of all its containers so we can analyze what went wrong. --- test/e2e/framework/util.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index 2416a94b47d..385d8e0eaa1 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -2218,9 +2218,7 @@ func (f *Framework) MatchContainerOutput( }() // Wait for client pod to complete. - if err := WaitForPodSuccessInNamespace(f.ClientSet, createdPod.Name, ns); err != nil { - return fmt.Errorf("expected pod %q success: %v", pod.Name, err) - } + podErr := WaitForPodSuccessInNamespace(f.ClientSet, createdPod.Name, ns) // Grab its logs. Get host first. podStatus, err := podClient.Get(createdPod.Name, metav1.GetOptions{}) @@ -2228,6 +2226,20 @@ func (f *Framework) MatchContainerOutput( return fmt.Errorf("failed to get pod status: %v", err) } + if podErr != nil { + // Pod failed. Dump all logs from all containers to see what's wrong + for _, container := range podStatus.Spec.Containers { + logs, err := GetPodLogs(f.ClientSet, ns, podStatus.Name, container.Name) + if err != nil { + Logf("Failed to get logs from node %q pod %q container %q: %v", + podStatus.Spec.NodeName, podStatus.Name, container.Name, err) + continue + } + Logf("Output of node %q pod %q container %q: %s", podStatus.Spec.NodeName, podStatus.Name, container.Name, logs) + } + return fmt.Errorf("expected pod %q success: %v", pod.Name, err) + } + Logf("Trying to get logs from node %s pod %s container %s: %v", podStatus.Spec.NodeName, podStatus.Name, containerName, err)