k8s_openapi/v1_34/api/core/v1/
probe.rs

1// Generated from definition io.k8s.api.core.v1.Probe
2
3/// Probe describes a health check to be performed against a container to determine whether it is alive or ready to receive traffic.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct Probe {
6    /// Exec specifies a command to execute in the container.
7    pub exec: Option<crate::api::core::v1::ExecAction>,
8
9    /// Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to 3. Minimum value is 1.
10    pub failure_threshold: Option<i32>,
11
12    /// GRPC specifies a GRPC HealthCheckRequest.
13    pub grpc: Option<crate::api::core::v1::GRPCAction>,
14
15    /// HTTPGet specifies an HTTP GET request to perform.
16    pub http_get: Option<crate::api::core::v1::HTTPGetAction>,
17
18    /// Number of seconds after the container has started before liveness probes are initiated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
19    pub initial_delay_seconds: Option<i32>,
20
21    /// How often (in seconds) to perform the probe. Default to 10 seconds. Minimum value is 1.
22    pub period_seconds: Option<i32>,
23
24    /// Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to 1. Must be 1 for liveness and startup. Minimum value is 1.
25    pub success_threshold: Option<i32>,
26
27    /// TCPSocket specifies a connection to a TCP port.
28    pub tcp_socket: Option<crate::api::core::v1::TCPSocketAction>,
29
30    /// Optional duration in seconds the pod needs to terminate gracefully upon probe failure. The grace period is the duration in seconds after the processes running in the pod are sent a termination signal and the time when the processes are forcibly halted with a kill signal. Set this value longer than the expected cleanup time for your process. If this value is nil, the pod's terminationGracePeriodSeconds will be used. Otherwise, this value overrides the value provided by the pod spec. Value must be non-negative integer. The value zero indicates stop immediately via the kill signal (no opportunity to shut down). This is a beta field and requires enabling ProbeTerminationGracePeriod feature gate. Minimum value is 1. spec.terminationGracePeriodSeconds is used if unset.
31    pub termination_grace_period_seconds: Option<i64>,
32
33    /// Number of seconds after which the probe times out. Defaults to 1 second. Minimum value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
34    pub timeout_seconds: Option<i32>,
35}
36
37impl crate::DeepMerge for Probe {
38    fn merge_from(&mut self, other: Self) {
39        crate::DeepMerge::merge_from(&mut self.exec, other.exec);
40        crate::DeepMerge::merge_from(&mut self.failure_threshold, other.failure_threshold);
41        crate::DeepMerge::merge_from(&mut self.grpc, other.grpc);
42        crate::DeepMerge::merge_from(&mut self.http_get, other.http_get);
43        crate::DeepMerge::merge_from(&mut self.initial_delay_seconds, other.initial_delay_seconds);
44        crate::DeepMerge::merge_from(&mut self.period_seconds, other.period_seconds);
45        crate::DeepMerge::merge_from(&mut self.success_threshold, other.success_threshold);
46        crate::DeepMerge::merge_from(&mut self.tcp_socket, other.tcp_socket);
47        crate::DeepMerge::merge_from(&mut self.termination_grace_period_seconds, other.termination_grace_period_seconds);
48        crate::DeepMerge::merge_from(&mut self.timeout_seconds, other.timeout_seconds);
49    }
50}
51
52impl<'de> crate::serde::Deserialize<'de> for Probe {
53    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
54        #[allow(non_camel_case_types)]
55        enum Field {
56            Key_exec,
57            Key_failure_threshold,
58            Key_grpc,
59            Key_http_get,
60            Key_initial_delay_seconds,
61            Key_period_seconds,
62            Key_success_threshold,
63            Key_tcp_socket,
64            Key_termination_grace_period_seconds,
65            Key_timeout_seconds,
66            Other,
67        }
68
69        impl<'de> crate::serde::Deserialize<'de> for Field {
70            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
71                struct Visitor;
72
73                impl crate::serde::de::Visitor<'_> for Visitor {
74                    type Value = Field;
75
76                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
77                        f.write_str("field identifier")
78                    }
79
80                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
81                        Ok(match v {
82                            "exec" => Field::Key_exec,
83                            "failureThreshold" => Field::Key_failure_threshold,
84                            "grpc" => Field::Key_grpc,
85                            "httpGet" => Field::Key_http_get,
86                            "initialDelaySeconds" => Field::Key_initial_delay_seconds,
87                            "periodSeconds" => Field::Key_period_seconds,
88                            "successThreshold" => Field::Key_success_threshold,
89                            "tcpSocket" => Field::Key_tcp_socket,
90                            "terminationGracePeriodSeconds" => Field::Key_termination_grace_period_seconds,
91                            "timeoutSeconds" => Field::Key_timeout_seconds,
92                            _ => Field::Other,
93                        })
94                    }
95                }
96
97                deserializer.deserialize_identifier(Visitor)
98            }
99        }
100
101        struct Visitor;
102
103        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
104            type Value = Probe;
105
106            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
107                f.write_str("Probe")
108            }
109
110            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
111                let mut value_exec: Option<crate::api::core::v1::ExecAction> = None;
112                let mut value_failure_threshold: Option<i32> = None;
113                let mut value_grpc: Option<crate::api::core::v1::GRPCAction> = None;
114                let mut value_http_get: Option<crate::api::core::v1::HTTPGetAction> = None;
115                let mut value_initial_delay_seconds: Option<i32> = None;
116                let mut value_period_seconds: Option<i32> = None;
117                let mut value_success_threshold: Option<i32> = None;
118                let mut value_tcp_socket: Option<crate::api::core::v1::TCPSocketAction> = None;
119                let mut value_termination_grace_period_seconds: Option<i64> = None;
120                let mut value_timeout_seconds: Option<i32> = None;
121
122                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
123                    match key {
124                        Field::Key_exec => value_exec = crate::serde::de::MapAccess::next_value(&mut map)?,
125                        Field::Key_failure_threshold => value_failure_threshold = crate::serde::de::MapAccess::next_value(&mut map)?,
126                        Field::Key_grpc => value_grpc = crate::serde::de::MapAccess::next_value(&mut map)?,
127                        Field::Key_http_get => value_http_get = crate::serde::de::MapAccess::next_value(&mut map)?,
128                        Field::Key_initial_delay_seconds => value_initial_delay_seconds = crate::serde::de::MapAccess::next_value(&mut map)?,
129                        Field::Key_period_seconds => value_period_seconds = crate::serde::de::MapAccess::next_value(&mut map)?,
130                        Field::Key_success_threshold => value_success_threshold = crate::serde::de::MapAccess::next_value(&mut map)?,
131                        Field::Key_tcp_socket => value_tcp_socket = crate::serde::de::MapAccess::next_value(&mut map)?,
132                        Field::Key_termination_grace_period_seconds => value_termination_grace_period_seconds = crate::serde::de::MapAccess::next_value(&mut map)?,
133                        Field::Key_timeout_seconds => value_timeout_seconds = crate::serde::de::MapAccess::next_value(&mut map)?,
134                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
135                    }
136                }
137
138                Ok(Probe {
139                    exec: value_exec,
140                    failure_threshold: value_failure_threshold,
141                    grpc: value_grpc,
142                    http_get: value_http_get,
143                    initial_delay_seconds: value_initial_delay_seconds,
144                    period_seconds: value_period_seconds,
145                    success_threshold: value_success_threshold,
146                    tcp_socket: value_tcp_socket,
147                    termination_grace_period_seconds: value_termination_grace_period_seconds,
148                    timeout_seconds: value_timeout_seconds,
149                })
150            }
151        }
152
153        deserializer.deserialize_struct(
154            "Probe",
155            &[
156                "exec",
157                "failureThreshold",
158                "grpc",
159                "httpGet",
160                "initialDelaySeconds",
161                "periodSeconds",
162                "successThreshold",
163                "tcpSocket",
164                "terminationGracePeriodSeconds",
165                "timeoutSeconds",
166            ],
167            Visitor,
168        )
169    }
170}
171
172impl crate::serde::Serialize for Probe {
173    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
174        let mut state = serializer.serialize_struct(
175            "Probe",
176            self.exec.as_ref().map_or(0, |_| 1) +
177            self.failure_threshold.as_ref().map_or(0, |_| 1) +
178            self.grpc.as_ref().map_or(0, |_| 1) +
179            self.http_get.as_ref().map_or(0, |_| 1) +
180            self.initial_delay_seconds.as_ref().map_or(0, |_| 1) +
181            self.period_seconds.as_ref().map_or(0, |_| 1) +
182            self.success_threshold.as_ref().map_or(0, |_| 1) +
183            self.tcp_socket.as_ref().map_or(0, |_| 1) +
184            self.termination_grace_period_seconds.as_ref().map_or(0, |_| 1) +
185            self.timeout_seconds.as_ref().map_or(0, |_| 1),
186        )?;
187        if let Some(value) = &self.exec {
188            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "exec", value)?;
189        }
190        if let Some(value) = &self.failure_threshold {
191            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "failureThreshold", value)?;
192        }
193        if let Some(value) = &self.grpc {
194            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "grpc", value)?;
195        }
196        if let Some(value) = &self.http_get {
197            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "httpGet", value)?;
198        }
199        if let Some(value) = &self.initial_delay_seconds {
200            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "initialDelaySeconds", value)?;
201        }
202        if let Some(value) = &self.period_seconds {
203            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "periodSeconds", value)?;
204        }
205        if let Some(value) = &self.success_threshold {
206            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "successThreshold", value)?;
207        }
208        if let Some(value) = &self.tcp_socket {
209            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "tcpSocket", value)?;
210        }
211        if let Some(value) = &self.termination_grace_period_seconds {
212            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "terminationGracePeriodSeconds", value)?;
213        }
214        if let Some(value) = &self.timeout_seconds {
215            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "timeoutSeconds", value)?;
216        }
217        crate::serde::ser::SerializeStruct::end(state)
218    }
219}
220
221#[cfg(feature = "schemars")]
222impl crate::schemars::JsonSchema for Probe {
223    fn schema_name() -> std::borrow::Cow<'static, str> {
224        "io.k8s.api.core.v1.Probe".into()
225    }
226
227    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
228        crate::schemars::json_schema!({
229            "description": "Probe describes a health check to be performed against a container to determine whether it is alive or ready to receive traffic.",
230            "type": "object",
231            "properties": {
232                "exec": ({
233                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ExecAction>();
234                    schema_obj.ensure_object().insert("description".into(), "Exec specifies a command to execute in the container.".into());
235                    schema_obj
236                }),
237                "failureThreshold": {
238                    "description": "Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to 3. Minimum value is 1.",
239                    "type": "integer",
240                    "format": "int32",
241                },
242                "grpc": ({
243                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::GRPCAction>();
244                    schema_obj.ensure_object().insert("description".into(), "GRPC specifies a GRPC HealthCheckRequest.".into());
245                    schema_obj
246                }),
247                "httpGet": ({
248                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::HTTPGetAction>();
249                    schema_obj.ensure_object().insert("description".into(), "HTTPGet specifies an HTTP GET request to perform.".into());
250                    schema_obj
251                }),
252                "initialDelaySeconds": {
253                    "description": "Number of seconds after the container has started before liveness probes are initiated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes",
254                    "type": "integer",
255                    "format": "int32",
256                },
257                "periodSeconds": {
258                    "description": "How often (in seconds) to perform the probe. Default to 10 seconds. Minimum value is 1.",
259                    "type": "integer",
260                    "format": "int32",
261                },
262                "successThreshold": {
263                    "description": "Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to 1. Must be 1 for liveness and startup. Minimum value is 1.",
264                    "type": "integer",
265                    "format": "int32",
266                },
267                "tcpSocket": ({
268                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::TCPSocketAction>();
269                    schema_obj.ensure_object().insert("description".into(), "TCPSocket specifies a connection to a TCP port.".into());
270                    schema_obj
271                }),
272                "terminationGracePeriodSeconds": {
273                    "description": "Optional duration in seconds the pod needs to terminate gracefully upon probe failure. The grace period is the duration in seconds after the processes running in the pod are sent a termination signal and the time when the processes are forcibly halted with a kill signal. Set this value longer than the expected cleanup time for your process. If this value is nil, the pod's terminationGracePeriodSeconds will be used. Otherwise, this value overrides the value provided by the pod spec. Value must be non-negative integer. The value zero indicates stop immediately via the kill signal (no opportunity to shut down). This is a beta field and requires enabling ProbeTerminationGracePeriod feature gate. Minimum value is 1. spec.terminationGracePeriodSeconds is used if unset.",
274                    "type": "integer",
275                    "format": "int64",
276                },
277                "timeoutSeconds": {
278                    "description": "Number of seconds after which the probe times out. Defaults to 1 second. Minimum value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes",
279                    "type": "integer",
280                    "format": "int32",
281                },
282            },
283        })
284    }
285}