3
3
package libpod
4
4
5
5
import (
6
- "fmt"
7
6
"strconv"
8
- "strings"
9
7
"time"
10
8
11
9
"github.com/sirupsen/logrus"
@@ -19,11 +17,16 @@ func (r *ConmonOCIRuntime) addHealthCheckArgs(ctr *Container, args []string) []s
19
17
if healthConfig != nil {
20
18
logrus .Debugf ("HEALTHCHECK: Adding healthcheck CLI args for container %s" , ctr .ID ())
21
19
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 )
24
22
if healthCmd != "" {
25
23
args = append (args , "--healthcheck-cmd" , healthCmd )
26
24
25
+ // Add all healthcheck arguments
26
+ for _ , arg := range healthArgs {
27
+ args = append (args , "--healthcheck-arg" , arg )
28
+ }
29
+
27
30
// Add optional healthcheck parameters with validation and defaults
28
31
interval := r .validateAndGetInterval (healthConfig .Interval )
29
32
timeout := r .validateAndGetTimeout (healthConfig .Timeout )
@@ -35,8 +38,8 @@ func (r *ConmonOCIRuntime) addHealthCheckArgs(ctr *Container, args []string) []s
35
38
args = append (args , "--healthcheck-retries" , strconv .Itoa (retries ))
36
39
args = append (args , "--healthcheck-start-period" , strconv .Itoa (startPeriod ))
37
40
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 )
40
43
} else {
41
44
logrus .Warnf ("HEALTHCHECK: Container %s has healthcheck config but no valid command" , ctr .ID ())
42
45
}
@@ -47,32 +50,34 @@ func (r *ConmonOCIRuntime) addHealthCheckArgs(ctr *Container, args []string) []s
47
50
return args
48
51
}
49
52
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 ) {
52
55
if len (test ) == 0 {
53
- return ""
56
+ return "" , nil
54
57
}
55
58
56
59
// Handle special cases
57
60
switch test [0 ] {
58
61
case "" , "NONE" :
59
- return ""
62
+ return "" , nil
60
63
case "CMD" :
61
64
// CMD format: ["CMD", "curl", "-f", "http://localhost:8080/health"]
65
+ // -> cmd="curl", args=["-f", "http://localhost:8080/health"]
62
66
if len (test ) > 1 {
63
- return strings . Join ( test [1 : ], " " )
67
+ return test [1 ], test [ 2 :]
64
68
}
65
- return ""
69
+ return "" , nil
66
70
case "CMD-SHELL" :
67
71
// 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"]
69
73
if len (test ) > 1 {
70
- return fmt . Sprintf ( "/bin/sh -c %q " , test [1 ])
74
+ return "/bin/sh" , [] string { "-c " , test [1 ]}
71
75
}
72
- return ""
76
+ return "" , nil
73
77
default :
74
78
// 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 :]
76
81
}
77
82
}
78
83
0 commit comments