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

    1// Generated from definition io.k8s.api.core.v1.ResourceStatus
    2
    3/// ResourceStatus represents the status of a single resource allocated to a Pod.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct ResourceStatus {
    6    /// Name of the resource. Must be unique within the pod and in case of non-DRA resource, match one of the resources from the pod spec. For DRA resources, the value must be "claim:\<claim_name\>/\<request\>". When this status is reported about a container, the "claim_name" and "request" must match one of the claims of this container.
    7    pub name: std::string::String,
    8
    9    /// List of unique resources health. Each element in the list contains an unique resource ID and its health. At a minimum, for the lifetime of a Pod, resource ID must uniquely identify the resource allocated to the Pod on the Node. If other Pod on the same Node reports the status with the same resource ID, it must be the same resource they share. See ResourceID type definition for a specific format it has in various use cases.
    10    pub resources: Option<std::vec::Vec<crate::api::core::v1::ResourceHealth>>,
    11}
    12
    13impl crate::DeepMerge for ResourceStatus {
    14    fn merge_from(&mut self, other: Self) {
    15        crate::DeepMerge::merge_from(&mut self.name, other.name);
    16        crate::merge_strategies::list::map(
    17            &mut self.resources,
    18            other.resources,
    19            &[|lhs, rhs| lhs.resource_id == rhs.resource_id],
    20            |current_item, other_item| {
    21                crate::DeepMerge::merge_from(current_item, other_item);
    22            },
    23        );
    24    }
    25}
    26
    27impl<'de> crate::serde::Deserialize<'de> for ResourceStatus {
    28    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    29        #[allow(non_camel_case_types)]
    30        enum Field {
    31            Key_name,
    32            Key_resources,
    33            Other,
    34        }
    35
    36        impl<'de> crate::serde::Deserialize<'de> for Field {
    37            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    38                struct Visitor;
    39
    40                impl crate::serde::de::Visitor<'_> for Visitor {
    41                    type Value = Field;
    42
    43                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    44                        f.write_str("field identifier")
    45                    }
    46
    47                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    48                        Ok(match v {
    49                            "name" => Field::Key_name,
    50                            "resources" => Field::Key_resources,
    51                            _ => Field::Other,
    52                        })
    53                    }
    54                }
    55
    56                deserializer.deserialize_identifier(Visitor)
    57            }
    58        }
    59
    60        struct Visitor;
    61
    62        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    63            type Value = ResourceStatus;
    64
    65            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    66                f.write_str("ResourceStatus")
    67            }
    68
    69            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    70                let mut value_name: Option<std::string::String> = None;
    71                let mut value_resources: Option<std::vec::Vec<crate::api::core::v1::ResourceHealth>> = None;
    72
    73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    74                    match key {
    75                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
    76                        Field::Key_resources => value_resources = crate::serde::de::MapAccess::next_value(&mut map)?,
    77                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    78                    }
    79                }
    80
    81                Ok(ResourceStatus {
    82                    name: value_name.unwrap_or_default(),
    83                    resources: value_resources,
    84                })
    85            }
    86        }
    87
    88        deserializer.deserialize_struct(
    89            "ResourceStatus",
    90            &[
    91                "name",
    92                "resources",
    93            ],
    94            Visitor,
    95        )
    96    }
    97}
    98
    99impl crate::serde::Serialize for ResourceStatus {
    100    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    101        let mut state = serializer.serialize_struct(
    102            "ResourceStatus",
    103            1 +
    104            self.resources.as_ref().map_or(0, |_| 1),
    105        )?;
    106        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
    107        if let Some(value) = &self.resources {
    108            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resources", value)?;
    109        }
    110        crate::serde::ser::SerializeStruct::end(state)
    111    }
    112}
    113
    114#[cfg(feature = "schemars")]
    115impl crate::schemars::JsonSchema for ResourceStatus {
    116    fn schema_name() -> std::borrow::Cow<'static, str> {
    117        "io.k8s.api.core.v1.ResourceStatus".into()
    118    }
    119
    120    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    121        crate::schemars::json_schema!({
    122            "description": "ResourceStatus represents the status of a single resource allocated to a Pod.",
    123            "type": "object",
    124            "properties": {
    125                "name": {
    126                    "description": "Name of the resource. Must be unique within the pod and in case of non-DRA resource, match one of the resources from the pod spec. For DRA resources, the value must be \"claim:<claim_name>/<request>\". When this status is reported about a container, the \"claim_name\" and \"request\" must match one of the claims of this container.",
    127                    "type": "string",
    128                },
    129                "resources": {
    130                    "description": "List of unique resources health. Each element in the list contains an unique resource ID and its health. At a minimum, for the lifetime of a Pod, resource ID must uniquely identify the resource allocated to the Pod on the Node. If other Pod on the same Node reports the status with the same resource ID, it must be the same resource they share. See ResourceID type definition for a specific format it has in various use cases.",
    131                    "type": "array",
    132                    "items": (__gen.subschema_for::<crate::api::core::v1::ResourceHealth>()),
    133                },
    134            },
    135            "required": [
    136                "name",
    137            ],
    138        })
    139    }
    140}