Skip to content

Commit

Permalink
healthcheck: improve command list parser
Browse files Browse the repository at this point in the history
- remove duplicate check, already called in HealthCheck()
- reject zero-length command list and empty command string as errorneous
- support all Docker command list keywords: NONE, CMD or CMD-SHELL
- use Docker default "/bin/sh -c" for CMD-SHELL

Fixes #3507

Signed-off-by: Stefan Becker <[email protected]>
  • Loading branch information
stefanb2 committed Jul 16, 2019
1 parent d2291ec commit dd0ea08
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions libpod/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,20 @@ func (c *Container) runHealthCheck() (HealthCheckStatus, error) {
capture bytes.Buffer
inStartPeriod bool
)
hcStatus, err := checkHealthCheckCanBeRun(c)
if err != nil {
return hcStatus, err
}
hcCommand := c.HealthCheckConfig().Test
if len(hcCommand) > 0 && hcCommand[0] == "CMD-SHELL" {
newCommand = []string{"sh", "-c", strings.Join(hcCommand[1:], " ")}
} else {
if len(hcCommand) < 1 {
return HealthCheckNotDefined, errors.Errorf("container %s has no defined healthcheck", c.ID())
}
switch hcCommand[0] {
case "", "NONE":
return HealthCheckNotDefined, errors.Errorf("container %s has no defined healthcheck", c.ID())
case "CMD":
newCommand = hcCommand[1:]
case "CMD-SHELL":
// TODO: SHELL command from image not available in Container - use Docker default
newCommand = []string{"/bin/sh", "-c", strings.Join(hcCommand[1:], " ")}
default:
// command supplied on command line - pass as-is
newCommand = hcCommand
}
captureBuffer := bufio.NewWriter(&capture)
Expand Down

0 comments on commit dd0ea08

Please sign in to comment.