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

    1// Generated from definition io.k8s.api.core.v1.ResourceQuotaStatus
    2
    3/// ResourceQuotaStatus defines the enforced hard limits and observed use.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct ResourceQuotaStatus {
    6    /// Hard is the set of enforced hard limits for each named resource. More info: https://kubernetes.io/docs/concepts/policy/resource-quotas/
    7    pub hard: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>>,
    8
    9    /// Used is the current observed total usage of the resource in the namespace.
    10    pub used: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>>,
    11}
    12
    13impl crate::DeepMerge for ResourceQuotaStatus {
    14    fn merge_from(&mut self, other: Self) {
    15        crate::merge_strategies::map::granular(&mut self.hard, other.hard, |current_item, other_item| {
    16            crate::DeepMerge::merge_from(current_item, other_item);
    17        });
    18        crate::merge_strategies::map::granular(&mut self.used, other.used, |current_item, other_item| {
    19            crate::DeepMerge::merge_from(current_item, other_item);
    20        });
    21    }
    22}
    23
    24impl<'de> crate::serde::Deserialize<'de> for ResourceQuotaStatus {
    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_hard,
    29            Key_used,
    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                            "hard" => Field::Key_hard,
    47                            "used" => Field::Key_used,
    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 = ResourceQuotaStatus;
    61
    62            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    63                f.write_str("ResourceQuotaStatus")
    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_hard: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
    68                let mut value_used: 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_hard => value_hard = crate::serde::de::MapAccess::next_value(&mut map)?,
    73                        Field::Key_used => value_used = 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(ResourceQuotaStatus {
    79                    hard: value_hard,
    80                    used: value_used,
    81                })
    82            }
    83        }
    84
    85        deserializer.deserialize_struct(
    86            "ResourceQuotaStatus",
    87            &[
    88                "hard",
    89                "used",
    90            ],
    91            Visitor,
    92        )
    93    }
    94}
    95
    96impl crate::serde::Serialize for ResourceQuotaStatus {
    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            "ResourceQuotaStatus",
    100            self.hard.as_ref().map_or(0, |_| 1) +
    101            self.used.as_ref().map_or(0, |_| 1),
    102        )?;
    103        if let Some(value) = &self.hard {
    104            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "hard", value)?;
    105        }
    106        if let Some(value) = &self.used {
    107            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "used", value)?;
    108        }
    109        crate::serde::ser::SerializeStruct::end(state)
    110    }
    111}
    112
    113#[cfg(feature = "schemars")]
    114impl crate::schemars::JsonSchema for ResourceQuotaStatus {
    115    fn schema_name() -> std::borrow::Cow<'static, str> {
    116        "io.k8s.api.core.v1.ResourceQuotaStatus".into()
    117    }
    118
    119    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    120        crate::schemars::json_schema!({
    121            "description": "ResourceQuotaStatus defines the enforced hard limits and observed use.",
    122            "type": "object",
    123            "properties": {
    124                "hard": {
    125                    "description": "Hard is the set of enforced hard limits for each named resource. More info: https://kubernetes.io/docs/concepts/policy/resource-quotas/",
    126                    "type": "object",
    127                    "additionalProperties": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
    128                },
    129                "used": {
    130                    "description": "Used is the current observed total usage of the resource in the namespace.",
    131                    "type": "object",
    132                    "additionalProperties": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
    133                },
    134            },
    135        })
    136    }
    137}