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 http_get = Some(corev1::HTTPGetAction {
41 path,
42 port,
43 ..default()
47 });
48 Self {
49 http_get,
50 ..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 ..default()
68 });
69 Self {
70 tcp_socket,
71 ..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 ..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}