Merge pull request #5994 from giuseppe/fix-healthchecks

v2, podman: fix healthchecks
This commit is contained in:
OpenShift Merge Robot
2020-04-27 15:40:24 +02:00
committed by GitHub
3 changed files with 23 additions and 5 deletions

View File

@ -203,10 +203,17 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
s.User = c.User s.User = c.User
inputCommand := args[1:] inputCommand := args[1:]
if len(c.HealthCmd) > 0 { if len(c.HealthCmd) > 0 {
if c.NoHealthCheck {
return errors.New("Cannot specify both --no-healthcheck and --health-cmd")
}
s.HealthConfig, err = makeHealthCheckFromCli(c.HealthCmd, c.HealthInterval, c.HealthRetries, c.HealthTimeout, c.HealthStartPeriod) s.HealthConfig, err = makeHealthCheckFromCli(c.HealthCmd, c.HealthInterval, c.HealthRetries, c.HealthTimeout, c.HealthStartPeriod)
if err != nil { if err != nil {
return err return err
} }
} else if c.NoHealthCheck {
s.HealthConfig = &manifest.Schema2HealthConfig{
Test: []string{"NONE"},
}
} }
userNS := ns.UsernsMode(c.UserNS) userNS := ns.UsernsMode(c.UserNS)
@ -624,11 +631,16 @@ func makeHealthCheckFromCli(inCmd, interval string, retries uint, timeout, start
// first try to parse option value as JSON array of strings... // first try to parse option value as JSON array of strings...
cmd := []string{} cmd := []string{}
if inCmd == "none" {
cmd = []string{"NONE"}
} 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", inCmd} cmd = []string{"CMD-SHELL", inCmd}
} }
}
hc := manifest.Schema2HealthConfig{ hc := manifest.Schema2HealthConfig{
Test: cmd, Test: cmd,
} }

View File

@ -25,6 +25,13 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
return err return err
} }
if s.HealthConfig == nil {
s.HealthConfig, err = newImage.GetHealthCheck(ctx)
if err != nil {
return err
}
}
// Image stop signal // Image stop signal
if s.StopSignal == nil { if s.StopSignal == nil {
stopSignal, err := newImage.StopSignal(ctx) stopSignal, err := newImage.StopSignal(ctx)

View File

@ -18,7 +18,6 @@ var _ = Describe("Podman healthcheck run", func() {
) )
BeforeEach(func() { BeforeEach(func() {
Skip(v2fail)
tempdir, err = CreateTempDirInTempDir() tempdir, err = CreateTempDirInTempDir()
if err != nil { if err != nil {
os.Exit(1) os.Exit(1)