Make the healthcheck flags compatible with Docker CLI

Docker CLI calls the healthcheck flags "--health-*", instead of
"--healthcheck-*".

Introduce the former, in order to keep compatibility, and alias
the later, in order to avoid breaking current usage.

Change "--healthcheck-*" to "--health-*" in the docs and tests.

Signed-off-by: Hunor Csomortáni <csomh@redhat.com>
This commit is contained in:
Hunor Csomortáni
2019-07-04 14:24:09 +02:00
parent 51c00eae8b
commit 3e53bfe36e
10 changed files with 47 additions and 30 deletions

View File

@ -244,23 +244,23 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
"help", false, "", "help", false, "",
) )
createFlags.String( createFlags.String(
"healthcheck-command", "", "health-cmd", "",
"set a healthcheck command for the container ('none' disables the existing healthcheck)", "set a healthcheck command for the container ('none' disables the existing healthcheck)",
) )
createFlags.String( 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)", "set an interval for the healthchecks (a value of disable results in no automatic timer setup)",
) )
createFlags.Uint( createFlags.Uint(
"healthcheck-retries", cliconfig.DefaultHealthCheckRetries, "health-retries", cliconfig.DefaultHealthCheckRetries,
"the number of retries allowed before a healthcheck is considered to be unhealthy", "the number of retries allowed before a healthcheck is considered to be unhealthy",
) )
createFlags.String( createFlags.String(
"healthcheck-start-period", cliconfig.DefaultHealthCheckStartPeriod, "health-start-period", cliconfig.DefaultHealthCheckStartPeriod,
"the initialization time needed for a container to bootstrap", "the initialization time needed for a container to bootstrap",
) )
createFlags.String( createFlags.String(
"healthcheck-timeout", cliconfig.DefaultHealthCheckTimeout, "health-timeout", cliconfig.DefaultHealthCheckTimeout,
"the maximum time allowed to complete the healthcheck before an interval is considered failed", "the maximum time allowed to complete the healthcheck before an interval is considered failed",
) )
createFlags.StringP( createFlags.StringP(

View File

@ -40,7 +40,7 @@ func init() {
getCreateFlags(&createCommand.PodmanCommand) getCreateFlags(&createCommand.PodmanCommand)
flags := createCommand.Flags() flags := createCommand.Flags()
flags.SetInterspersed(false) flags.SetInterspersed(false)
flags.SetNormalizeFunc(aliasFlags)
} }
func createCmd(c *cliconfig.CreateValues) error { func createCmd(c *cliconfig.CreateValues) error {

View File

@ -34,6 +34,7 @@ func init() {
runCommand.SetUsageTemplate(UsageTemplate()) runCommand.SetUsageTemplate(UsageTemplate())
flags := runCommand.Flags() flags := runCommand.Flags()
flags.SetInterspersed(false) flags.SetInterspersed(false)
flags.SetNormalizeFunc(aliasFlags)
flags.Bool("sig-proxy", true, "Proxy received signals to the process") flags.Bool("sig-proxy", true, "Proxy received signals to the process")
getCreateFlags(&runCommand.PodmanCommand) getCreateFlags(&runCommand.PodmanCommand)
markFlagHiddenForRemoteClient("authfile", flags) markFlagHiddenForRemoteClient("authfile", flags)

View File

@ -399,11 +399,11 @@ func NewIntermediateLayer(c *cliconfig.PodmanCommand, remote bool) GenericCLIRes
m["gidmap"] = newCRStringSlice(c, "gidmap") m["gidmap"] = newCRStringSlice(c, "gidmap")
m["group-add"] = newCRStringSlice(c, "group-add") m["group-add"] = newCRStringSlice(c, "group-add")
m["help"] = newCRBool(c, "help") m["help"] = newCRBool(c, "help")
m["healthcheck-command"] = newCRString(c, "healthcheck-command") m["healthcheck-command"] = newCRString(c, "health-cmd")
m["healthcheck-interval"] = newCRString(c, "healthcheck-interval") m["healthcheck-interval"] = newCRString(c, "health-interval")
m["healthcheck-retries"] = newCRUint(c, "healthcheck-retries") m["healthcheck-retries"] = newCRUint(c, "health-retries")
m["healthcheck-start-period"] = newCRString(c, "healthcheck-start-period") m["healthcheck-start-period"] = newCRString(c, "health-start-period")
m["healthcheck-timeout"] = newCRString(c, "healthcheck-timeout") m["healthcheck-timeout"] = newCRString(c, "health-timeout")
m["hostname"] = newCRString(c, "hostname") m["hostname"] = newCRString(c, "hostname")
m["http-proxy"] = newCRBool(c, "http-proxy") m["http-proxy"] = newCRBool(c, "http-proxy")
m["image-volume"] = newCRString(c, "image-volume") m["image-volume"] = newCRString(c, "image-volume")

View File

@ -47,3 +47,19 @@ func markFlagHidden(flags *pflag.FlagSet, flag string) {
logrus.Errorf("unable to mark flag '%s' as hidden: %q", flag, err) 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)
}

View File

@ -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 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 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 container that determines your container health. The command is required for other healthcheck options
@ -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 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`. 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") 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`. 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 The initialization time needed for a container to bootstrap. The value can be expressed in time format like
`2m3s`. The default value is `0s` `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 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`. value can be expressed in a time format such as `1m22s`. The default value is `30s`.

View File

@ -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 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 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 container that determines your container health. The command is required for other healthcheck options
@ -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 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`. 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") 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`. 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 The initialization time needed for a container to bootstrap. The value can be expressed in time format like
`2m3s`. The default value is `0s` `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 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`. value can be expressed in a time format such as `1m22s`. The default value is `30s`.

View File

@ -375,7 +375,7 @@ func (p *PodmanTestIntegration) RunNginxWithHealthCheck(name string) (*PodmanSes
if name != "" { if name != "" {
podmanArgs = append(podmanArgs, "--name", 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 := p.Podman(podmanArgs)
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
return session, session.OutputToString() return session, session.OutputToString()

View File

@ -95,7 +95,7 @@ var _ = Describe("Podman healthcheck run", func() {
}) })
It("podman healthcheck should be starting", 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() session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0)) Expect(session.ExitCode()).To(Equal(0))
inspect := podmanTest.InspectContainer("hc") inspect := podmanTest.InspectContainer("hc")
@ -103,7 +103,7 @@ var _ = Describe("Podman healthcheck run", func() {
}) })
It("podman healthcheck failed checks in start-period should not change status", func() { 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() session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0)) Expect(session.ExitCode()).To(Equal(0))
@ -124,7 +124,7 @@ var _ = Describe("Podman healthcheck run", func() {
}) })
It("podman healthcheck failed checks must reach retries before unhealthy ", 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() session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0)) Expect(session.ExitCode()).To(Equal(0))
@ -145,7 +145,7 @@ var _ = Describe("Podman healthcheck run", func() {
}) })
It("podman healthcheck good check results in healthy even in start-period", 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() session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0)) Expect(session.ExitCode()).To(Equal(0))
@ -158,7 +158,7 @@ var _ = Describe("Podman healthcheck run", func() {
}) })
It("podman healthcheck single healthy result changes failed to healthy", 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() session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0)) Expect(session.ExitCode()).To(Equal(0))

View File

@ -750,21 +750,21 @@ USER mail`
}) })
It("podman run with bad healthcheck retries", func() { 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() session.Wait()
Expect(session.ExitCode()).ToNot(Equal(0)) Expect(session.ExitCode()).ToNot(Equal(0))
Expect(session.ErrorToString()).To(ContainSubstring("healthcheck-retries must be greater than 0")) Expect(session.ErrorToString()).To(ContainSubstring("healthcheck-retries must be greater than 0"))
}) })
It("podman run with bad healthcheck timeout", func() { 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() session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).ToNot(Equal(0)) Expect(session.ExitCode()).ToNot(Equal(0))
Expect(session.ErrorToString()).To(ContainSubstring("healthcheck-timeout must be at least 1 second")) Expect(session.ErrorToString()).To(ContainSubstring("healthcheck-timeout must be at least 1 second"))
}) })
It("podman run with bad healthcheck start-period", func() { 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() session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).ToNot(Equal(0)) Expect(session.ExitCode()).ToNot(Equal(0))
Expect(session.ErrorToString()).To(ContainSubstring("healthcheck-start-period must be 0 seconds or greater")) Expect(session.ErrorToString()).To(ContainSubstring("healthcheck-start-period must be 0 seconds or greater"))