From 05674a50961d99eaf5320f32beb91646fd1355b4 Mon Sep 17 00:00:00 2001 From: Stephane Jeandeaux Date: Tue, 12 Mar 2019 21:40:05 -0400 Subject: [PATCH] [pretty print] pretty print and healthcheck fixes #117 Print healthcheck information in pretty mode. Signed-off-by: Stephane Jeandeaux --- cli/command/service/formatter.go | 17 +++++++++++++++++ cli/command/service/inspect_test.go | 11 +++++++++++ 2 files changed, 28 insertions(+) diff --git a/cli/command/service/formatter.go b/cli/command/service/formatter.go index 972129a7a3..d814ddbd13 100644 --- a/cli/command/service/formatter.go +++ b/cli/command/service/formatter.go @@ -10,6 +10,7 @@ import ( "github.com/docker/cli/cli/command/inspect" "github.com/docker/distribution/reference" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" mounttypes "github.com/docker/docker/api/types/mount" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/pkg/stringid" @@ -146,6 +147,18 @@ Ports: TargetPort = {{ $port.TargetPort }} PublishMode = {{ $port.PublishMode }} {{- end }} {{ end -}} +{{- if .Healthcheck }} + Healthcheck: + Interval = {{ .Healthcheck.Interval }} + Retries = {{ .Healthcheck.Retries }} + StartPeriod = {{ .Healthcheck.StartPeriod }} + Timeout = {{ .Healthcheck.Timeout }} + {{- if .Healthcheck.Test }} + Tests: + {{- range $test := .Healthcheck.Test }} + Test = {{ $test }} + {{- end }} {{ end -}} +{{- end }} ` // NewFormat returns a Format for rendering using a Context @@ -227,6 +240,10 @@ func (ctx *serviceInspectContext) Secrets() []*swarm.SecretReference { return ctx.Service.Spec.TaskTemplate.ContainerSpec.Secrets } +func (ctx *serviceInspectContext) Healthcheck() *container.HealthConfig { + return ctx.Service.Spec.TaskTemplate.ContainerSpec.Healthcheck +} + func (ctx *serviceInspectContext) IsModeGlobal() bool { return ctx.Service.Spec.Mode.Global != nil } diff --git a/cli/command/service/inspect_test.go b/cli/command/service/inspect_test.go index 4559353e41..4c72fa93a1 100644 --- a/cli/command/service/inspect_test.go +++ b/cli/command/service/inspect_test.go @@ -7,6 +7,8 @@ import ( "testing" "time" + "github.com/docker/docker/api/types/container" + "github.com/docker/cli/cli/command/formatter" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" @@ -62,6 +64,14 @@ func formatServiceInspect(t *testing.T, format formatter.Format, now time.Time) }, }, }, + + Healthcheck: &container.HealthConfig{ + Test: []string{"CMD-SHELL", "curl"}, + Interval: 4, + Retries: 3, + StartPeriod: 2, + Timeout: 1, + }, }, Networks: []swarm.NetworkAttachmentConfig{ { @@ -157,4 +167,5 @@ func TestPrettyPrintWithConfigsAndSecrets(t *testing.T) { assert.Check(t, is.Contains(s, "Configs:"), "Pretty print missing configs") assert.Check(t, is.Contains(s, "Secrets:"), "Pretty print missing secrets") + assert.Check(t, is.Contains(s, "Healthcheck:"), "Pretty print missing healthcheck") }