mirror of
https://github.com/containers/podman.git
synced 2025-06-21 17:38:12 +08:00
Merge pull request #14626 from jakecorrenti/disable-docker-compose-health-check
Docker-compose disable healthcheck properly handled
This commit is contained in:
@ -47,3 +47,13 @@ const (
|
|||||||
// DefaultHealthCheckTimeout default value
|
// DefaultHealthCheckTimeout default value
|
||||||
DefaultHealthCheckTimeout = "30s"
|
DefaultHealthCheckTimeout = "30s"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// HealthConfig.Test options
|
||||||
|
const (
|
||||||
|
// HealthConfigTestNone disables healthcheck
|
||||||
|
HealthConfigTestNone = "NONE"
|
||||||
|
// HealthConfigTestCmd execs arguments directly
|
||||||
|
HealthConfigTestCmd = "CMD"
|
||||||
|
// HealthConfigTestCmdShell runs commands with the system's default shell
|
||||||
|
HealthConfigTestCmdShell = "CMD-SHELL"
|
||||||
|
)
|
||||||
|
@ -47,11 +47,11 @@ func (c *Container) runHealthCheck() (define.HealthCheckStatus, error) {
|
|||||||
return define.HealthCheckNotDefined, errors.Errorf("container %s has no defined healthcheck", c.ID())
|
return define.HealthCheckNotDefined, errors.Errorf("container %s has no defined healthcheck", c.ID())
|
||||||
}
|
}
|
||||||
switch hcCommand[0] {
|
switch hcCommand[0] {
|
||||||
case "", "NONE":
|
case "", define.HealthConfigTestNone:
|
||||||
return define.HealthCheckNotDefined, errors.Errorf("container %s has no defined healthcheck", c.ID())
|
return define.HealthCheckNotDefined, errors.Errorf("container %s has no defined healthcheck", c.ID())
|
||||||
case "CMD":
|
case define.HealthConfigTestCmd:
|
||||||
newCommand = hcCommand[1:]
|
newCommand = hcCommand[1:]
|
||||||
case "CMD-SHELL":
|
case define.HealthConfigTestCmdShell:
|
||||||
// TODO: SHELL command from image not available in Container - use Docker default
|
// TODO: SHELL command from image not available in Container - use Docker default
|
||||||
newCommand = []string{"/bin/sh", "-c", strings.Join(hcCommand[1:], " ")}
|
newCommand = []string{"/bin/sh", "-c", strings.Join(hcCommand[1:], " ")}
|
||||||
default:
|
default:
|
||||||
|
@ -511,12 +511,12 @@ func makeHealthCheck(inCmd string, interval int32, retries int32, timeout int32,
|
|||||||
cmd := []string{}
|
cmd := []string{}
|
||||||
|
|
||||||
if inCmd == "none" {
|
if inCmd == "none" {
|
||||||
cmd = []string{"NONE"}
|
cmd = []string{define.HealthConfigTestNone}
|
||||||
} else {
|
} else {
|
||||||
err := json.Unmarshal([]byte(inCmd), &cmd)
|
err := json.Unmarshal([]byte(inCmd), &cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// ...otherwise pass it to "/bin/sh -c" inside the container
|
// ...otherwise pass it to "/bin/sh -c" inside the container
|
||||||
cmd = []string{"CMD-SHELL"}
|
cmd = []string{define.HealthConfigTestCmdShell}
|
||||||
cmd = append(cmd, strings.Split(inCmd, " ")...)
|
cmd = append(cmd, strings.Split(inCmd, " ")...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -873,23 +873,23 @@ func makeHealthCheckFromCli(inCmd, interval string, retries uint, timeout, start
|
|||||||
}
|
}
|
||||||
|
|
||||||
var concat string
|
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]) == define.HealthConfigTestCmd || strings.ToUpper(cmdArr[0]) == define.HealthConfigTestNone { // this is for compat, we are already split properly for most compat cases
|
||||||
cmdArr = strings.Fields(inCmd)
|
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]) != define.HealthConfigTestCmdShell { // this is for podman side of things, won't contain the keywords
|
||||||
if isArr && len(cmdArr) > 1 { // an array of consecutive commands
|
if isArr && len(cmdArr) > 1 { // an array of consecutive commands
|
||||||
cmdArr = append([]string{"CMD"}, cmdArr...)
|
cmdArr = append([]string{define.HealthConfigTestCmd}, cmdArr...)
|
||||||
} else { // one singular command
|
} else { // one singular command
|
||||||
if len(cmdArr) == 1 {
|
if len(cmdArr) == 1 {
|
||||||
concat = cmdArr[0]
|
concat = cmdArr[0]
|
||||||
} else {
|
} else {
|
||||||
concat = strings.Join(cmdArr[0:], " ")
|
concat = strings.Join(cmdArr[0:], " ")
|
||||||
}
|
}
|
||||||
cmdArr = append([]string{"CMD-SHELL"}, concat)
|
cmdArr = append([]string{define.HealthConfigTestCmdShell}, concat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cmdArr[0] == "none" { // if specified to remove healtcheck
|
if strings.ToUpper(cmdArr[0]) == define.HealthConfigTestNone { // if specified to remove healtcheck
|
||||||
cmdArr = []string{"NONE"}
|
cmdArr = []string{define.HealthConfigTestNone}
|
||||||
}
|
}
|
||||||
|
|
||||||
// healthcheck is by default an array, so we simply pass the user input
|
// healthcheck is by default an array, so we simply pass the user input
|
||||||
|
10
test/compose/disable_healthcheck/docker-compose.yml
Normal file
10
test/compose/disable_healthcheck/docker-compose.yml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
version: "3.7"
|
||||||
|
services:
|
||||||
|
noHc:
|
||||||
|
image: alpine
|
||||||
|
container_name: noHc
|
||||||
|
ports:
|
||||||
|
- "4000:80"
|
||||||
|
restart: unless-stopped
|
||||||
|
healthcheck:
|
||||||
|
disable: true
|
2
test/compose/disable_healthcheck/tests.sh
Normal file
2
test/compose/disable_healthcheck/tests.sh
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
podman inspect --format='{{.Config.Healthcheck.Test}}' noHc
|
||||||
|
like $output "[NONE]" "$testname: healthcheck properly disabled"
|
Reference in New Issue
Block a user