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

    1// Generated from definition io.k8s.api.core.v1.VolumeResourceRequirements
    2
    3/// VolumeResourceRequirements describes the storage resource requirements for a volume.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct VolumeResourceRequirements {
    6    /// Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
    7    pub limits: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>>,
    8
    9    /// 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/
    10    pub requests: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>>,
    11}
    12
    13impl crate::DeepMerge for VolumeResourceRequirements {
    14    fn merge_from(&mut self, other: Self) {
    15        crate::merge_strategies::map::granular(&mut self.limits, other.limits, |current_item, other_item| {
    16            crate::DeepMerge::merge_from(current_item, other_item);
    17        });
    18        crate::merge_strategies::map::granular(&mut self.requests, other.requests, |current_item, other_item| {
    19            crate::DeepMerge::merge_from(current_item, other_item);
    20        });
    21    }
    22}
    23
    24impl<'de> crate::serde::Deserialize<'de> for VolumeResourceRequirements {
    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_limits,
    29            Key_requests,
    30            Other,
    31        }
    32
    33        impl<'de> crate::serde::Deserialize<'de> for Field {
    34            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    35                struct Visitor;
    36
    37                impl crate::serde::de::Visitor<'_> for Visitor {
    38                    type Value = Field;
    39
    40                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    41                        f.write_str("field identifier")
    42                    }
    43
    44                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    45                        Ok(match v {
    46                            "limits" => Field::Key_limits,
    47                            "requests" => Field::Key_requests,
    48                            _ => Field::Other,
    49                        })
    50                    }
    51                }
    52
    53                deserializer.deserialize_identifier(Visitor)
    54            }
    55        }
    56
    57        struct Visitor;
    58
    59        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    60            type Value = VolumeResourceRequirements;
    61
    62            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    63                f.write_str("VolumeResourceRequirements")
    64            }
    65
    66            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    67                let mut value_limits: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
    68                let mut value_requests: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
    69
    70                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    71                    match key {
    72                        Field::Key_limits => value_limits = crate::serde::de::MapAccess::next_value(&mut map)?,
    73                        Field::Key_requests => value_requests = crate::serde::de::MapAccess::next_value(&mut map)?,
    74                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    75                    }
    76                }
    77
    78                Ok(VolumeResourceRequirements {
    79                    limits: value_limits,
    80                    requests: value_requests,
    81                })
    82            }
    83        }
    84
    85        deserializer.deserialize_struct(
    86            "VolumeResourceRequirements",
    87            &[
    88                "limits",
    89                "requests",
    90            ],
    91            Visitor,
    92        )
    93    }
    94}
    95
    96impl crate::serde::Serialize for VolumeResourceRequirements {
    97    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    98        let mut state = serializer.serialize_struct(
    99            "VolumeResourceRequirements",
    100            self.limits.as_ref().map_or(0, |_| 1) +
    101            self.requests.as_ref().map_or(0, |_| 1),
    102        )?;
    103        if let Some(value) = &self.limits {
    104            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "limits", value)?;
    105        }
    106        if let Some(value) = &self.requests {
    107            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "requests", value)?;
    108        }
    109        crate::serde::ser::SerializeStruct::end(state)
    110    }
    111}
    112
    113#[cfg(feature = "schemars")]
    114impl crate::schemars::JsonSchema for VolumeResourceRequirements {
    115    fn schema_name() -> std::borrow::Cow<'static, str> {
    116        "io.k8s.api.core.v1.VolumeResourceRequirements".into()
    117    }
    118
    119    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    120        crate::schemars::json_schema!({
    121            "description": "VolumeResourceRequirements describes the storage resource requirements for a volume.",
    122            "type": "object",
    123            "properties": {
    124                "limits": {
    125                    "description": "Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/",
    126                    "type": "object",
    127                    "additionalProperties": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
    128                },
    129                "requests": {
    130                    "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/",
    131                    "type": "object",
    132                    "additionalProperties": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
    133                },
    134            },
    135        })
    136    }
    137}