@@ -93,19 +93,24 @@ func (c *Container) runHealthCheck(ctx context.Context, isStartup bool) (define.
93
93
streams .AttachInput = true
94
94
95
95
logrus .Debugf ("executing health check command %s for %s" , strings .Join (newCommand , " " ), c .ID ())
96
- timeStart := time .Now ()
97
96
hcResult := define .HealthCheckSuccess
98
97
config := new (ExecConfig )
99
98
config .Command = newCommand
100
- exitCode , hcErr := c .healthCheckExec (config , streams )
99
+ timeStart := time .Now ()
100
+ exitCode , hcErr := c .healthCheckExec (config , c .HealthCheckConfig ().Timeout , streams )
101
+ timeEnd := time .Now ()
101
102
if hcErr != nil {
102
103
hcResult = define .HealthCheckFailure
103
- if errors .Is (hcErr , define .ErrOCIRuntimeNotFound ) ||
104
+ switch {
105
+ case errors .Is (hcErr , define .ErrOCIRuntimeNotFound ) ||
104
106
errors .Is (hcErr , define .ErrOCIRuntimePermissionDenied ) ||
105
- errors .Is (hcErr , define .ErrOCIRuntime ) {
107
+ errors .Is (hcErr , define .ErrOCIRuntime ):
106
108
returnCode = 1
107
109
hcErr = nil
108
- } else {
110
+ case errors .Is (hcErr , define .ErrHealthCheckTimeout ):
111
+ returnCode = - 1
112
+ hcErr = fmt .Errorf ("healthcheck command exceeded timeout of %s" , c .HealthCheckConfig ().Timeout .String ())
113
+ default :
109
114
returnCode = 125
110
115
}
111
116
} else if exitCode != 0 {
@@ -140,7 +145,6 @@ func (c *Container) runHealthCheck(ctx context.Context, isStartup bool) (define.
140
145
hcResult = define .HealthCheckContainerStopped
141
146
}
142
147
143
- timeEnd := time .Now ()
144
148
if c .HealthCheckConfig ().StartPeriod > 0 {
145
149
// there is a start-period we need to honor; we add startPeriod to container start time
146
150
startPeriodTime := c .state .StartedTime .Add (c .HealthCheckConfig ().StartPeriod )
@@ -156,12 +160,6 @@ func (c *Container) runHealthCheck(ctx context.Context, isStartup bool) (define.
156
160
eventLog = eventLog [:c .HealthCheckMaxLogSize ()]
157
161
}
158
162
159
- if timeEnd .Sub (timeStart ) > c .HealthCheckConfig ().Timeout {
160
- returnCode = - 1
161
- hcResult = define .HealthCheckFailure
162
- hcErr = fmt .Errorf ("healthcheck command exceeded timeout of %s" , c .HealthCheckConfig ().Timeout .String ())
163
- }
164
-
165
163
hcl := newHealthCheckLog (timeStart , timeEnd , returnCode , eventLog )
166
164
167
165
healthCheckResult , err := c .updateHealthCheckLog (hcl , hcResult , inStartPeriod , isStartup )
0 commit comments