Skip to content

Commit e1f0526

Browse files
authored
Merge pull request kubernetes#77742 from deads2k/test-debug
improve e2e namespace dumping on failure
2 parents e72d73b + d503cba commit e1f0526

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

test/e2e/framework/util.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,23 @@ func logPodStates(pods []v1.Pod) {
538538
Logf("") // Final empty line helps for readability.
539539
}
540540

541+
// logPodTerminationMessages logs termination messages for failing pods. It's a short snippet (much smaller than full logs), but it often shows
542+
// why pods crashed and since it is in the API, it's fast to retrieve.
543+
func logPodTerminationMessages(pods []v1.Pod) {
544+
for _, pod := range pods {
545+
for _, status := range pod.Status.InitContainerStatuses {
546+
if status.LastTerminationState.Terminated != nil && len(status.LastTerminationState.Terminated.Message) > 0 {
547+
Logf("%s[%s].initContainer[%s]=%s", pod.Name, pod.Namespace, status.Name, status.LastTerminationState.Terminated.Message)
548+
}
549+
}
550+
for _, status := range pod.Status.ContainerStatuses {
551+
if status.LastTerminationState.Terminated != nil && len(status.LastTerminationState.Terminated.Message) > 0 {
552+
Logf("%s[%s].container[%s]=%s", pod.Name, pod.Namespace, status.Name, status.LastTerminationState.Terminated.Message)
553+
}
554+
}
555+
}
556+
}
557+
541558
// errorBadPodsStates create error message of basic info of bad pods for debugging.
542559
func errorBadPodsStates(badPods []v1.Pod, desiredPods int, ns, desiredState string, timeout time.Duration) string {
543560
errStr := fmt.Sprintf("%d / %d pods in namespace %q are NOT in %s state in %v\n", len(badPods), desiredPods, ns, desiredState, timeout)
@@ -2422,14 +2439,15 @@ func DumpAllNamespaceInfo(c clientset.Interface, namespace string) {
24222439
return c.CoreV1().Events(ns).List(opts)
24232440
}, namespace)
24242441

2442+
dumpAllPodInfoForNamespace(c, namespace)
2443+
24252444
// If cluster is large, then the following logs are basically useless, because:
24262445
// 1. it takes tens of minutes or hours to grab all of them
24272446
// 2. there are so many of them that working with them are mostly impossible
24282447
// So we dump them only if the cluster is relatively small.
24292448
maxNodesForDump := TestContext.MaxNodesToGather
24302449
if nodes, err := c.CoreV1().Nodes().List(metav1.ListOptions{}); err == nil {
24312450
if len(nodes.Items) <= maxNodesForDump {
2432-
dumpAllPodInfo(c)
24332451
dumpAllNodeInfo(c)
24342452
} else {
24352453
Logf("skipping dumping cluster info - cluster too large")
@@ -2452,12 +2470,13 @@ func (o byFirstTimestamp) Less(i, j int) bool {
24522470
return o[i].FirstTimestamp.Before(&o[j].FirstTimestamp)
24532471
}
24542472

2455-
func dumpAllPodInfo(c clientset.Interface) {
2456-
pods, err := c.CoreV1().Pods("").List(metav1.ListOptions{})
2473+
func dumpAllPodInfoForNamespace(c clientset.Interface, namespace string) {
2474+
pods, err := c.CoreV1().Pods(namespace).List(metav1.ListOptions{})
24572475
if err != nil {
24582476
Logf("unable to fetch pod debug info: %v", err)
24592477
}
24602478
logPodStates(pods.Items)
2479+
logPodTerminationMessages(pods.Items)
24612480
}
24622481

24632482
func dumpAllNodeInfo(c clientset.Interface) {

0 commit comments

Comments
 (0)