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 395a6d560d
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 <albin@akerouanton.name>
This commit is contained in:
Albin Kerouanton 2020-07-28 22:11:13 +02:00
parent 12b74cb5a0
commit 21da11c5fd
No known key found for this signature in database
GPG Key ID: 630B8E1DCBDB1864
1 changed files with 3 additions and 0 deletions

View File

@ -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
}