Skip to content

Commit e7f75a2

Browse files
committed
add default values to healthConfig
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent 93d74e6 commit e7f75a2

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

pkg/cmd/container/create.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,11 @@ func withHealthcheck(options types.ContainerCreateOptions, ensuredImage *imgutil
892892
hc.StartPeriod = options.HealthStartPeriod
893893
}
894894

895+
// Apply defaults for any unset values, but only if we have a healthcheck configured
896+
if len(hc.Test) > 0 && hc.Test[0] != "NONE" {
897+
hc.ApplyDefaults()
898+
}
899+
895900
// If no healthcheck config is set (via CLI or image), return empty string so we skip adding to container config.
896901
if reflect.DeepEqual(hc, &healthcheck.Healthcheck{}) {
897902
return "", nil

pkg/healthcheck/health.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,19 @@ func HealthcheckResultFromJSON(s string) (*HealthcheckResult, error) {
136136
}
137137
return &r, nil
138138
}
139+
140+
// ApplyDefaults sets default values for unset healthcheck fields
141+
func (hc *Healthcheck) ApplyDefaults() {
142+
if hc.Interval == 0 {
143+
hc.Interval = DefaultProbeInterval
144+
}
145+
if hc.Timeout == 0 {
146+
hc.Timeout = DefaultProbeTimeout
147+
}
148+
if hc.StartPeriod == 0 {
149+
hc.StartPeriod = DefaultStartPeriod
150+
}
151+
if hc.Retries == 0 {
152+
hc.Retries = DefaultProbeRetries
153+
}
154+
}

pkg/healthcheck/healthcheck_manager_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func shouldSkipHealthCheckSystemd(hc *Healthcheck, cfg *config.Config) bool {
265265
}
266266

267267
// Don't proceed if health check is nil, empty, explicitly NONE or interval is 0.
268-
if hc == nil || len(hc.Test) == 0 || hc.Test[0] == "NONE" || hc.Interval == 0 {
268+
if hc == nil || len(hc.Test) == 0 || hc.Test[0] == "NONE" {
269269
return true
270270
}
271271
return false

0 commit comments

Comments
 (0)