Skip to content

Commit

Permalink
Merge pull request #3508 from csomh/healthcheck-flag-compat
Browse files Browse the repository at this point in the history
Make the healthcheck flags compatible with Docker CLI
  • Loading branch information
openshift-merge-robot authored Jul 16, 2019
2 parents a449e9a + 47c1fe6 commit 400851a
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 31 deletions.
10 changes: 5 additions & 5 deletions cmd/podman/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,23 +244,23 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
"help", false, "",
)
createFlags.String(
"healthcheck-command", "",
"health-cmd", "",
"set a healthcheck command for the container ('none' disables the existing healthcheck)",
)
createFlags.String(
"healthcheck-interval", cliconfig.DefaultHealthCheckInterval,
"health-interval", cliconfig.DefaultHealthCheckInterval,
"set an interval for the healthchecks (a value of disable results in no automatic timer setup)",
)
createFlags.Uint(
"healthcheck-retries", cliconfig.DefaultHealthCheckRetries,
"health-retries", cliconfig.DefaultHealthCheckRetries,
"the number of retries allowed before a healthcheck is considered to be unhealthy",
)
createFlags.String(
"healthcheck-start-period", cliconfig.DefaultHealthCheckStartPeriod,
"health-start-period", cliconfig.DefaultHealthCheckStartPeriod,
"the initialization time needed for a container to bootstrap",
)
createFlags.String(
"healthcheck-timeout", cliconfig.DefaultHealthCheckTimeout,
"health-timeout", cliconfig.DefaultHealthCheckTimeout,
"the maximum time allowed to complete the healthcheck before an interval is considered failed",
)
createFlags.StringP(
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func init() {
getCreateFlags(&createCommand.PodmanCommand)
flags := createCommand.Flags()
flags.SetInterspersed(false)

flags.SetNormalizeFunc(aliasFlags)
}

func createCmd(c *cliconfig.CreateValues) error {
Expand Down
1 change: 1 addition & 0 deletions cmd/podman/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func init() {
runCommand.SetUsageTemplate(UsageTemplate())
flags := runCommand.Flags()
flags.SetInterspersed(false)
flags.SetNormalizeFunc(aliasFlags)
flags.Bool("sig-proxy", true, "Proxy received signals to the process")
getCreateFlags(&runCommand.PodmanCommand)
markFlagHiddenForRemoteClient("authfile", flags)
Expand Down
10 changes: 5 additions & 5 deletions cmd/podman/shared/intermediate.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,11 @@ func NewIntermediateLayer(c *cliconfig.PodmanCommand, remote bool) GenericCLIRes
m["gidmap"] = newCRStringSlice(c, "gidmap")
m["group-add"] = newCRStringSlice(c, "group-add")
m["help"] = newCRBool(c, "help")
m["healthcheck-command"] = newCRString(c, "healthcheck-command")
m["healthcheck-interval"] = newCRString(c, "healthcheck-interval")
m["healthcheck-retries"] = newCRUint(c, "healthcheck-retries")
m["healthcheck-start-period"] = newCRString(c, "healthcheck-start-period")
m["healthcheck-timeout"] = newCRString(c, "healthcheck-timeout")
m["healthcheck-command"] = newCRString(c, "health-cmd")
m["healthcheck-interval"] = newCRString(c, "health-interval")
m["healthcheck-retries"] = newCRUint(c, "health-retries")
m["healthcheck-start-period"] = newCRString(c, "health-start-period")
m["healthcheck-timeout"] = newCRString(c, "health-timeout")
m["hostname"] = newCRString(c, "hostname")
m["http-proxy"] = newCRBool(c, "http-proxy")
m["image-volume"] = newCRString(c, "image-volume")
Expand Down
16 changes: 16 additions & 0 deletions cmd/podman/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,19 @@ func markFlagHidden(flags *pflag.FlagSet, flag string) {
logrus.Errorf("unable to mark flag '%s' as hidden: %q", flag, err)
}
}

func aliasFlags(f *pflag.FlagSet, name string) pflag.NormalizedName {
switch name {
case "healthcheck-command":
name = "health-cmd"
case "healthcheck-interval":
name = "health-interval"
case "healthcheck-retries":
name = "health-retries"
case "healthcheck-start-period":
name = "health-start-period"
case "healthcheck-timeout":
name = "health-timeout"
}
return pflag.NormalizedName(name)
}
2 changes: 1 addition & 1 deletion completions/bash/podman
Original file line number Diff line number Diff line change
Expand Up @@ -1812,10 +1812,10 @@ _podman_container_run() {
--health-interval
--health-retries
--health-timeout
--health-start-period
"
boolean_options="$boolean_options
--detach -d
--no-healthcheck
--rm
--sig-proxy=false
"
Expand Down
10 changes: 5 additions & 5 deletions docs/podman-create.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ The following example maps uids 0-2000 in the container to the uids 30000-31999

Add additional groups to run as

**--healthcheck-command**=*"command"* | *'["command", "arg1", ...]'*
**--health-cmd**=*"command"* | *'["command", "arg1", ...]'*

Set or alter a healthcheck command for a container. The command is a command to be executed inside your
container that determines your container health. The command is required for other healthcheck options
Expand All @@ -281,20 +281,20 @@ to be applied. A value of `none` disables existing healthchecks.
Multiple options can be passed in the form of a JSON array; otherwise, the command will be interpreted
as an argument to `/bin/sh -c`.

**--healthcheck-interval**=*interval*
**--health-interval**=*interval*

Set an interval for the healthchecks (a value of `disable` results in no automatic timer setup) (default "30s")

**--healthcheck-retries**=*retries*
**--health-retries**=*retries*

The number of retries allowed before a healthcheck is considered to be unhealthy. The default value is `3`.

**--healthcheck-start-period**=*period*
**--health-start-period**=*period*

The initialization time needed for a container to bootstrap. The value can be expressed in time format like
`2m3s`. The default value is `0s`

**--healthcheck-timeout**=*timeout*
**--health-timeout**=*timeout*

The maximum time allowed to complete the healthcheck before an interval is considered failed. Like start-period, the
value can be expressed in a time format such as `1m22s`. The default value is `30s`.
Expand Down
10 changes: 5 additions & 5 deletions docs/podman-run.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ The example maps gids 0-2000 in the container to the gids 30000-31999 on the hos

Add additional groups to run as

**--healthcheck-command**=*"command"* | *'["command", "arg1", ...]'*
**--health-cmd**=*"command"* | *'["command", "arg1", ...]'*

Set or alter a healthcheck command for a container. The command is a command to be executed inside your
container that determines your container health. The command is required for other healthcheck options
Expand All @@ -288,20 +288,20 @@ to be applied. A value of `none` disables existing healthchecks.
Multiple options can be passed in the form of a JSON array; otherwise, the command will be interpreted
as an argument to `/bin/sh -c`.

**--healthcheck-interval**=*interval*
**--health-interval**=*interval*

Set an interval for the healthchecks (a value of `disable` results in no automatic timer setup) (default "30s")

**--healthcheck-retries**=*retries*
**--health-retries**=*retries*

The number of retries allowed before a healthcheck is considered to be unhealthy. The default value is `3`.

**--healthcheck-start-period**=*period*
**--health-start-period**=*period*

The initialization time needed for a container to bootstrap. The value can be expressed in time format like
`2m3s`. The default value is `0s`

**--healthcheck-timeout**=*timeout*
**--health-timeout**=*timeout*

The maximum time allowed to complete the healthcheck before an interval is considered failed. Like start-period, the
value can be expressed in a time format such as `1m22s`. The default value is `30s`.
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func (p *PodmanTestIntegration) RunNginxWithHealthCheck(name string) (*PodmanSes
if name != "" {
podmanArgs = append(podmanArgs, "--name", name)
}
podmanArgs = append(podmanArgs, "-dt", "-P", "--healthcheck-command", "curl http://localhost/", nginx)
podmanArgs = append(podmanArgs, "-dt", "-P", "--health-cmd", "curl http://localhost/", nginx)
session := p.Podman(podmanArgs)
session.WaitWithDefaultTimeout()
return session, session.OutputToString()
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/healthcheck_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ var _ = Describe("Podman healthcheck run", func() {
})

It("podman healthcheck should be starting", func() {
session := podmanTest.Podman([]string{"run", "-dt", "--name", "hc", "--healthcheck-retries", "2", "--healthcheck-command", "ls /foo || exit 1", ALPINE, "top"})
session := podmanTest.Podman([]string{"run", "-dt", "--name", "hc", "--health-retries", "2", "--health-cmd", "ls /foo || exit 1", ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
inspect := podmanTest.InspectContainer("hc")
Expect(inspect[0].State.Healthcheck.Status).To(Equal("starting"))
})

It("podman healthcheck failed checks in start-period should not change status", func() {
session := podmanTest.Podman([]string{"run", "-dt", "--name", "hc", "--healthcheck-start-period", "2m", "--healthcheck-retries", "2", "--healthcheck-command", "ls /foo || exit 1", ALPINE, "top"})
session := podmanTest.Podman([]string{"run", "-dt", "--name", "hc", "--health-start-period", "2m", "--health-retries", "2", "--health-cmd", "ls /foo || exit 1", ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

Expand All @@ -124,7 +124,7 @@ var _ = Describe("Podman healthcheck run", func() {
})

It("podman healthcheck failed checks must reach retries before unhealthy ", func() {
session := podmanTest.Podman([]string{"run", "-dt", "--name", "hc", "--healthcheck-retries", "2", "--healthcheck-command", "ls /foo || exit 1", ALPINE, "top"})
session := podmanTest.Podman([]string{"run", "-dt", "--name", "hc", "--health-retries", "2", "--health-cmd", "ls /foo || exit 1", ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

Expand All @@ -145,7 +145,7 @@ var _ = Describe("Podman healthcheck run", func() {
})

It("podman healthcheck good check results in healthy even in start-period", func() {
session := podmanTest.Podman([]string{"run", "-dt", "--name", "hc", "--healthcheck-start-period", "2m", "--healthcheck-retries", "2", "--healthcheck-command", "ls || exit 1", ALPINE, "top"})
session := podmanTest.Podman([]string{"run", "-dt", "--name", "hc", "--health-start-period", "2m", "--health-retries", "2", "--health-cmd", "ls || exit 1", ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

Expand All @@ -158,7 +158,7 @@ var _ = Describe("Podman healthcheck run", func() {
})

It("podman healthcheck single healthy result changes failed to healthy", func() {
session := podmanTest.Podman([]string{"run", "-dt", "--name", "hc", "--healthcheck-retries", "2", "--healthcheck-command", "ls /foo || exit 1", ALPINE, "top"})
session := podmanTest.Podman([]string{"run", "-dt", "--name", "hc", "--health-retries", "2", "--health-cmd", "ls /foo || exit 1", ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

Expand Down
6 changes: 3 additions & 3 deletions test/e2e/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,21 +750,21 @@ USER mail`
})

It("podman run with bad healthcheck retries", func() {
session := podmanTest.Podman([]string{"run", "-dt", "--healthcheck-command", "[\"foo\"]", "--healthcheck-retries", "0", ALPINE, "top"})
session := podmanTest.Podman([]string{"run", "-dt", "--health-cmd", "[\"foo\"]", "--health-retries", "0", ALPINE, "top"})
session.Wait()
Expect(session.ExitCode()).ToNot(Equal(0))
Expect(session.ErrorToString()).To(ContainSubstring("healthcheck-retries must be greater than 0"))
})

It("podman run with bad healthcheck timeout", func() {
session := podmanTest.Podman([]string{"run", "-dt", "--healthcheck-command", "[\"foo\"]", "--healthcheck-timeout", "0s", ALPINE, "top"})
session := podmanTest.Podman([]string{"run", "-dt", "--health-cmd", "[\"foo\"]", "--health-timeout", "0s", ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).ToNot(Equal(0))
Expect(session.ErrorToString()).To(ContainSubstring("healthcheck-timeout must be at least 1 second"))
})

It("podman run with bad healthcheck start-period", func() {
session := podmanTest.Podman([]string{"run", "-dt", "--healthcheck-command", "[\"foo\"]", "--healthcheck-start-period", "-1s", ALPINE, "top"})
session := podmanTest.Podman([]string{"run", "-dt", "--health-cmd", "[\"foo\"]", "--health-start-period", "-1s", ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).ToNot(Equal(0))
Expect(session.ErrorToString()).To(ContainSubstring("healthcheck-start-period must be 0 seconds or greater"))
Expand Down

0 comments on commit 400851a

Please sign in to comment.