From 21da11c5fd1a927c2d4faa655e76edb05b6817e4 Mon Sep 17 00:00:00 2001 From: Albin Kerouanton Date: Tue, 28 Jul 2020 22:11:13 +0200 Subject: [PATCH] docker service inspect fails when TaskTemplate.Resources is nil When doing `docker service inspect --pretty` on services without `TaskTemplate.Resources` or `TaskTemplate.Resources.Limits`, the command fails. This is due to a missing check on ResourceLimitPids(). This bug has been introduced by 395a6d560decb1da85ec66b0913a555ceace738d and produces following error message: ``` Template parsing error: template: :139:10: executing "" at <.ResourceLimitPids>: error calling ResourceLimitPids: runtime error: invalid memory address or nil pointer dereference ``` Signed-off-by: Albin Kerouanton --- cli/command/service/formatter.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cli/command/service/formatter.go b/cli/command/service/formatter.go index f4d815a554..26bdd2994d 100644 --- a/cli/command/service/formatter.go +++ b/cli/command/service/formatter.go @@ -502,6 +502,9 @@ func (ctx *serviceInspectContext) ResourceLimitMemory() string { } func (ctx *serviceInspectContext) ResourceLimitPids() int64 { + if ctx.Service.Spec.TaskTemplate.Resources == nil || ctx.Service.Spec.TaskTemplate.Resources.Limits == nil { + return 0 + } return ctx.Service.Spec.TaskTemplate.Resources.Limits.Pids }