Fix Issue #3002: kubectl get pods/log podname don't work well together

pull/6/head
saadali 2014-12-18 18:15:47 -08:00
parent c34f2d354c
commit 0db4b8e2ad
1 changed files with 37 additions and 17 deletions

View File

@ -188,8 +188,8 @@ func (h *HumanReadablePrinter) validatePrintHandlerFunc(printFunc reflect.Value)
return nil return nil
} }
var podColumns = []string{"NAME", "IMAGE(S)", "HOST", "LABELS", "STATUS"} var podColumns = []string{"POD", "CONTAINER(S)", "IMAGE(S)", "HOST", "LABELS", "STATUS"}
var replicationControllerColumns = []string{"NAME", "IMAGE(S)", "SELECTOR", "REPLICAS"} var replicationControllerColumns = []string{"CONTROLLER", "CONTAINER(S)", "IMAGE(S)", "SELECTOR", "REPLICAS"}
var serviceColumns = []string{"NAME", "LABELS", "SELECTOR", "IP", "PORT"} var serviceColumns = []string{"NAME", "LABELS", "SELECTOR", "IP", "PORT"}
var minionColumns = []string{"NAME", "LABELS"} var minionColumns = []string{"NAME", "LABELS"}
var statusColumns = []string{"STATUS"} 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 { if err := api.Scheme.Convert(&pod.Spec, spec); err != nil {
glog.Errorf("Unable to convert pod manifest: %v", err) glog.Errorf("Unable to convert pod manifest: %v", err)
} }
il := listOfImages(spec) containers := spec.Containers
// Be paranoid about the case where there is no image. var firstContainer api.Container
var firstImage string if len(containers) > 0 {
if len(il) > 0 { firstContainer, containers = containers[0], containers[1:]
firstImage, il = il[0], il[1:]
} }
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\n",
pod.Name, firstImage, pod.Name,
firstContainer.Name,
firstContainer.Image,
podHostString(pod.Status.Host, pod.Status.HostIP), podHostString(pod.Status.Host, pod.Status.HostIP),
formatLabels(pod.Labels), pod.Status.Phase) formatLabels(pod.Labels),
pod.Status.Phase)
if err != nil { if err != nil {
return err return err
} }
// Lay out all the other images on separate lines. // Lay out all the other containers on separate lines.
for _, image := range il { for _, container := range containers {
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", "", image, "", "", "") _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\n", "", container.Name, container.Image, "", "", "")
if err != nil { if err != nil {
return err return err
} }
@ -268,10 +270,28 @@ func printPodList(podList *api.PodList, w io.Writer) error {
} }
func printReplicationController(controller *api.ReplicationController, 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", containers := controller.Spec.Template.Spec.Containers
controller.Name, makeImageList(&controller.Spec.Template.Spec), var firstContainer api.Container
formatLabels(controller.Spec.Selector), controller.Spec.Replicas) 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 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 { func printReplicationControllerList(list *api.ReplicationControllerList, w io.Writer) error {