k8s_openapi_ext/ext/
probe.rs

1use std::path::Path;
2
3use super::*;
4
5/// Builders for `corev1::Probe` objects
6pub trait ProbeExt {
7    /// HTTP get probe
8    fn http_get(path: impl AsRef<Path>, port: impl ToIntOrString) -> Self;
9
10    /// TCPSocket specifies an action involving a TCP port. TCP hooks not yet supported
11    fn tcp_socket(port: impl ToIntOrString) -> Self;
12
13    /// gRPC probe
14    ///
15    fn grpc<'a>(port: i32, service: impl Into<Option<&'a str>>) -> Self;
16
17    /// Minimum consecutive failures for the probe to be considered failed after having succeeded.
18    /// Defaults to 3. Minimum value is 1.
19    ///
20    fn failure_threshold(self, threshold: i32) -> Self;
21
22    /// Minimum consecutive successes for the probe to be considered successful after having failed.
23    /// Defaults to 1. Must be 1 for liveness and startup. Minimum value is 1.
24    ///
25    fn success_threshold(self, threshold: i32) -> Self;
26
27    fn initial_delay_seconds(self, seconds: i32) -> Self;
28
29    fn period_seconds(self, seconds: i32) -> Self;
30
31    fn timeout_seconds(self, seconds: i32) -> Self;
32
33    fn termination_grace_period_seconds(self, seconds: i64) -> Self;
34}
35
36impl ProbeExt for corev1::Probe {
37    fn http_get(path: impl AsRef<Path>, port: impl ToIntOrString) -> Self {
38        let path = Some(path.as_ref().display().to_string());
39        let port = port.to_int_or_string();
40        let scheme = Some("HTTP".to_string());
41        let http_get = Some(corev1::HTTPGetAction {
42            path,
43            port,
44            scheme,
45            // host: todo!(),
46            // http_headers: todo!(),
47            ..default()
48        });
49        Self {
50            http_get,
51            // exec: todo!(),
52            // failure_threshold: todo!(),
53            // initial_delay_seconds: todo!(),
54            // period_seconds: todo!(),
55            // success_threshold: todo!(),
56            // tcp_socket: todo!(),
57            // termination_grace_period_seconds: todo!(),
58            // timeout_seconds: todo!(),
59            ..default()
60        }
61    }
62
63    fn tcp_socket(port: impl ToIntOrString) -> Self {
64        let port = port.to_int_or_string();
65        let tcp_socket = Some(corev1::TCPSocketAction {
66            port,
67            // host: todo!(),
68            ..default()
69        });
70        Self {
71            tcp_socket,
72            // exec: todo!(),
73            // failure_threshold: todo!(),
74            // grpc: todo!(),
75            // http_get: todo!(),
76            // initial_delay_seconds: todo!(),
77            // period_seconds: todo!(),
78            // success_threshold: todo!(),
79            // termination_grace_period_seconds: todo!(),
80            // timeout_seconds: todo!(),
81            ..default()
82        }
83    }
84
85    fn grpc<'a>(port: i32, service: impl Into<Option<&'a str>>) -> Self {
86        let service = service.into().map(|service| service.to_string());
87        let grpc = Some(corev1::GRPCAction { port, service });
88        Self {
89            grpc,
90            // exec: todo!(),
91            // failure_threshold: todo!(),
92            // http_get: todo!(),
93            // initial_delay_seconds: todo!(),
94            // period_seconds: todo!(),
95            // success_threshold: todo!(),
96            // tcp_socket: todo!(),
97            // termination_grace_period_seconds: todo!(),
98            // timeout_seconds: todo!(),
99            ..default()
100        }
101    }
102
103    fn failure_threshold(mut self, threshold: i32) -> Self {
104        self.failure_threshold = Some(threshold);
105        self
106    }
107
108    fn success_threshold(mut self, threshold: i32) -> Self {
109        self.success_threshold = Some(threshold);
110        self
111    }
112
113    fn initial_delay_seconds(mut self, seconds: i32) -> Self {
114        self.initial_delay_seconds = Some(seconds);
115        self
116    }
117
118    fn period_seconds(mut self, seconds: i32) -> Self {
119        self.period_seconds = Some(seconds);
120        self
121    }
122
123    fn timeout_seconds(mut self, seconds: i32) -> Self {
124        self.timeout_seconds = Some(seconds);
125        self
126    }
127
128    fn termination_grace_period_seconds(mut self, seconds: i64) -> Self {
129        self.termination_grace_period_seconds = Some(seconds);
130        self
131    }
132}