Merge pull request #1006 from essamhassan/908_show_secrets_configs_srv_inspect

908 - Adding configs/secrets to service inspect pretty
This commit is contained in:
Vincent Demeester 2018-05-03 10:12:51 +02:00 committed by GitHub
commit e9731e9d0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 0 deletions

View File

@ -97,6 +97,18 @@ Mounts:
ReadOnly = {{ $mount.ReadOnly }}
Type = {{ $mount.Type }}
{{- end -}}
{{- if .Configs}}
Configs:
{{- range $config := .Configs }}
Target: {{$config.File.Name}}
Source: {{$config.ConfigName}}
{{- end }}{{ end }}
{{- if .Secrets }}
Secrets:
{{- range $secret := .Secrets }}
Target: {{$secret.File.Name}}
Source: {{$secret.SecretName}}
{{- end }}{{ end }}
{{- if .HasResources }}
Resources:
{{- if .HasResourceReservations }}
@ -200,6 +212,14 @@ func (ctx *serviceInspectContext) Labels() map[string]string {
return ctx.Service.Spec.Labels
}
func (ctx *serviceInspectContext) Configs() []*swarm.ConfigReference {
return ctx.Service.Spec.TaskTemplate.ContainerSpec.Configs
}
func (ctx *serviceInspectContext) Secrets() []*swarm.SecretReference {
return ctx.Service.Spec.TaskTemplate.ContainerSpec.Secrets
}
func (ctx *serviceInspectContext) IsModeGlobal() bool {
return ctx.Service.Spec.Mode.Global != nil
}

View File

@ -44,6 +44,24 @@ func formatServiceInspect(t *testing.T, format formatter.Format, now time.Time)
TaskTemplate: swarm.TaskSpec{
ContainerSpec: &swarm.ContainerSpec{
Image: "foo/bar@sha256:this_is_a_test",
Configs: []*swarm.ConfigReference{
{
ConfigID: "mtc3i44r1awdoziy2iceg73z8",
ConfigName: "configtest.conf",
File: &swarm.ConfigReferenceFileTarget{
Name: "/configtest.conf",
},
},
},
Secrets: []*swarm.SecretReference{
{
SecretID: "3hv39ehbbb4hdozo7spod9ftn",
SecretName: "secrettest.conf",
File: &swarm.SecretReferenceFileTarget{
Name: "/secrettest.conf",
},
},
},
},
Networks: []swarm.NetworkAttachmentConfig{
{
@ -133,3 +151,10 @@ func TestJSONFormatWithNoUpdateConfig(t *testing.T) {
}
assert.Check(t, is.DeepEqual(m1, m2))
}
func TestPrettyPrintWithConfigsAndSecrets(t *testing.T) {
s := formatServiceInspect(t, formatter.NewServiceFormat("pretty"), time.Now())
assert.Check(t, is.Contains(s, "Configs:"), "Pretty print missing configs")
assert.Check(t, is.Contains(s, "Secrets:"), "Pretty print missing secrets")
}