From 0db4b8e2adaa3e492c53c1e07f1a06fba98258e9 Mon Sep 17 00:00:00 2001 From: saadali Date: Thu, 18 Dec 2014 18:15:47 -0800 Subject: [PATCH] Fix Issue #3002: kubectl get pods/log podname don't work well together --- pkg/kubectl/resource_printer.go | 54 ++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/pkg/kubectl/resource_printer.go b/pkg/kubectl/resource_printer.go index dbe53cbc8e..0f8aa3ba88 100644 --- a/pkg/kubectl/resource_printer.go +++ b/pkg/kubectl/resource_printer.go @@ -188,8 +188,8 @@ func (h *HumanReadablePrinter) validatePrintHandlerFunc(printFunc reflect.Value) return nil } -var podColumns = []string{"NAME", "IMAGE(S)", "HOST", "LABELS", "STATUS"} -var replicationControllerColumns = []string{"NAME", "IMAGE(S)", "SELECTOR", "REPLICAS"} +var podColumns = []string{"POD", "CONTAINER(S)", "IMAGE(S)", "HOST", "LABELS", "STATUS"} +var replicationControllerColumns = []string{"CONTROLLER", "CONTAINER(S)", "IMAGE(S)", "SELECTOR", "REPLICAS"} var serviceColumns = []string{"NAME", "LABELS", "SELECTOR", "IP", "PORT"} var minionColumns = []string{"NAME", "LABELS"} var statusColumns = []string{"STATUS"} @@ -235,22 +235,24 @@ func printPod(pod *api.Pod, w io.Writer) error { if err := api.Scheme.Convert(&pod.Spec, spec); err != nil { glog.Errorf("Unable to convert pod manifest: %v", err) } - il := listOfImages(spec) - // Be paranoid about the case where there is no image. - var firstImage string - if len(il) > 0 { - firstImage, il = il[0], il[1:] + containers := spec.Containers + var firstContainer api.Container + if len(containers) > 0 { + firstContainer, containers = containers[0], containers[1:] } - _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", - pod.Name, firstImage, + _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\n", + pod.Name, + firstContainer.Name, + firstContainer.Image, podHostString(pod.Status.Host, pod.Status.HostIP), - formatLabels(pod.Labels), pod.Status.Phase) + formatLabels(pod.Labels), + pod.Status.Phase) if err != nil { return err } - // Lay out all the other images on separate lines. - for _, image := range il { - _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", "", image, "", "", "") + // Lay out all the other containers on separate lines. + for _, container := range containers { + _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\n", "", container.Name, container.Image, "", "", "") if err != nil { return err } @@ -268,10 +270,28 @@ func printPodList(podList *api.PodList, w io.Writer) error { } func printReplicationController(controller *api.ReplicationController, w io.Writer) error { - _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%d\n", - controller.Name, makeImageList(&controller.Spec.Template.Spec), - formatLabels(controller.Spec.Selector), controller.Spec.Replicas) - return err + containers := controller.Spec.Template.Spec.Containers + var firstContainer api.Container + if len(containers) > 0 { + firstContainer, containers = containers[0], containers[1:] + } + _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\n", + controller.Name, + firstContainer.Name, + firstContainer.Image, + formatLabels(controller.Spec.Selector), + controller.Spec.Replicas) + if err != nil { + return err + } + // Lay out all the other containers on separate lines. + for _, container := range containers { + _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", "", container.Name, container.Image, "", "") + if err != nil { + return err + } + } + return nil } func printReplicationControllerList(list *api.ReplicationControllerList, w io.Writer) error {