Fix service inspect --pretty
| ... | ... |
@@ -102,7 +102,6 @@ func printService(out io.Writer, service swarm.Service) {
|
| 102 | 102 |
} |
| 103 | 103 |
} |
| 104 | 104 |
fmt.Fprintln(out, "Placement:") |
| 105 |
- fmt.Fprintln(out, " Strategy:\tSpread") |
|
| 106 | 105 |
if service.Spec.TaskTemplate.Placement != nil && len(service.Spec.TaskTemplate.Placement.Constraints) > 0 {
|
| 107 | 106 |
ioutils.FprintfIfNotEmpty(out, " Constraints\t: %s\n", strings.Join(service.Spec.TaskTemplate.Placement.Constraints, ", ")) |
| 108 | 107 |
} |
| ... | ... |
@@ -114,24 +113,23 @@ func printService(out io.Writer, service swarm.Service) {
|
| 114 | 114 |
fmt.Fprintf(out, "ContainerSpec:\n") |
| 115 | 115 |
printContainerSpec(out, service.Spec.TaskTemplate.ContainerSpec) |
| 116 | 116 |
|
| 117 |
- if service.Spec.TaskTemplate.Resources != nil {
|
|
| 117 |
+ resources := service.Spec.TaskTemplate.Resources |
|
| 118 |
+ if resources != nil {
|
|
| 118 | 119 |
fmt.Fprintln(out, "Resources:") |
| 119 |
- printResources := func(out io.Writer, r *swarm.Resources) {
|
|
| 120 |
+ printResources := func(out io.Writer, requirement string, r *swarm.Resources) {
|
|
| 121 |
+ if r == nil || (r.MemoryBytes == 0 && r.NanoCPUs == 0) {
|
|
| 122 |
+ return |
|
| 123 |
+ } |
|
| 124 |
+ fmt.Fprintf(out, " %s:\n", requirement) |
|
| 120 | 125 |
if r.NanoCPUs != 0 {
|
| 121 |
- fmt.Fprintf(out, " CPU:\t\t%g\n", float64(r.NanoCPUs)/1e9) |
|
| 126 |
+ fmt.Fprintf(out, " CPU:\t\t%g\n", float64(r.NanoCPUs)/1e9) |
|
| 122 | 127 |
} |
| 123 | 128 |
if r.MemoryBytes != 0 {
|
| 124 |
- fmt.Fprintf(out, " Memory:\t\t%s\n", units.BytesSize(float64(r.MemoryBytes))) |
|
| 129 |
+ fmt.Fprintf(out, " Memory:\t%s\n", units.BytesSize(float64(r.MemoryBytes))) |
|
| 125 | 130 |
} |
| 126 | 131 |
} |
| 127 |
- if service.Spec.TaskTemplate.Resources.Reservations != nil {
|
|
| 128 |
- fmt.Fprintln(out, "Reservations:") |
|
| 129 |
- printResources(out, service.Spec.TaskTemplate.Resources.Reservations) |
|
| 130 |
- } |
|
| 131 |
- if service.Spec.TaskTemplate.Resources.Limits != nil {
|
|
| 132 |
- fmt.Fprintln(out, "Limits:") |
|
| 133 |
- printResources(out, service.Spec.TaskTemplate.Resources.Limits) |
|
| 134 |
- } |
|
| 132 |
+ printResources(out, "Reservations", resources.Reservations) |
|
| 133 |
+ printResources(out, "Limits", resources.Limits) |
|
| 135 | 134 |
} |
| 136 | 135 |
if len(service.Spec.Networks) > 0 {
|
| 137 | 136 |
fmt.Fprintf(out, "Networks:") |