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

    1// Generated from definition io.k8s.api.core.v1.LimitRangeItem
    2
    3/// LimitRangeItem defines a min/max usage limit for any resource that matches on kind.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct LimitRangeItem {
    6    /// Default resource requirement limit value by resource name if resource limit is omitted.
    7    pub default: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>>,
    8
    9    /// DefaultRequest is the default resource requirement request value by resource name if resource request is omitted.
    10    pub default_request: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>>,
    11
    12    /// Max usage constraints on this kind by resource name.
    13    pub max: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>>,
    14
    15    /// MaxLimitRequestRatio if specified, the named resource must have a request and limit that are both non-zero where limit divided by request is less than or equal to the enumerated value; this represents the max burst for the named resource.
    16    pub max_limit_request_ratio: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>>,
    17
    18    /// Min usage constraints on this kind by resource name.
    19    pub min: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>>,
    20
    21    /// Type of resource that this limit applies to.
    22    pub type_: std::string::String,
    23}
    24
    25impl crate::DeepMerge for LimitRangeItem {
    26    fn merge_from(&mut self, other: Self) {
    27        crate::merge_strategies::map::granular(&mut self.default, other.default, |current_item, other_item| {
    28            crate::DeepMerge::merge_from(current_item, other_item);
    29        });
    30        crate::merge_strategies::map::granular(&mut self.default_request, other.default_request, |current_item, other_item| {
    31            crate::DeepMerge::merge_from(current_item, other_item);
    32        });
    33        crate::merge_strategies::map::granular(&mut self.max, other.max, |current_item, other_item| {
    34            crate::DeepMerge::merge_from(current_item, other_item);
    35        });
    36        crate::merge_strategies::map::granular(&mut self.max_limit_request_ratio, other.max_limit_request_ratio, |current_item, other_item| {
    37            crate::DeepMerge::merge_from(current_item, other_item);
    38        });
    39        crate::merge_strategies::map::granular(&mut self.min, other.min, |current_item, other_item| {
    40            crate::DeepMerge::merge_from(current_item, other_item);
    41        });
    42        crate::DeepMerge::merge_from(&mut self.type_, other.type_);
    43    }
    44}
    45
    46impl<'de> crate::serde::Deserialize<'de> for LimitRangeItem {
    47    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    48        #[allow(non_camel_case_types)]
    49        enum Field {
    50            Key_default,
    51            Key_default_request,
    52            Key_max,
    53            Key_max_limit_request_ratio,
    54            Key_min,
    55            Key_type_,
    56            Other,
    57        }
    58
    59        impl<'de> crate::serde::Deserialize<'de> for Field {
    60            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    61                struct Visitor;
    62
    63                impl crate::serde::de::Visitor<'_> for Visitor {
    64                    type Value = Field;
    65
    66                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    67                        f.write_str("field identifier")
    68                    }
    69
    70                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    71                        Ok(match v {
    72                            "default" => Field::Key_default,
    73                            "defaultRequest" => Field::Key_default_request,
    74                            "max" => Field::Key_max,
    75                            "maxLimitRequestRatio" => Field::Key_max_limit_request_ratio,
    76                            "min" => Field::Key_min,
    77                            "type" => Field::Key_type_,
    78                            _ => Field::Other,
    79                        })
    80                    }
    81                }
    82
    83                deserializer.deserialize_identifier(Visitor)
    84            }
    85        }
    86
    87        struct Visitor;
    88
    89        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    90            type Value = LimitRangeItem;
    91
    92            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    93                f.write_str("LimitRangeItem")
    94            }
    95
    96            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    97                let mut value_default: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
    98                let mut value_default_request: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
    99                let mut value_max: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
    100                let mut value_max_limit_request_ratio: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
    101                let mut value_min: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
    102                let mut value_type_: Option<std::string::String> = None;
    103
    104                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    105                    match key {
    106                        Field::Key_default => value_default = crate::serde::de::MapAccess::next_value(&mut map)?,
    107                        Field::Key_default_request => value_default_request = crate::serde::de::MapAccess::next_value(&mut map)?,
    108                        Field::Key_max => value_max = crate::serde::de::MapAccess::next_value(&mut map)?,
    109                        Field::Key_max_limit_request_ratio => value_max_limit_request_ratio = crate::serde::de::MapAccess::next_value(&mut map)?,
    110                        Field::Key_min => value_min = crate::serde::de::MapAccess::next_value(&mut map)?,
    111                        Field::Key_type_ => value_type_ = crate::serde::de::MapAccess::next_value(&mut map)?,
    112                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    113                    }
    114                }
    115
    116                Ok(LimitRangeItem {
    117                    default: value_default,
    118                    default_request: value_default_request,
    119                    max: value_max,
    120                    max_limit_request_ratio: value_max_limit_request_ratio,
    121                    min: value_min,
    122                    type_: value_type_.unwrap_or_default(),
    123                })
    124            }
    125        }
    126
    127        deserializer.deserialize_struct(
    128            "LimitRangeItem",
    129            &[
    130                "default",
    131                "defaultRequest",
    132                "max",
    133                "maxLimitRequestRatio",
    134                "min",
    135                "type",
    136            ],
    137            Visitor,
    138        )
    139    }
    140}
    141
    142impl crate::serde::Serialize for LimitRangeItem {
    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            "LimitRangeItem",
    146            1 +
    147            self.default.as_ref().map_or(0, |_| 1) +
    148            self.default_request.as_ref().map_or(0, |_| 1) +
    149            self.max.as_ref().map_or(0, |_| 1) +
    150            self.max_limit_request_ratio.as_ref().map_or(0, |_| 1) +
    151            self.min.as_ref().map_or(0, |_| 1),
    152        )?;
    153        if let Some(value) = &self.default {
    154            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "default", value)?;
    155        }
    156        if let Some(value) = &self.default_request {
    157            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "defaultRequest", value)?;
    158        }
    159        if let Some(value) = &self.max {
    160            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "max", value)?;
    161        }
    162        if let Some(value) = &self.max_limit_request_ratio {
    163            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "maxLimitRequestRatio", value)?;
    164        }
    165        if let Some(value) = &self.min {
    166            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "min", value)?;
    167        }
    168        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "type", &self.type_)?;
    169        crate::serde::ser::SerializeStruct::end(state)
    170    }
    171}
    172
    173#[cfg(feature = "schemars")]
    174impl crate::schemars::JsonSchema for LimitRangeItem {
    175    fn schema_name() -> std::borrow::Cow<'static, str> {
    176        "io.k8s.api.core.v1.LimitRangeItem".into()
    177    }
    178
    179    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    180        crate::schemars::json_schema!({
    181            "description": "LimitRangeItem defines a min/max usage limit for any resource that matches on kind.",
    182            "type": "object",
    183            "properties": {
    184                "default": {
    185                    "description": "Default resource requirement limit value by resource name if resource limit is omitted.",
    186                    "type": "object",
    187                    "additionalProperties": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
    188                },
    189                "defaultRequest": {
    190                    "description": "DefaultRequest is the default resource requirement request value by resource name if resource request is omitted.",
    191                    "type": "object",
    192                    "additionalProperties": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
    193                },
    194                "max": {
    195                    "description": "Max usage constraints on this kind by resource name.",
    196                    "type": "object",
    197                    "additionalProperties": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
    198                },
    199                "maxLimitRequestRatio": {
    200                    "description": "MaxLimitRequestRatio if specified, the named resource must have a request and limit that are both non-zero where limit divided by request is less than or equal to the enumerated value; this represents the max burst for the named resource.",
    201                    "type": "object",
    202                    "additionalProperties": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
    203                },
    204                "min": {
    205                    "description": "Min usage constraints on this kind by resource name.",
    206                    "type": "object",
    207                    "additionalProperties": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
    208                },
    209                "type": {
    210                    "description": "Type of resource that this limit applies to.",
    211                    "type": "string",
    212                },
    213            },
    214            "required": [
    215                "type",
    216            ],
    217        })
    218    }
    219}