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 http_get = Some(corev1::HTTPGetAction {
41            path,
42            port,
43            // host: todo!(),
44            // http_headers: todo!(),
45            // scheme: todo!(),
46            ..default()
47        });
48        Self {
49            http_get,
50            // exec: todo!(),
51            // failure_threshold: todo!(),
52            // initial_delay_seconds: todo!(),
53            // period_seconds: todo!(),
54            // success_threshold: todo!(),
55            // tcp_socket: todo!(),
56            // termination_grace_period_seconds: todo!(),
57            // timeout_seconds: todo!(),
58            ..default()
59        }
60    }
61
62    fn tcp_socket(port: impl ToIntOrString) -> Self {
63        let port = port.to_int_or_string();
64        let tcp_socket = Some(corev1::TCPSocketAction {
65            port,
66            // host: todo!(),
67            ..default()
68        });
69        Self {
70            tcp_socket,
71            // exec: todo!(),
72            // failure_threshold: todo!(),
73            // grpc: todo!(),
74            // http_get: todo!(),
75            // initial_delay_seconds: todo!(),
76            // period_seconds: todo!(),
77            // success_threshold: todo!(),
78            // termination_grace_period_seconds: todo!(),
79            // timeout_seconds: todo!(),
80            ..default()
81        }
82    }
83
84    fn grpc<'a>(port: i32, service: impl Into<Option<&'a str>>) -> Self {
85        let service = service.into().map(|service| service.to_string());
86        let grpc = Some(corev1::GRPCAction { port, service });
87        Self {
88            grpc,
89            // exec: todo!(),
90            // failure_threshold: todo!(),
91            // http_get: todo!(),
92            // initial_delay_seconds: todo!(),
93            // period_seconds: todo!(),
94            // success_threshold: todo!(),
95            // tcp_socket: todo!(),
96            // termination_grace_period_seconds: todo!(),
97            // timeout_seconds: todo!(),
98            ..default()
99        }
100    }
101
102    fn failure_threshold(mut self, threshold: i32) -> Self {
103        self.failure_threshold = Some(threshold);
104        self
105    }
106
107    fn success_threshold(mut self, threshold: i32) -> Self {
108        self.success_threshold = Some(threshold);
109        self
110    }
111
112    fn initial_delay_seconds(mut self, seconds: i32) -> Self {
113        self.initial_delay_seconds = Some(seconds);
114        self
115    }
116
117    fn period_seconds(mut self, seconds: i32) -> Self {
118        self.period_seconds = Some(seconds);
119        self
120    }
121
122    fn timeout_seconds(mut self, seconds: i32) -> Self {
123        self.timeout_seconds = Some(seconds);
124        self
125    }
126
127    fn termination_grace_period_seconds(mut self, seconds: i64) -> Self {
128        self.termination_grace_period_seconds = Some(seconds);
129        self
130    }
131}