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

    1// Generated from definition io.k8s.api.core.v1.ResourceRequirements
    2
    3/// ResourceRequirements describes the compute resource requirements.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct ResourceRequirements {
    6    /// Claims lists the names of resources, defined in spec.resourceClaims, that are used by this container.
    7    ///
    8    /// This field depends on the DynamicResourceAllocation feature gate.
    9    ///
    10    /// This field is immutable. It can only be set for containers.
    11    pub claims: Option<std::vec::Vec<crate::api::core::v1::ResourceClaim>>,
    12
    13    /// Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
    14    pub limits: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>>,
    15
    16    /// Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. Requests cannot exceed Limits. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
    17    pub requests: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>>,
    18}
    19
    20impl crate::DeepMerge for ResourceRequirements {
    21    fn merge_from(&mut self, other: Self) {
    22        crate::merge_strategies::list::map(
    23            &mut self.claims,
    24            other.claims,
    25            &[|lhs, rhs| lhs.name == rhs.name],
    26            |current_item, other_item| {
    27                crate::DeepMerge::merge_from(current_item, other_item);
    28            },
    29        );
    30        crate::merge_strategies::map::granular(&mut self.limits, other.limits, |current_item, other_item| {
    31            crate::DeepMerge::merge_from(current_item, other_item);
    32        });
    33        crate::merge_strategies::map::granular(&mut self.requests, other.requests, |current_item, other_item| {
    34            crate::DeepMerge::merge_from(current_item, other_item);
    35        });
    36    }
    37}
    38
    39impl<'de> crate::serde::Deserialize<'de> for ResourceRequirements {
    40    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    41        #[allow(non_camel_case_types)]
    42        enum Field {
    43            Key_claims,
    44            Key_limits,
    45            Key_requests,
    46            Other,
    47        }
    48
    49        impl<'de> crate::serde::Deserialize<'de> for Field {
    50            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    51                struct Visitor;
    52
    53                impl crate::serde::de::Visitor<'_> for Visitor {
    54                    type Value = Field;
    55
    56                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    57                        f.write_str("field identifier")
    58                    }
    59
    60                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    61                        Ok(match v {
    62                            "claims" => Field::Key_claims,
    63                            "limits" => Field::Key_limits,
    64                            "requests" => Field::Key_requests,
    65                            _ => Field::Other,
    66                        })
    67                    }
    68                }
    69
    70                deserializer.deserialize_identifier(Visitor)
    71            }
    72        }
    73
    74        struct Visitor;
    75
    76        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    77            type Value = ResourceRequirements;
    78
    79            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    80                f.write_str("ResourceRequirements")
    81            }
    82
    83            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    84                let mut value_claims: Option<std::vec::Vec<crate::api::core::v1::ResourceClaim>> = None;
    85                let mut value_limits: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
    86                let mut value_requests: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
    87
    88                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    89                    match key {
    90                        Field::Key_claims => value_claims = crate::serde::de::MapAccess::next_value(&mut map)?,
    91                        Field::Key_limits => value_limits = crate::serde::de::MapAccess::next_value(&mut map)?,
    92                        Field::Key_requests => value_requests = crate::serde::de::MapAccess::next_value(&mut map)?,
    93                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    94                    }
    95                }
    96
    97                Ok(ResourceRequirements {
    98                    claims: value_claims,
    99                    limits: value_limits,
    100                    requests: value_requests,
    101                })
    102            }
    103        }
    104
    105        deserializer.deserialize_struct(
    106            "ResourceRequirements",
    107            &[
    108                "claims",
    109                "limits",
    110                "requests",
    111            ],
    112            Visitor,
    113        )
    114    }
    115}
    116
    117impl crate::serde::Serialize for ResourceRequirements {
    118    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    119        let mut state = serializer.serialize_struct(
    120            "ResourceRequirements",
    121            self.claims.as_ref().map_or(0, |_| 1) +
    122            self.limits.as_ref().map_or(0, |_| 1) +
    123            self.requests.as_ref().map_or(0, |_| 1),
    124        )?;
    125        if let Some(value) = &self.claims {
    126            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "claims", value)?;
    127        }
    128        if let Some(value) = &self.limits {
    129            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "limits", value)?;
    130        }
    131        if let Some(value) = &self.requests {
    132            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "requests", value)?;
    133        }
    134        crate::serde::ser::SerializeStruct::end(state)
    135    }
    136}
    137
    138#[cfg(feature = "schemars")]
    139impl crate::schemars::JsonSchema for ResourceRequirements {
    140    fn schema_name() -> std::borrow::Cow<'static, str> {
    141        "io.k8s.api.core.v1.ResourceRequirements".into()
    142    }
    143
    144    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    145        crate::schemars::json_schema!({
    146            "description": "ResourceRequirements describes the compute resource requirements.",
    147            "type": "object",
    148            "properties": {
    149                "claims": {
    150                    "description": "Claims lists the names of resources, defined in spec.resourceClaims, that are used by this container.\n\nThis field depends on the DynamicResourceAllocation feature gate.\n\nThis field is immutable. It can only be set for containers.",
    151                    "type": "array",
    152                    "items": (__gen.subschema_for::<crate::api::core::v1::ResourceClaim>()),
    153                },
    154                "limits": {
    155                    "description": "Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/",
    156                    "type": "object",
    157                    "additionalProperties": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
    158                },
    159                "requests": {
    160                    "description": "Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. Requests cannot exceed Limits. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/",
    161                    "type": "object",
    162                    "additionalProperties": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
    163                },
    164            },
    165        })
    166    }
    167}