k8s_openapi/v1_30/api/core/v1/
lifecycle_handler.rs

1// Generated from definition io.k8s.api.core.v1.LifecycleHandler
2
3/// LifecycleHandler defines a specific action that should be taken in a lifecycle hook. One and only one of the fields, except TCPSocket must be specified.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct LifecycleHandler {
6    /// Exec specifies the action to take.
7    pub exec: Option<crate::api::core::v1::ExecAction>,
8
9    /// HTTPGet specifies the http request to perform.
10    pub http_get: Option<crate::api::core::v1::HTTPGetAction>,
11
12    /// Sleep represents the duration that the container should sleep before being terminated.
13    pub sleep: Option<crate::api::core::v1::SleepAction>,
14
15    /// Deprecated. TCPSocket is NOT supported as a LifecycleHandler and kept for the backward compatibility. There are no validation of this field and lifecycle hooks will fail in runtime when tcp handler is specified.
16    pub tcp_socket: Option<crate::api::core::v1::TCPSocketAction>,
17}
18
19impl crate::DeepMerge for LifecycleHandler {
20    fn merge_from(&mut self, other: Self) {
21        crate::DeepMerge::merge_from(&mut self.exec, other.exec);
22        crate::DeepMerge::merge_from(&mut self.http_get, other.http_get);
23        crate::DeepMerge::merge_from(&mut self.sleep, other.sleep);
24        crate::DeepMerge::merge_from(&mut self.tcp_socket, other.tcp_socket);
25    }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for LifecycleHandler {
29    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
30        #[allow(non_camel_case_types)]
31        enum Field {
32            Key_exec,
33            Key_http_get,
34            Key_sleep,
35            Key_tcp_socket,
36            Other,
37        }
38
39        impl<'de> crate::serde::Deserialize<'de> for Field {
40            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
41                struct Visitor;
42
43                impl crate::serde::de::Visitor<'_> for Visitor {
44                    type Value = Field;
45
46                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
47                        f.write_str("field identifier")
48                    }
49
50                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
51                        Ok(match v {
52                            "exec" => Field::Key_exec,
53                            "httpGet" => Field::Key_http_get,
54                            "sleep" => Field::Key_sleep,
55                            "tcpSocket" => Field::Key_tcp_socket,
56                            _ => Field::Other,
57                        })
58                    }
59                }
60
61                deserializer.deserialize_identifier(Visitor)
62            }
63        }
64
65        struct Visitor;
66
67        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
68            type Value = LifecycleHandler;
69
70            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71                f.write_str("LifecycleHandler")
72            }
73
74            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
75                let mut value_exec: Option<crate::api::core::v1::ExecAction> = None;
76                let mut value_http_get: Option<crate::api::core::v1::HTTPGetAction> = None;
77                let mut value_sleep: Option<crate::api::core::v1::SleepAction> = None;
78                let mut value_tcp_socket: Option<crate::api::core::v1::TCPSocketAction> = None;
79
80                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
81                    match key {
82                        Field::Key_exec => value_exec = crate::serde::de::MapAccess::next_value(&mut map)?,
83                        Field::Key_http_get => value_http_get = crate::serde::de::MapAccess::next_value(&mut map)?,
84                        Field::Key_sleep => value_sleep = crate::serde::de::MapAccess::next_value(&mut map)?,
85                        Field::Key_tcp_socket => value_tcp_socket = crate::serde::de::MapAccess::next_value(&mut map)?,
86                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
87                    }
88                }
89
90                Ok(LifecycleHandler {
91                    exec: value_exec,
92                    http_get: value_http_get,
93                    sleep: value_sleep,
94                    tcp_socket: value_tcp_socket,
95                })
96            }
97        }
98
99        deserializer.deserialize_struct(
100            "LifecycleHandler",
101            &[
102                "exec",
103                "httpGet",
104                "sleep",
105                "tcpSocket",
106            ],
107            Visitor,
108        )
109    }
110}
111
112impl crate::serde::Serialize for LifecycleHandler {
113    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
114        let mut state = serializer.serialize_struct(
115            "LifecycleHandler",
116            self.exec.as_ref().map_or(0, |_| 1) +
117            self.http_get.as_ref().map_or(0, |_| 1) +
118            self.sleep.as_ref().map_or(0, |_| 1) +
119            self.tcp_socket.as_ref().map_or(0, |_| 1),
120        )?;
121        if let Some(value) = &self.exec {
122            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "exec", value)?;
123        }
124        if let Some(value) = &self.http_get {
125            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "httpGet", value)?;
126        }
127        if let Some(value) = &self.sleep {
128            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "sleep", value)?;
129        }
130        if let Some(value) = &self.tcp_socket {
131            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "tcpSocket", value)?;
132        }
133        crate::serde::ser::SerializeStruct::end(state)
134    }
135}
136
137#[cfg(feature = "schemars")]
138impl crate::schemars::JsonSchema for LifecycleHandler {
139    fn schema_name() -> std::borrow::Cow<'static, str> {
140        "io.k8s.api.core.v1.LifecycleHandler".into()
141    }
142
143    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
144        crate::schemars::json_schema!({
145            "description": "LifecycleHandler defines a specific action that should be taken in a lifecycle hook. One and only one of the fields, except TCPSocket must be specified.",
146            "type": "object",
147            "properties": {
148                "exec": ({
149                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ExecAction>();
150                    schema_obj.ensure_object().insert("description".into(), "Exec specifies the action to take.".into());
151                    schema_obj
152                }),
153                "httpGet": ({
154                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::HTTPGetAction>();
155                    schema_obj.ensure_object().insert("description".into(), "HTTPGet specifies the http request to perform.".into());
156                    schema_obj
157                }),
158                "sleep": ({
159                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::SleepAction>();
160                    schema_obj.ensure_object().insert("description".into(), "Sleep represents the duration that the container should sleep before being terminated.".into());
161                    schema_obj
162                }),
163                "tcpSocket": ({
164                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::TCPSocketAction>();
165                    schema_obj.ensure_object().insert("description".into(), "Deprecated. TCPSocket is NOT supported as a LifecycleHandler and kept for the backward compatibility. There are no validation of this field and lifecycle hooks will fail in runtime when tcp handler is specified.".into());
166                    schema_obj
167                }),
168            },
169        })
170    }
171}