From a769e22b7016d3de993b1521f7e0183fc0071c25 Mon Sep 17 00:00:00 2001 From: Dong Chen Date: Wed, 13 Jul 2016 16:19:31 -0700 Subject: [PATCH] Fix service inspect --pretty. Signed-off-by: Dong Chen (cherry picked from commit 08ae4e544d5744e975da0f89c4f04baa2b8474f2) Signed-off-by: Tibor Vass --- api/client/service/inspect.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/api/client/service/inspect.go b/api/client/service/inspect.go index 913483b92d..dc23ae617e 100644 --- a/api/client/service/inspect.go +++ b/api/client/service/inspect.go @@ -102,7 +102,6 @@ func printService(out io.Writer, service swarm.Service) { } } fmt.Fprintln(out, "Placement:") - fmt.Fprintln(out, " Strategy:\tSpread") if service.Spec.TaskTemplate.Placement != nil && len(service.Spec.TaskTemplate.Placement.Constraints) > 0 { ioutils.FprintfIfNotEmpty(out, " Constraints\t: %s\n", strings.Join(service.Spec.TaskTemplate.Placement.Constraints, ", ")) } @@ -114,24 +113,23 @@ func printService(out io.Writer, service swarm.Service) { fmt.Fprintf(out, "ContainerSpec:\n") printContainerSpec(out, service.Spec.TaskTemplate.ContainerSpec) - if service.Spec.TaskTemplate.Resources != nil { + resources := service.Spec.TaskTemplate.Resources + if resources != nil { fmt.Fprintln(out, "Resources:") - printResources := func(out io.Writer, r *swarm.Resources) { + printResources := func(out io.Writer, requirement string, r *swarm.Resources) { + if r == nil || (r.MemoryBytes == 0 && r.NanoCPUs == 0) { + return + } + fmt.Fprintf(out, " %s:\n", requirement) if r.NanoCPUs != 0 { - fmt.Fprintf(out, " CPU:\t\t%g\n", float64(r.NanoCPUs)/1e9) + fmt.Fprintf(out, " CPU:\t\t%g\n", float64(r.NanoCPUs)/1e9) } if r.MemoryBytes != 0 { - fmt.Fprintf(out, " Memory:\t\t%s\n", units.BytesSize(float64(r.MemoryBytes))) + fmt.Fprintf(out, " Memory:\t%s\n", units.BytesSize(float64(r.MemoryBytes))) } } - if service.Spec.TaskTemplate.Resources.Reservations != nil { - fmt.Fprintln(out, "Reservations:") - printResources(out, service.Spec.TaskTemplate.Resources.Reservations) - } - if service.Spec.TaskTemplate.Resources.Limits != nil { - fmt.Fprintln(out, "Limits:") - printResources(out, service.Spec.TaskTemplate.Resources.Limits) - } + printResources(out, "Reservations", resources.Reservations) + printResources(out, "Limits", resources.Limits) } if len(service.Spec.Networks) > 0 { fmt.Fprintf(out, "Networks:")