#
k8s_openapi/v1_35/api/core/v1/
lifecycle.rs

    1// Generated from definition io.k8s.api.core.v1.Lifecycle
    2
    3/// Lifecycle describes actions that the management system should take in response to container lifecycle events. For the PostStart and PreStop lifecycle handlers, management of the container blocks until the action is complete, unless the container process fails, in which case the handler is aborted.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct Lifecycle {
    6    /// PostStart is called immediately after a container is created. If the handler fails, the container is terminated and restarted according to its restart policy. Other management of the container blocks until the hook completes. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks
    7    pub post_start: Option<crate::api::core::v1::LifecycleHandler>,
    8
    9    /// PreStop is called immediately before a container is terminated due to an API request or management event such as liveness/startup probe failure, preemption, resource contention, etc. The handler is not called if the container crashes or exits. The Pod's termination grace period countdown begins before the PreStop hook is executed. Regardless of the outcome of the handler, the container will eventually terminate within the Pod's termination grace period (unless delayed by finalizers). Other management of the container blocks until the hook completes or until the termination grace period is reached. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks
    10    pub pre_stop: Option<crate::api::core::v1::LifecycleHandler>,
    11
    12    /// StopSignal defines which signal will be sent to a container when it is being stopped. If not specified, the default is defined by the container runtime in use. StopSignal can only be set for Pods with a non-empty .spec.os.name
    13    pub stop_signal: Option<std::string::String>,
    14}
    15
    16impl crate::DeepMerge for Lifecycle {
    17    fn merge_from(&mut self, other: Self) {
    18        crate::DeepMerge::merge_from(&mut self.post_start, other.post_start);
    19        crate::DeepMerge::merge_from(&mut self.pre_stop, other.pre_stop);
    20        crate::DeepMerge::merge_from(&mut self.stop_signal, other.stop_signal);
    21    }
    22}
    23
    24impl<'de> crate::serde::Deserialize<'de> for Lifecycle {
    25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    26        #[allow(non_camel_case_types)]
    27        enum Field {
    28            Key_post_start,
    29            Key_pre_stop,
    30            Key_stop_signal,
    31            Other,
    32        }
    33
    34        impl<'de> crate::serde::Deserialize<'de> for Field {
    35            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    36                struct Visitor;
    37
    38                impl crate::serde::de::Visitor<'_> for Visitor {
    39                    type Value = Field;
    40
    41                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    42                        f.write_str("field identifier")
    43                    }
    44
    45                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    46                        Ok(match v {
    47                            "postStart" => Field::Key_post_start,
    48                            "preStop" => Field::Key_pre_stop,
    49                            "stopSignal" => Field::Key_stop_signal,
    50                            _ => Field::Other,
    51                        })
    52                    }
    53                }
    54
    55                deserializer.deserialize_identifier(Visitor)
    56            }
    57        }
    58
    59        struct Visitor;
    60
    61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    62            type Value = Lifecycle;
    63
    64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    65                f.write_str("Lifecycle")
    66            }
    67
    68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    69                let mut value_post_start: Option<crate::api::core::v1::LifecycleHandler> = None;
    70                let mut value_pre_stop: Option<crate::api::core::v1::LifecycleHandler> = None;
    71                let mut value_stop_signal: Option<std::string::String> = None;
    72
    73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    74                    match key {
    75                        Field::Key_post_start => value_post_start = crate::serde::de::MapAccess::next_value(&mut map)?,
    76                        Field::Key_pre_stop => value_pre_stop = crate::serde::de::MapAccess::next_value(&mut map)?,
    77                        Field::Key_stop_signal => value_stop_signal = crate::serde::de::MapAccess::next_value(&mut map)?,
    78                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    79                    }
    80                }
    81
    82                Ok(Lifecycle {
    83                    post_start: value_post_start,
    84                    pre_stop: value_pre_stop,
    85                    stop_signal: value_stop_signal,
    86                })
    87            }
    88        }
    89
    90        deserializer.deserialize_struct(
    91            "Lifecycle",
    92            &[
    93                "postStart",
    94                "preStop",
    95                "stopSignal",
    96            ],
    97            Visitor,
    98        )
    99    }
    100}
    101
    102impl crate::serde::Serialize for Lifecycle {
    103    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    104        let mut state = serializer.serialize_struct(
    105            "Lifecycle",
    106            self.post_start.as_ref().map_or(0, |_| 1) +
    107            self.pre_stop.as_ref().map_or(0, |_| 1) +
    108            self.stop_signal.as_ref().map_or(0, |_| 1),
    109        )?;
    110        if let Some(value) = &self.post_start {
    111            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "postStart", value)?;
    112        }
    113        if let Some(value) = &self.pre_stop {
    114            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "preStop", value)?;
    115        }
    116        if let Some(value) = &self.stop_signal {
    117            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "stopSignal", value)?;
    118        }
    119        crate::serde::ser::SerializeStruct::end(state)
    120    }
    121}
    122
    123#[cfg(feature = "schemars")]
    124impl crate::schemars::JsonSchema for Lifecycle {
    125    fn schema_name() -> std::borrow::Cow<'static, str> {
    126        "io.k8s.api.core.v1.Lifecycle".into()
    127    }
    128
    129    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    130        crate::schemars::json_schema!({
    131            "description": "Lifecycle describes actions that the management system should take in response to container lifecycle events. For the PostStart and PreStop lifecycle handlers, management of the container blocks until the action is complete, unless the container process fails, in which case the handler is aborted.",
    132            "type": "object",
    133            "properties": {
    134                "postStart": ({
    135                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::LifecycleHandler>();
    136                    schema_obj.ensure_object().insert("description".into(), "PostStart is called immediately after a container is created. If the handler fails, the container is terminated and restarted according to its restart policy. Other management of the container blocks until the hook completes. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks".into());
    137                    schema_obj
    138                }),
    139                "preStop": ({
    140                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::LifecycleHandler>();
    141                    schema_obj.ensure_object().insert("description".into(), "PreStop is called immediately before a container is terminated due to an API request or management event such as liveness/startup probe failure, preemption, resource contention, etc. The handler is not called if the container crashes or exits. The Pod's termination grace period countdown begins before the PreStop hook is executed. Regardless of the outcome of the handler, the container will eventually terminate within the Pod's termination grace period (unless delayed by finalizers). Other management of the container blocks until the hook completes or until the termination grace period is reached. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks".into());
    142                    schema_obj
    143                }),
    144                "stopSignal": {
    145                    "description": "StopSignal defines which signal will be sent to a container when it is being stopped. If not specified, the default is defined by the container runtime in use. StopSignal can only be set for Pods with a non-empty .spec.os.name",
    146                    "type": "string",
    147                },
    148            },
    149        })
    150    }
    151}