Skip to content

Commit

Permalink
Docker-compose disable healthcheck properly handled
Browse files Browse the repository at this point in the history
Previously, if a container had healthchecks disabled in the
docker-compose.yml file and the user did a `podman inspect <container>`,
they would have an incorrect output:

```
"Healthcheck":{
   "Test":[
      "CMD-SHELL",
      "NONE"
   ],
   "Interval":30000000000,
   "Timeout":30000000000,
   "Retries":3
}
```

After a quick change, the correct output is now the result:
```
"Healthcheck":{
   "Test":[
      "NONE"
   ]
}
```

Closes: containers#14493

Signed-off-by: Jake Correnti <jcorrenti13@gmail.com>
  • Loading branch information
Jake Correnti committed Jun 16, 2022
1 parent b34cba6 commit c5750af
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/specgenutil/specgen.go
Expand Up @@ -873,9 +873,9 @@ func makeHealthCheckFromCli(inCmd, interval string, retries uint, timeout, start
}

var concat string
if cmdArr[0] == "CMD" || cmdArr[0] == "none" { // this is for compat, we are already split properly for most compat cases
if strings.ToUpper(cmdArr[0]) == "CMD" || strings.ToUpper(cmdArr[0]) == "NONE" { // this is for compat, we are already split properly for most compat cases
cmdArr = strings.Fields(inCmd)
} else if cmdArr[0] != "CMD-SHELL" { // this is for podman side of things, won't contain the keywords
} else if strings.ToUpper(cmdArr[0]) != "CMD-SHELL" { // this is for podman side of things, won't contain the keywords
if isArr && len(cmdArr) > 1 { // an array of consecutive commands
cmdArr = append([]string{"CMD"}, cmdArr...)
} else { // one singular command
Expand All @@ -888,7 +888,7 @@ func makeHealthCheckFromCli(inCmd, interval string, retries uint, timeout, start
}
}

if cmdArr[0] == "none" { // if specified to remove healtcheck
if strings.ToUpper(cmdArr[0]) == "NONE" { // if specified to remove healtcheck
cmdArr = []string{"NONE"}
}

Expand Down
10 changes: 10 additions & 0 deletions test/compose/disable_healthcheck/docker-compose.yml
@@ -0,0 +1,10 @@
version: "3.7"
services:
noHc:
image: alpine
container_name: noHc
ports:
- "4000:80"
restart: unless-stopped
healthcheck:
disable: true
2 changes: 2 additions & 0 deletions test/compose/disable_healthcheck/tests.sh
@@ -0,0 +1,2 @@
podman inspect --format='{{.Config.Healthcheck.Test}}' noHc
like $output "[NONE]" "$testname: healthcheck properly disabled"

0 comments on commit c5750af

Please sign in to comment.