k8s_openapi_ext/ext/
probe.rs1use std::path::Path;
2
3use super::*;
4
5pub trait ProbeExt {
7 fn http_get(path: impl AsRef<Path>, port: impl ToIntOrString) -> Self;
9
10 fn tcp_socket(port: impl ToIntOrString) -> Self;
12
13 fn grpc<'a>(port: i32, service: impl Into<Option<&'a str>>) -> Self;
16
17 fn failure_threshold(self, threshold: i32) -> Self;
21
22 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 ..default()
48 });
49 Self {
50 http_get,
51 ..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 ..default()
69 });
70 Self {
71 tcp_socket,
72 ..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 ..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}