@@ -64,7 +64,7 @@ pub struct ProbeBuilder<Action, Period> {
6464 failure_threshold : i32 ,
6565 timeout : Duration ,
6666 initial_delay : Duration ,
67- termination_grace_period : Duration ,
67+ termination_grace_period : Option < Duration > ,
6868}
6969
7070/// Available probes
@@ -145,7 +145,7 @@ impl ProbeBuilder<(), ()> {
145145 failure_threshold : 1 ,
146146 timeout : Duration :: from_secs ( 1 ) ,
147147 initial_delay : Duration :: from_secs ( 0 ) ,
148- termination_grace_period : Duration :: from_secs ( 0 ) ,
148+ termination_grace_period : None ,
149149 }
150150 }
151151}
@@ -200,24 +200,48 @@ impl ProbeBuilder<ProbeAction, Duration> {
200200 Ok ( self . with_success_threshold ( success_threshold. ceil ( ) as i32 ) )
201201 }
202202
203- /// How often the probe must fail before being considered failed.
203+ /// After a probe fails `failureThreshold` times in a row, Kubernetes considers that the
204+ /// overall check has failed: the container is not ready/healthy/live.
205+ ///
206+ /// Minimum value is 1 second. For the case of a startup or liveness probe, if at least
207+ /// `failureThreshold` probes have failed, Kubernetes treats the container as unhealthy and
208+ /// triggers a restart for that specific container. The kubelet honors the setting of
209+ /// `terminationGracePeriodSeconds` for that container. For a failed readiness probe, the
210+ /// kubelet continues running the container that failed checks, and also continues to run more
211+ /// probes; because the check failed, the kubelet sets the `Ready` condition on the Pod to
212+ /// `false`.
204213 pub fn with_failure_threshold ( mut self , failure_threshold : i32 ) -> Self {
205214 self . failure_threshold = failure_threshold;
206215 self
207216 }
208217
218+ /// Number of seconds after which the probe times out.
219+ ///
220+ /// Minimum value is 1 second.
209221 pub fn with_timeout ( mut self , timeout : Duration ) -> Self {
210222 self . timeout = timeout;
211223 self
212224 }
213225
226+ /// Number of seconds after the container has started before startup, liveness or readiness
227+ /// probes are initiated.
228+ ///
229+ /// If a startup probe is defined, liveness and readiness probe delays do not begin until the
230+ /// startup probe has succeeded. If the value of periodSeconds is greater than
231+ /// `initialDelaySeconds` then the `initialDelaySeconds` will be ignored.
214232 pub fn with_initial_delay ( mut self , initial_delay : Duration ) -> Self {
215233 self . initial_delay = initial_delay;
216234 self
217235 }
218236
237+ /// Configure a grace period for the kubelet to wait between triggering a shut down of the
238+ /// failed container, and then forcing the container runtime to stop that container.
239+ ///
240+ /// The default (if this function is not called) is to inherit the Pod-level value for
241+ /// `terminationGracePeriodSeconds` (30 seconds if not specified), and the minimum value is
242+ /// 1 second. See probe-level `terminationGracePeriodSeconds` for more detail.
219243 pub fn with_termination_grace_period ( mut self , termination_grace_period : Duration ) -> Self {
220- self . termination_grace_period = termination_grace_period;
244+ self . termination_grace_period = Some ( termination_grace_period) ;
221245 self
222246 }
223247
@@ -263,14 +287,17 @@ impl ProbeBuilder<ProbeAction, Duration> {
263287 ) ?) ,
264288 success_threshold : Some ( self . success_threshold ) ,
265289 tcp_socket : None ,
266- termination_grace_period_seconds : Some (
267- self . termination_grace_period . as_secs ( ) . try_into ( ) . context (
268- DurationTooLongSnafu {
269- field : "terminationGracePeriod" ,
270- duration : self . termination_grace_period ,
271- } ,
272- ) ?,
273- ) ,
290+ termination_grace_period_seconds : match self . termination_grace_period {
291+ Some ( termination_grace_period) => {
292+ Some ( termination_grace_period. as_secs ( ) . try_into ( ) . context (
293+ DurationTooLongSnafu {
294+ field : "terminationGracePeriod" ,
295+ duration : termination_grace_period,
296+ } ,
297+ ) ?)
298+ }
299+ None => None ,
300+ } ,
274301 timeout_seconds : Some ( self . timeout . as_secs ( ) . try_into ( ) . context (
275302 DurationTooLongSnafu {
276303 field : "timeout" ,
@@ -302,13 +329,23 @@ mod tests {
302329 . expect ( "Valid inputs must produce a Probe" ) ;
303330
304331 assert_eq ! (
305- probe. http_get,
306- Some ( HTTPGetAction {
307- port: IntOrString :: Int ( 8080 ) ,
308- ..Default :: default ( )
309- } )
332+ probe,
333+ Probe {
334+ exec: None ,
335+ failure_threshold: Some ( 1 ) ,
336+ grpc: None ,
337+ http_get: Some ( HTTPGetAction {
338+ port: IntOrString :: Int ( 8080 ) ,
339+ ..Default :: default ( )
340+ } ) ,
341+ initial_delay_seconds: Some ( 0 ) ,
342+ period_seconds: Some ( 10 ) ,
343+ success_threshold: Some ( 1 ) ,
344+ tcp_socket: None ,
345+ termination_grace_period_seconds: None ,
346+ timeout_seconds: Some ( 1 ) ,
347+ }
310348 ) ;
311- assert_eq ! ( probe. period_seconds, Some ( 10 ) ) ;
312349 }
313350
314351 #[ test]
0 commit comments