mirror of
https://github.com/containers/podman.git
synced 2025-06-21 01:19:15 +08:00
Merge pull request #5994 from giuseppe/fix-healthchecks
v2, podman: fix healthchecks
This commit is contained in:
@ -203,10 +203,17 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
|
||||
s.User = c.User
|
||||
inputCommand := args[1:]
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if c.NoHealthCheck {
|
||||
s.HealthConfig = &manifest.Schema2HealthConfig{
|
||||
Test: []string{"NONE"},
|
||||
}
|
||||
}
|
||||
|
||||
userNS := ns.UsernsMode(c.UserNS)
|
||||
@ -624,10 +631,15 @@ func makeHealthCheckFromCli(inCmd, interval string, retries uint, timeout, start
|
||||
|
||||
// first try to parse option value as JSON array of strings...
|
||||
cmd := []string{}
|
||||
err := json.Unmarshal([]byte(inCmd), &cmd)
|
||||
if err != nil {
|
||||
// ...otherwise pass it to "/bin/sh -c" inside the container
|
||||
cmd = []string{"CMD-SHELL", inCmd}
|
||||
|
||||
if inCmd == "none" {
|
||||
cmd = []string{"NONE"}
|
||||
} else {
|
||||
err := json.Unmarshal([]byte(inCmd), &cmd)
|
||||
if err != nil {
|
||||
// ...otherwise pass it to "/bin/sh -c" inside the container
|
||||
cmd = []string{"CMD-SHELL", inCmd}
|
||||
}
|
||||
}
|
||||
hc := manifest.Schema2HealthConfig{
|
||||
Test: cmd,
|
||||
|
@ -25,6 +25,13 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
|
||||
return err
|
||||
}
|
||||
|
||||
if s.HealthConfig == nil {
|
||||
s.HealthConfig, err = newImage.GetHealthCheck(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Image stop signal
|
||||
if s.StopSignal == nil {
|
||||
stopSignal, err := newImage.StopSignal(ctx)
|
||||
|
@ -18,7 +18,6 @@ var _ = Describe("Podman healthcheck run", func() {
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
Skip(v2fail)
|
||||
tempdir, err = CreateTempDirInTempDir()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
|
Reference in New Issue
Block a user