summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcdoern <cbdoer23@g.holycross.edu>2021-07-26 09:05:05 -0400
committercdoern <cdoern@redhat.com>2021-07-28 09:52:41 -0400
commita9f6592af6646d3692e8a7260df98dd606aa4d9b (patch)
treed4fe0c7816873543f5fccc089468321f3ac7fabc
parentfd1f57b3a667f69bb2ae424ec7a7735ef8f1fda4 (diff)
downloadpodman-a9f6592af6646d3692e8a7260df98dd606aa4d9b.tar.gz
podman-a9f6592af6646d3692e8a7260df98dd606aa4d9b.tar.bz2
podman-a9f6592af6646d3692e8a7260df98dd606aa4d9b.zip
Fixed Healthcheck formatting, string to []string
Compat healthcheck tests are of the format []string but podman's were of the format string. Converted podman's to []string at the specgen level since it has the same effect and removed the incorrect parsing of compat healthchecks. fixes #10617 Signed-off-by: cdoern <cdoern@redhat.com>
-rw-r--r--cmd/podman/common/create_opts.go4
-rw-r--r--cmd/podman/common/specgen.go33
-rw-r--r--test/e2e/healthcheck_run_test.go10
-rw-r--r--test/e2e/run_test.go2
4 files changed, 36 insertions, 13 deletions
diff --git a/cmd/podman/common/create_opts.go b/cmd/podman/common/create_opts.go
index cca6399b7..42e0efe5d 100644
--- a/cmd/podman/common/create_opts.go
+++ b/cmd/podman/common/create_opts.go
@@ -521,7 +521,9 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, rtc *c
for _, str := range cc.Config.Healthcheck.Test {
finCmd = finCmd + str + " "
}
- finCmd = finCmd[:len(finCmd)-1]
+ if len(finCmd) > 1 {
+ finCmd = finCmd[:len(finCmd)-1]
+ }
cliOpts.HealthCmd = finCmd
cliOpts.HealthInterval = cc.Config.Healthcheck.Interval.String()
cliOpts.HealthRetries = uint(cc.Config.Healthcheck.Retries)
diff --git a/cmd/podman/common/specgen.go b/cmd/podman/common/specgen.go
index c0cc7d17b..149869237 100644
--- a/cmd/podman/common/specgen.go
+++ b/cmd/podman/common/specgen.go
@@ -516,7 +516,6 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
if len(con) != 2 {
return fmt.Errorf("invalid --security-opt 1: %q", opt)
}
-
switch con[0] {
case "apparmor":
s.ContainerSecurityConfig.ApparmorProfile = con[1]
@@ -655,21 +654,33 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
return nil
}
-func makeHealthCheckFromCli(inCmd string, interval string, retries uint, timeout, startPeriod string) (*manifest.Schema2HealthConfig, error) {
- var cmdArr []string
- cmdSplitPrelim := strings.SplitN(inCmd, " ", 2)
- if cmdSplitPrelim[0] == "CMD-SHELL" {
- cmdArr = cmdSplitPrelim
- } else if cmdSplitPrelim[0] != "CMD" && cmdSplitPrelim[0] != "none" { // if it isnt a cmd-shell or a cmd, it is a command
- cmdArr = []string{"CMD-SHELL"}
- cmdArr = append(cmdArr, inCmd)
- } else {
- cmdArr = strings.Fields(inCmd)
+func makeHealthCheckFromCli(inCmd, interval string, retries uint, timeout, startPeriod string) (*manifest.Schema2HealthConfig, error) {
+ cmdArr := []string{}
+ isArr := true
+ err := json.Unmarshal([]byte(inCmd), &cmdArr) // array unmarshalling
+ if err != nil {
+ cmdArr = strings.SplitN(inCmd, " ", 2) // default for compat
+ isArr = false
}
// Every healthcheck requires a command
if len(cmdArr) == 0 {
return nil, errors.New("Must define a healthcheck command for all healthchecks")
}
+ concat := ""
+ if cmdArr[0] == "CMD" || cmdArr[0] == "none" { // this is for compat, we are already split properly for most compat cases
+ cmdArr = strings.Fields(inCmd)
+ } else if cmdArr[0] != "CMD-SHELL" { // this is for podman side of things, wont contain the keywords
+ if isArr && len(cmdArr) > 1 { // an array of consecutive commands
+ cmdArr = append([]string{"CMD"}, cmdArr...)
+ } else { // one singular command
+ if len(cmdArr) == 1 {
+ concat = cmdArr[0]
+ } else {
+ concat = strings.Join(cmdArr[0:], " ")
+ }
+ cmdArr = append([]string{"CMD-SHELL"}, concat)
+ }
+ }
if cmdArr[0] == "none" { // if specified to remove healtcheck
cmdArr = []string{"NONE"}
diff --git a/test/e2e/healthcheck_run_test.go b/test/e2e/healthcheck_run_test.go
index ed7958323..bea22ea85 100644
--- a/test/e2e/healthcheck_run_test.go
+++ b/test/e2e/healthcheck_run_test.go
@@ -173,6 +173,16 @@ var _ = Describe("Podman healthcheck run", func() {
Expect(inspect[0].State.Healthcheck.Status).To(Equal("healthy"))
})
+ It("podman healthcheck unhealthy but valid arguments check", func() {
+ session := podmanTest.Podman([]string{"run", "-dt", "--name", "hc", "--health-retries", "2", "--health-cmd", "[\"ls\", \"/foo\"]", ALPINE, "top"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ hc := podmanTest.Podman([]string{"healthcheck", "run", "hc"})
+ hc.WaitWithDefaultTimeout()
+ Expect(hc.ExitCode()).To(Equal(1))
+ })
+
It("podman healthcheck single healthy result changes failed to healthy", func() {
session := podmanTest.Podman([]string{"run", "-dt", "--name", "hc", "--health-retries", "2", "--health-cmd", "ls /foo || exit 1", ALPINE, "top"})
session.WaitWithDefaultTimeout()
diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go
index c9f7cb6a9..5a29b035b 100644
--- a/test/e2e/run_test.go
+++ b/test/e2e/run_test.go
@@ -1205,7 +1205,7 @@ USER mail`, BB)
})
It("podman run with bad healthcheck retries", func() {
- session := podmanTest.Podman([]string{"run", "-dt", "--health-cmd", "foo", "--health-retries", "0", ALPINE, "top"})
+ session := podmanTest.Podman([]string{"run", "-dt", "--health-cmd", "[\"foo\"]", "--health-retries", "0", ALPINE, "top"})
session.Wait()
Expect(session).To(ExitWithError())
Expect(session.ErrorToString()).To(ContainSubstring("healthcheck-retries must be greater than 0"))