mirror of
https://github.com/containers/podman.git
synced 2025-06-20 00:51:16 +08:00
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:
@ -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(
|
||||
|
@ -40,7 +40,7 @@ func init() {
|
||||
getCreateFlags(&createCommand.PodmanCommand)
|
||||
flags := createCommand.Flags()
|
||||
flags.SetInterspersed(false)
|
||||
|
||||
flags.SetNormalizeFunc(aliasFlags)
|
||||
}
|
||||
|
||||
func createCmd(c *cliconfig.CreateValues) error {
|
||||
|
@ -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)
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
@ -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`.
|
||||
|
@ -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
|
||||
@ -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`.
|
||||
|
@ -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()
|
||||
|
@ -95,7 +95,7 @@ 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")
|
||||
@ -103,7 +103,7 @@ var _ = Describe("Podman healthcheck run", 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()
|
||||
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() {
|
||||
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))
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -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))
|
||||
|
||||
|
@ -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"))
|
||||
|
Reference in New Issue
Block a user