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

    1// Generated from definition io.k8s.api.core.v1.ContainerStateTerminated
    2
    3/// ContainerStateTerminated is a terminated state of a container.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct ContainerStateTerminated {
    6    /// Container's ID in the format '\<type\>://\<container_id\>'
    7    pub container_id: Option<std::string::String>,
    8
    9    /// Exit status from the last termination of the container
    10    pub exit_code: i32,
    11
    12    /// Time at which the container last terminated
    13    pub finished_at: Option<crate::apimachinery::pkg::apis::meta::v1::Time>,
    14
    15    /// Message regarding the last termination of the container
    16    pub message: Option<std::string::String>,
    17
    18    /// (brief) reason from the last termination of the container
    19    pub reason: Option<std::string::String>,
    20
    21    /// Signal from the last termination of the container
    22    pub signal: Option<i32>,
    23
    24    /// Time at which previous execution of the container started
    25    pub started_at: Option<crate::apimachinery::pkg::apis::meta::v1::Time>,
    26}
    27
    28impl crate::DeepMerge for ContainerStateTerminated {
    29    fn merge_from(&mut self, other: Self) {
    30        crate::DeepMerge::merge_from(&mut self.container_id, other.container_id);
    31        crate::DeepMerge::merge_from(&mut self.exit_code, other.exit_code);
    32        crate::DeepMerge::merge_from(&mut self.finished_at, other.finished_at);
    33        crate::DeepMerge::merge_from(&mut self.message, other.message);
    34        crate::DeepMerge::merge_from(&mut self.reason, other.reason);
    35        crate::DeepMerge::merge_from(&mut self.signal, other.signal);
    36        crate::DeepMerge::merge_from(&mut self.started_at, other.started_at);
    37    }
    38}
    39
    40impl<'de> crate::serde::Deserialize<'de> for ContainerStateTerminated {
    41    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    42        #[allow(non_camel_case_types)]
    43        enum Field {
    44            Key_container_id,
    45            Key_exit_code,
    46            Key_finished_at,
    47            Key_message,
    48            Key_reason,
    49            Key_signal,
    50            Key_started_at,
    51            Other,
    52        }
    53
    54        impl<'de> crate::serde::Deserialize<'de> for Field {
    55            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    56                struct Visitor;
    57
    58                impl crate::serde::de::Visitor<'_> for Visitor {
    59                    type Value = Field;
    60
    61                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    62                        f.write_str("field identifier")
    63                    }
    64
    65                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    66                        Ok(match v {
    67                            "containerID" => Field::Key_container_id,
    68                            "exitCode" => Field::Key_exit_code,
    69                            "finishedAt" => Field::Key_finished_at,
    70                            "message" => Field::Key_message,
    71                            "reason" => Field::Key_reason,
    72                            "signal" => Field::Key_signal,
    73                            "startedAt" => Field::Key_started_at,
    74                            _ => Field::Other,
    75                        })
    76                    }
    77                }
    78
    79                deserializer.deserialize_identifier(Visitor)
    80            }
    81        }
    82
    83        struct Visitor;
    84
    85        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    86            type Value = ContainerStateTerminated;
    87
    88            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    89                f.write_str("ContainerStateTerminated")
    90            }
    91
    92            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    93                let mut value_container_id: Option<std::string::String> = None;
    94                let mut value_exit_code: Option<i32> = None;
    95                let mut value_finished_at: Option<crate::apimachinery::pkg::apis::meta::v1::Time> = None;
    96                let mut value_message: Option<std::string::String> = None;
    97                let mut value_reason: Option<std::string::String> = None;
    98                let mut value_signal: Option<i32> = None;
    99                let mut value_started_at: Option<crate::apimachinery::pkg::apis::meta::v1::Time> = None;
    100
    101                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    102                    match key {
    103                        Field::Key_container_id => value_container_id = crate::serde::de::MapAccess::next_value(&mut map)?,
    104                        Field::Key_exit_code => value_exit_code = crate::serde::de::MapAccess::next_value(&mut map)?,
    105                        Field::Key_finished_at => value_finished_at = crate::serde::de::MapAccess::next_value(&mut map)?,
    106                        Field::Key_message => value_message = crate::serde::de::MapAccess::next_value(&mut map)?,
    107                        Field::Key_reason => value_reason = crate::serde::de::MapAccess::next_value(&mut map)?,
    108                        Field::Key_signal => value_signal = crate::serde::de::MapAccess::next_value(&mut map)?,
    109                        Field::Key_started_at => value_started_at = crate::serde::de::MapAccess::next_value(&mut map)?,
    110                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    111                    }
    112                }
    113
    114                Ok(ContainerStateTerminated {
    115                    container_id: value_container_id,
    116                    exit_code: value_exit_code.unwrap_or_default(),
    117                    finished_at: value_finished_at,
    118                    message: value_message,
    119                    reason: value_reason,
    120                    signal: value_signal,
    121                    started_at: value_started_at,
    122                })
    123            }
    124        }
    125
    126        deserializer.deserialize_struct(
    127            "ContainerStateTerminated",
    128            &[
    129                "containerID",
    130                "exitCode",
    131                "finishedAt",
    132                "message",
    133                "reason",
    134                "signal",
    135                "startedAt",
    136            ],
    137            Visitor,
    138        )
    139    }
    140}
    141
    142impl crate::serde::Serialize for ContainerStateTerminated {
    143    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    144        let mut state = serializer.serialize_struct(
    145            "ContainerStateTerminated",
    146            1 +
    147            self.container_id.as_ref().map_or(0, |_| 1) +
    148            self.finished_at.as_ref().map_or(0, |_| 1) +
    149            self.message.as_ref().map_or(0, |_| 1) +
    150            self.reason.as_ref().map_or(0, |_| 1) +
    151            self.signal.as_ref().map_or(0, |_| 1) +
    152            self.started_at.as_ref().map_or(0, |_| 1),
    153        )?;
    154        if let Some(value) = &self.container_id {
    155            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "containerID", value)?;
    156        }
    157        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "exitCode", &self.exit_code)?;
    158        if let Some(value) = &self.finished_at {
    159            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "finishedAt", value)?;
    160        }
    161        if let Some(value) = &self.message {
    162            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "message", value)?;
    163        }
    164        if let Some(value) = &self.reason {
    165            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "reason", value)?;
    166        }
    167        if let Some(value) = &self.signal {
    168            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "signal", value)?;
    169        }
    170        if let Some(value) = &self.started_at {
    171            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "startedAt", value)?;
    172        }
    173        crate::serde::ser::SerializeStruct::end(state)
    174    }
    175}
    176
    177#[cfg(feature = "schemars")]
    178impl crate::schemars::JsonSchema for ContainerStateTerminated {
    179    fn schema_name() -> std::borrow::Cow<'static, str> {
    180        "io.k8s.api.core.v1.ContainerStateTerminated".into()
    181    }
    182
    183    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    184        crate::schemars::json_schema!({
    185            "description": "ContainerStateTerminated is a terminated state of a container.",
    186            "type": "object",
    187            "properties": {
    188                "containerID": {
    189                    "description": "Container's ID in the format '<type>://<container_id>'",
    190                    "type": "string",
    191                },
    192                "exitCode": {
    193                    "description": "Exit status from the last termination of the container",
    194                    "type": "integer",
    195                    "format": "int32",
    196                },
    197                "finishedAt": ({
    198                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::Time>();
    199                    schema_obj.ensure_object().insert("description".into(), "Time at which the container last terminated".into());
    200                    schema_obj
    201                }),
    202                "message": {
    203                    "description": "Message regarding the last termination of the container",
    204                    "type": "string",
    205                },
    206                "reason": {
    207                    "description": "(brief) reason from the last termination of the container",
    208                    "type": "string",
    209                },
    210                "signal": {
    211                    "description": "Signal from the last termination of the container",
    212                    "type": "integer",
    213                    "format": "int32",
    214                },
    215                "startedAt": ({
    216                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::Time>();
    217                    schema_obj.ensure_object().insert("description".into(), "Time at which previous execution of the container started".into());
    218                    schema_obj
    219                }),
    220            },
    221            "required": [
    222                "exitCode",
    223            ],
    224        })
    225    }
    226}