k8s_openapi/v1_35/api/core/v1/
resource_quota_spec.rs

1// Generated from definition io.k8s.api.core.v1.ResourceQuotaSpec
2
3/// ResourceQuotaSpec defines the desired hard limits to enforce for Quota.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ResourceQuotaSpec {
6    /// hard is the set of desired 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    /// scopeSelector is also a collection of filters like scopes that must match each object tracked by a quota but expressed using ScopeSelectorOperator in combination with possible values. For a resource to match, both scopes AND scopeSelector (if specified in spec), must be matched.
10    pub scope_selector: Option<crate::api::core::v1::ScopeSelector>,
11
12    /// A collection of filters that must match each object tracked by a quota. If not specified, the quota matches all objects.
13    pub scopes: Option<std::vec::Vec<std::string::String>>,
14}
15
16impl crate::DeepMerge for ResourceQuotaSpec {
17    fn merge_from(&mut self, other: Self) {
18        crate::merge_strategies::map::granular(&mut self.hard, other.hard, |current_item, other_item| {
19            crate::DeepMerge::merge_from(current_item, other_item);
20        });
21        crate::DeepMerge::merge_from(&mut self.scope_selector, other.scope_selector);
22        crate::merge_strategies::list::atomic(&mut self.scopes, other.scopes);
23    }
24}
25
26impl<'de> crate::serde::Deserialize<'de> for ResourceQuotaSpec {
27    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
28        #[allow(non_camel_case_types)]
29        enum Field {
30            Key_hard,
31            Key_scope_selector,
32            Key_scopes,
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                            "hard" => Field::Key_hard,
50                            "scopeSelector" => Field::Key_scope_selector,
51                            "scopes" => Field::Key_scopes,
52                            _ => Field::Other,
53                        })
54                    }
55                }
56
57                deserializer.deserialize_identifier(Visitor)
58            }
59        }
60
61        struct Visitor;
62
63        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
64            type Value = ResourceQuotaSpec;
65
66            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
67                f.write_str("ResourceQuotaSpec")
68            }
69
70            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
71                let mut value_hard: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
72                let mut value_scope_selector: Option<crate::api::core::v1::ScopeSelector> = None;
73                let mut value_scopes: Option<std::vec::Vec<std::string::String>> = None;
74
75                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
76                    match key {
77                        Field::Key_hard => value_hard = crate::serde::de::MapAccess::next_value(&mut map)?,
78                        Field::Key_scope_selector => value_scope_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
79                        Field::Key_scopes => value_scopes = crate::serde::de::MapAccess::next_value(&mut map)?,
80                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
81                    }
82                }
83
84                Ok(ResourceQuotaSpec {
85                    hard: value_hard,
86                    scope_selector: value_scope_selector,
87                    scopes: value_scopes,
88                })
89            }
90        }
91
92        deserializer.deserialize_struct(
93            "ResourceQuotaSpec",
94            &[
95                "hard",
96                "scopeSelector",
97                "scopes",
98            ],
99            Visitor,
100        )
101    }
102}
103
104impl crate::serde::Serialize for ResourceQuotaSpec {
105    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
106        let mut state = serializer.serialize_struct(
107            "ResourceQuotaSpec",
108            self.hard.as_ref().map_or(0, |_| 1) +
109            self.scope_selector.as_ref().map_or(0, |_| 1) +
110            self.scopes.as_ref().map_or(0, |_| 1),
111        )?;
112        if let Some(value) = &self.hard {
113            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "hard", value)?;
114        }
115        if let Some(value) = &self.scope_selector {
116            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "scopeSelector", value)?;
117        }
118        if let Some(value) = &self.scopes {
119            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "scopes", value)?;
120        }
121        crate::serde::ser::SerializeStruct::end(state)
122    }
123}
124
125#[cfg(feature = "schemars")]
126impl crate::schemars::JsonSchema for ResourceQuotaSpec {
127    fn schema_name() -> std::borrow::Cow<'static, str> {
128        "io.k8s.api.core.v1.ResourceQuotaSpec".into()
129    }
130
131    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
132        crate::schemars::json_schema!({
133            "description": "ResourceQuotaSpec defines the desired hard limits to enforce for Quota.",
134            "type": "object",
135            "properties": {
136                "hard": {
137                    "description": "hard is the set of desired hard limits for each named resource. More info: https://kubernetes.io/docs/concepts/policy/resource-quotas/",
138                    "type": "object",
139                    "additionalProperties": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
140                },
141                "scopeSelector": ({
142                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ScopeSelector>();
143                    schema_obj.ensure_object().insert("description".into(), "scopeSelector is also a collection of filters like scopes that must match each object tracked by a quota but expressed using ScopeSelectorOperator in combination with possible values. For a resource to match, both scopes AND scopeSelector (if specified in spec), must be matched.".into());
144                    schema_obj
145                }),
146                "scopes": {
147                    "description": "A collection of filters that must match each object tracked by a quota. If not specified, the quota matches all objects.",
148                    "type": "array",
149                    "items": {
150                        "type": "string",
151                    },
152                },
153            },
154        })
155    }
156}