Skip to content

Commit 5ad6579

Browse files
author
Samuel Archambault
committed
commit for backup
1 parent 364de91 commit 5ad6579

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

libpod/oci_conmon_nosystemd.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
package libpod
44

55
import (
6-
"fmt"
76
"strconv"
8-
"strings"
97
"time"
108

119
"github.com/sirupsen/logrus"
@@ -19,11 +17,16 @@ func (r *ConmonOCIRuntime) addHealthCheckArgs(ctr *Container, args []string) []s
1917
if healthConfig != nil {
2018
logrus.Debugf("HEALTHCHECK: Adding healthcheck CLI args for container %s", ctr.ID())
2119

22-
// Build healthcheck command string from test array
23-
healthCmd := r.buildHealthcheckCmd(healthConfig.Test)
20+
// Build healthcheck command and arguments from test array
21+
healthCmd, healthArgs := r.buildHealthcheckCmdAndArgs(healthConfig.Test)
2422
if healthCmd != "" {
2523
args = append(args, "--healthcheck-cmd", healthCmd)
2624

25+
// Add all healthcheck arguments
26+
for _, arg := range healthArgs {
27+
args = append(args, "--healthcheck-arg", arg)
28+
}
29+
2730
// Add optional healthcheck parameters with validation and defaults
2831
interval := r.validateAndGetInterval(healthConfig.Interval)
2932
timeout := r.validateAndGetTimeout(healthConfig.Timeout)
@@ -35,8 +38,8 @@ func (r *ConmonOCIRuntime) addHealthCheckArgs(ctr *Container, args []string) []s
3538
args = append(args, "--healthcheck-retries", strconv.Itoa(retries))
3639
args = append(args, "--healthcheck-start-period", strconv.Itoa(startPeriod))
3740

38-
logrus.Debugf("HEALTHCHECK: Added healthcheck args for container %s: cmd=%s, interval=%ds, timeout=%ds, retries=%d, start-period=%ds",
39-
ctr.ID(), healthCmd, interval, timeout, retries, startPeriod)
41+
logrus.Debugf("HEALTHCHECK: Added healthcheck args for container %s: cmd=%s, args=%v, interval=%ds, timeout=%ds, retries=%d, start-period=%ds",
42+
ctr.ID(), healthCmd, healthArgs, interval, timeout, retries, startPeriod)
4043
} else {
4144
logrus.Warnf("HEALTHCHECK: Container %s has healthcheck config but no valid command", ctr.ID())
4245
}
@@ -47,32 +50,34 @@ func (r *ConmonOCIRuntime) addHealthCheckArgs(ctr *Container, args []string) []s
4750
return args
4851
}
4952

50-
// buildHealthcheckCmd converts Podman's healthcheck test array to a single command string
51-
func (r *ConmonOCIRuntime) buildHealthcheckCmd(test []string) string {
53+
// buildHealthcheckCmdAndArgs converts Podman's healthcheck test array to command and arguments
54+
func (r *ConmonOCIRuntime) buildHealthcheckCmdAndArgs(test []string) (string, []string) {
5255
if len(test) == 0 {
53-
return ""
56+
return "", nil
5457
}
5558

5659
// Handle special cases
5760
switch test[0] {
5861
case "", "NONE":
59-
return ""
62+
return "", nil
6063
case "CMD":
6164
// CMD format: ["CMD", "curl", "-f", "http://localhost:8080/health"]
65+
// -> cmd="curl", args=["-f", "http://localhost:8080/health"]
6266
if len(test) > 1 {
63-
return strings.Join(test[1:], " ")
67+
return test[1], test[2:]
6468
}
65-
return ""
69+
return "", nil
6670
case "CMD-SHELL":
6771
// CMD-SHELL format: ["CMD-SHELL", "curl -f http://localhost:8080/health"]
68-
// Wrap with sh -c for shell execution
72+
// -> cmd="/bin/sh", args=["-c", "curl -f http://localhost:8080/health"]
6973
if len(test) > 1 {
70-
return fmt.Sprintf("/bin/sh -c %q", test[1])
74+
return "/bin/sh", []string{"-c", test[1]}
7175
}
72-
return ""
76+
return "", nil
7377
default:
7478
// Direct command format: ["curl", "-f", "http://localhost:8080/health"]
75-
return strings.Join(test, " ")
79+
// -> cmd="curl", args=["-f", "http://localhost:8080/health"]
80+
return test[0], test[1:]
7681
}
7782
}
7883

0 commit comments

Comments
 (0)