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