From a08ad428488ec326b7a5e0e0e58e73a030ad1028 Mon Sep 17 00:00:00 2001 From: Xing Zhou Date: Wed, 5 Apr 2017 16:37:35 +0800 Subject: [PATCH] Fixed `kubectl cluster-info dump` to support multi-container pod. Fixed `kubectl cluster-info dump` to support multi-container pod. --- pkg/kubectl/cmd/clusterinfo_dump.go | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/pkg/kubectl/cmd/clusterinfo_dump.go b/pkg/kubectl/cmd/clusterinfo_dump.go index 4e8dc765f14..381d3dd59eb 100644 --- a/pkg/kubectl/cmd/clusterinfo_dump.go +++ b/pkg/kubectl/cmd/clusterinfo_dump.go @@ -192,21 +192,34 @@ func dumpClusterInfo(f cmdutil.Factory, cmd *cobra.Command, args []string, out i return err } - for ix := range pods.Items { - pod := &pods.Items[ix] - writer := setupOutputWriter(cmd, out, path.Join(namespace, pod.Name, "logs.txt")) - writer.Write([]byte(fmt.Sprintf("==== START logs for %s/%s ====\n", pod.Namespace, pod.Name))) - request, err := f.LogsForObject(pod, &api.PodLogOptions{}, timeout) + printContainer := func(writer io.Writer, container api.Container, pod *api.Pod) { + writer.Write([]byte(fmt.Sprintf("==== START logs for container %s of pod %s/%s ====\n", container.Name, pod.Namespace, pod.Name))) + defer writer.Write([]byte(fmt.Sprintf("==== END logs for container %s of pod %s/%s ====\n", container.Name, pod.Namespace, pod.Name))) + + request, err := f.LogsForObject(pod, &api.PodLogOptions{Container: container.Name}, timeout) if err != nil { - return err + // Print error and return. + writer.Write([]byte(fmt.Sprintf("Create log request error: %s\n", err.Error()))) + return } data, err := request.DoRaw() if err != nil { - return err + // Print error and return. + writer.Write([]byte(fmt.Sprintf("Request log error: %s\n", err.Error()))) + return } writer.Write(data) - writer.Write([]byte(fmt.Sprintf("==== END logs for %s/%s ====\n", pod.Namespace, pod.Name))) + } + + for ix := range pods.Items { + pod := &pods.Items[ix] + containers := pod.Spec.Containers + writer := setupOutputWriter(cmd, out, path.Join(namespace, pod.Name, "logs.txt")) + + for i := range containers { + printContainer(writer, containers[i], pod) + } } } dir := cmdutil.GetFlagString(cmd, "output-directory")