Add log-driver and options to service inspect "pretty" format

Signed-off-by: Rahul Zoldyck <rahulzoldyck@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Rahul Zoldyck 2019-06-16 12:57:27 +05:30 committed by Sebastiaan van Stijn
parent c6d10b6da0
commit 139af1f6d6
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 33 additions and 1 deletions

View File

@ -123,6 +123,17 @@ Secrets:
Target: {{$secret.File.Name}}
Source: {{$secret.SecretName}}
{{- end }}{{ end }}
{{- if .HasLogDriver }}
Log Driver:
{{- if .HasLogDriverName }}
Name: {{ .LogDriverName }}
{{- end }}
{{- if .LogOpts }}
LogOpts:
{{- range $k, $v := .LogOpts }}
{{ $k }}{{if $v }}: {{ $v }}{{ end }}
{{- end }}{{ end }}
{{ end }}
{{- if .HasResources }}
Resources:
{{- if .HasResourceReservations }}
@ -238,6 +249,21 @@ func (ctx *serviceInspectContext) Labels() map[string]string {
return ctx.Service.Spec.Labels
}
func (ctx *serviceInspectContext) HasLogDriver() bool {
return ctx.Service.Spec.TaskTemplate.LogDriver != nil
}
func (ctx *serviceInspectContext) HasLogDriverName() bool {
return ctx.Service.Spec.TaskTemplate.LogDriver.Name != ""
}
func (ctx *serviceInspectContext) LogDriverName() string {
return ctx.Service.Spec.TaskTemplate.LogDriver.Name
}
func (ctx *serviceInspectContext) LogOpts() map[string]string {
return ctx.Service.Spec.TaskTemplate.LogDriver.Options
}
func (ctx *serviceInspectContext) Configs() []*swarm.ConfigReference {
return ctx.Service.Spec.TaskTemplate.ContainerSpec.Configs
}

View File

@ -43,6 +43,12 @@ func formatServiceInspect(t *testing.T, format formatter.Format, now time.Time)
Labels: map[string]string{"com.label": "foo"},
},
TaskTemplate: swarm.TaskSpec{
LogDriver: &swarm.Driver{
Name: "driver",
Options: map[string]string{
"max-file": "5",
},
},
ContainerSpec: &swarm.ContainerSpec{
Image: "foo/bar@sha256:this_is_a_test",
Configs: []*swarm.ConfigReference{
@ -163,7 +169,7 @@ func TestJSONFormatWithNoUpdateConfig(t *testing.T) {
func TestPrettyPrintWithConfigsAndSecrets(t *testing.T) {
s := formatServiceInspect(t, NewFormat("pretty"), time.Now())
assert.Check(t, is.Contains(s, "Log Driver:"), "Pretty print missing Log Driver")
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")