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.
This commit is contained in:
Jan Safranek 2017-03-10 10:08:57 +01:00
parent 342ef1115c
commit bc06c636d1

View File

@ -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)