Make the output kubectl.sh narrower

pull/6/head
Satnam Singh 2014-11-14 16:20:43 -08:00
parent 4681918888
commit fa0cb9a25e
2 changed files with 24 additions and 5 deletions

View File

@ -127,12 +127,16 @@ func formatLabels(labelMap map[string]string) string {
return l return l
} }
func makeImageList(spec *api.PodSpec) string { func listOfImages(spec *api.PodSpec) []string {
var images []string var images []string
for _, container := range spec.Containers { for _, container := range spec.Containers {
images = append(images, container.Image) images = append(images, container.Image)
} }
return strings.Join(images, ",") return images
}
func makeImageList(spec *api.PodSpec) string {
return strings.Join(listOfImages(spec), ",")
} }
// ExpandResourceShortcut will return the expanded version of resource // ExpandResourceShortcut will return the expanded version of resource

View File

@ -260,12 +260,27 @@ func printPod(pod *api.Pod, w io.Writer) error {
if err := api.Scheme.Convert(&pod.DesiredState.Manifest, spec); err != nil { if err := api.Scheme.Convert(&pod.DesiredState.Manifest, spec); err != nil {
glog.Errorf("Unable to convert pod manifest: %v", err) 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:]
}
_, 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\n",
pod.Name, makeImageList(spec), pod.Name, firstImage,
podHostString(pod.CurrentState.Host, pod.CurrentState.HostIP), podHostString(pod.CurrentState.Host, pod.CurrentState.HostIP),
labels.Set(pod.Labels), pod.CurrentState.Status) labels.Set(pod.Labels), pod.CurrentState.Status)
return err 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, "", "", "")
if err != nil {
return err
}
}
return nil
} }
func printPodList(podList *api.PodList, w io.Writer) error { func printPodList(podList *api.PodList, w io.Writer) error {