Merge pull request #14607 from erictune/jobs-get-fix

kubectl get jobs printing fix
This commit is contained in:
Alex Robinson 2015-10-05 17:03:25 -07:00
commit cae6b7cf61

View File

@ -724,13 +724,20 @@ func printReplicationControllerList(list *api.ReplicationControllerList, w io.Wr
}
func printJob(job *experimental.Job, w io.Writer, withNamespace bool, wide bool, showAll bool, columnLabels []string) error {
name := job.Name
namespace := job.Namespace
containers := job.Spec.Template.Spec.Containers
var firstContainer api.Container
if len(containers) > 0 {
firstContainer = containers[0]
firstContainer, containers = containers[0], containers[1:]
}
if withNamespace {
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
return err
}
}
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\n",
job.Name,
name,
firstContainer.Name,
firstContainer.Image,
labels.FormatLabels(job.Spec.Selector),
@ -738,6 +745,24 @@ func printJob(job *experimental.Job, w io.Writer, withNamespace bool, wide bool,
if err != nil {
return err
}
if _, err := fmt.Fprint(w, appendLabels(job.Labels, columnLabels)); err != nil {
return err
}
// Lay out all the other containers on separate lines.
extraLinePrefix := "\t"
if withNamespace {
extraLinePrefix = "\t\t"
}
for _, container := range containers {
_, err := fmt.Fprintf(w, "%s%s\t%s\t%s\t%s", extraLinePrefix, container.Name, container.Image, "", "")
if err != nil {
return err
}
if _, err := fmt.Fprint(w, appendLabelTabs(columnLabels)); err != nil {
return err
}
}
return nil
}