Merge pull request #3539 from stefanb2/topic-pr-3507-3525

Fix handling of healthcheck from image
This commit is contained in:
OpenShift Merge Robot
2019-07-16 16:38:09 +02:00
committed by GitHub
2 changed files with 40 additions and 7 deletions

View File

@ -115,6 +115,30 @@ func CreateContainer(ctx context.Context, c *GenericCLIResults, runtime *libpod.
if err != nil {
return nil, nil, errors.Wrapf(err, "unable to get healthcheck for %s", c.InputArgs[0])
}
if healthCheck != nil {
hcCommand := healthCheck.Test
if len(hcCommand) < 1 || hcCommand[0] == "" || hcCommand[0] == "NONE" {
// disable health check
healthCheck = nil
} else {
// apply defaults if image doesn't override them
if healthCheck.Interval == 0 {
healthCheck.Interval = 30 * time.Second
}
if healthCheck.Timeout == 0 {
healthCheck.Timeout = 30 * time.Second
}
/* Docker default is 0s, so the following would be a no-op
if healthCheck.StartPeriod == 0 {
healthCheck.StartPeriod = 0 * time.Second
}
*/
if healthCheck.Retries == 0 {
healthCheck.Retries = 3
}
}
}
}
}
}

View File

@ -107,16 +107,25 @@ 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
}
if len(newCommand) < 1 || newCommand[0] == "" {
return HealthCheckNotDefined, errors.Errorf("container %s has no defined healthcheck", c.ID())
}
captureBuffer := bufio.NewWriter(&capture)
hcw := hcWriteCloser{
captureBuffer,