Merge pull request #42879 from jsafrane/test-pod-logs

Automatic merge from submit-queue

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 would help us to see what wrong in https://github.com/kubernetes/kubernetes/issues/40811 - a container is running there for 3 minutes and dies and we want to see what it did for these 3 minutes.

```release-note
NONE
```
pull/6/head
Kubernetes Submit Queue 2017-03-10 06:13:44 -08:00 committed by GitHub
commit 4ff0af821a
1 changed files with 15 additions and 3 deletions

View File

@ -2215,9 +2215,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{})
@ -2225,6 +2223,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)