[pretty print] pretty print and healthcheck

fixes #117

Print healthcheck information in pretty mode.

Signed-off-by: Stephane Jeandeaux <stephane.jeandeaux@gmail.com>
This commit is contained in:
Stephane Jeandeaux 2019-03-12 21:40:05 -04:00
parent 81ac432cc2
commit 05674a5096
2 changed files with 28 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/docker/cli/cli/command/inspect" "github.com/docker/cli/cli/command/inspect"
"github.com/docker/distribution/reference" "github.com/docker/distribution/reference"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
mounttypes "github.com/docker/docker/api/types/mount" mounttypes "github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
@ -146,6 +147,18 @@ Ports:
TargetPort = {{ $port.TargetPort }} TargetPort = {{ $port.TargetPort }}
PublishMode = {{ $port.PublishMode }} PublishMode = {{ $port.PublishMode }}
{{- end }} {{ end -}} {{- 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 // 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 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 { func (ctx *serviceInspectContext) IsModeGlobal() bool {
return ctx.Service.Spec.Mode.Global != nil return ctx.Service.Spec.Mode.Global != nil
} }

View File

@ -7,6 +7,8 @@ import (
"testing" "testing"
"time" "time"
"github.com/docker/docker/api/types/container"
"github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/formatter"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm" "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{ 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, "Configs:"), "Pretty print missing configs")
assert.Check(t, is.Contains(s, "Secrets:"), "Pretty print missing secrets") assert.Check(t, is.Contains(s, "Secrets:"), "Pretty print missing secrets")
assert.Check(t, is.Contains(s, "Healthcheck:"), "Pretty print missing healthcheck")
} }