k8s_openapi/v1_30/api/flowcontrol/v1/
priority_level_configuration_spec.rs

1// Generated from definition io.k8s.api.flowcontrol.v1.PriorityLevelConfigurationSpec
2
3/// PriorityLevelConfigurationSpec specifies the configuration of a priority level.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct PriorityLevelConfigurationSpec {
6    /// `exempt` specifies how requests are handled for an exempt priority level. This field MUST be empty if `type` is `"Limited"`. This field MAY be non-empty if `type` is `"Exempt"`. If empty and `type` is `"Exempt"` then the default values for `ExemptPriorityLevelConfiguration` apply.
7    pub exempt: Option<crate::api::flowcontrol::v1::ExemptPriorityLevelConfiguration>,
8
9    /// `limited` specifies how requests are handled for a Limited priority level. This field must be non-empty if and only if `type` is `"Limited"`.
10    pub limited: Option<crate::api::flowcontrol::v1::LimitedPriorityLevelConfiguration>,
11
12    /// `type` indicates whether this priority level is subject to limitation on request execution.  A value of `"Exempt"` means that requests of this priority level are not subject to a limit (and thus are never queued) and do not detract from the capacity made available to other priority levels.  A value of `"Limited"` means that (a) requests of this priority level _are_ subject to limits and (b) some of the server's limited capacity is made available exclusively to this priority level. Required.
13    pub type_: std::string::String,
14}
15
16impl crate::DeepMerge for PriorityLevelConfigurationSpec {
17    fn merge_from(&mut self, other: Self) {
18        crate::DeepMerge::merge_from(&mut self.exempt, other.exempt);
19        crate::DeepMerge::merge_from(&mut self.limited, other.limited);
20        crate::DeepMerge::merge_from(&mut self.type_, other.type_);
21    }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for PriorityLevelConfigurationSpec {
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_exempt,
29            Key_limited,
30            Key_type_,
31            Other,
32        }
33
34        impl<'de> crate::serde::Deserialize<'de> for Field {
35            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36                struct Visitor;
37
38                impl crate::serde::de::Visitor<'_> for Visitor {
39                    type Value = Field;
40
41                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
42                        f.write_str("field identifier")
43                    }
44
45                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
46                        Ok(match v {
47                            "exempt" => Field::Key_exempt,
48                            "limited" => Field::Key_limited,
49                            "type" => Field::Key_type_,
50                            _ => Field::Other,
51                        })
52                    }
53                }
54
55                deserializer.deserialize_identifier(Visitor)
56            }
57        }
58
59        struct Visitor;
60
61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
62            type Value = PriorityLevelConfigurationSpec;
63
64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65                f.write_str("PriorityLevelConfigurationSpec")
66            }
67
68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
69                let mut value_exempt: Option<crate::api::flowcontrol::v1::ExemptPriorityLevelConfiguration> = None;
70                let mut value_limited: Option<crate::api::flowcontrol::v1::LimitedPriorityLevelConfiguration> = None;
71                let mut value_type_: Option<std::string::String> = None;
72
73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74                    match key {
75                        Field::Key_exempt => value_exempt = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Key_limited => value_limited = crate::serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Key_type_ => value_type_ = crate::serde::de::MapAccess::next_value(&mut map)?,
78                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
79                    }
80                }
81
82                Ok(PriorityLevelConfigurationSpec {
83                    exempt: value_exempt,
84                    limited: value_limited,
85                    type_: value_type_.unwrap_or_default(),
86                })
87            }
88        }
89
90        deserializer.deserialize_struct(
91            "PriorityLevelConfigurationSpec",
92            &[
93                "exempt",
94                "limited",
95                "type",
96            ],
97            Visitor,
98        )
99    }
100}
101
102impl crate::serde::Serialize for PriorityLevelConfigurationSpec {
103    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
104        let mut state = serializer.serialize_struct(
105            "PriorityLevelConfigurationSpec",
106            1 +
107            self.exempt.as_ref().map_or(0, |_| 1) +
108            self.limited.as_ref().map_or(0, |_| 1),
109        )?;
110        if let Some(value) = &self.exempt {
111            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "exempt", value)?;
112        }
113        if let Some(value) = &self.limited {
114            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "limited", value)?;
115        }
116        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "type", &self.type_)?;
117        crate::serde::ser::SerializeStruct::end(state)
118    }
119}
120
121#[cfg(feature = "schemars")]
122impl crate::schemars::JsonSchema for PriorityLevelConfigurationSpec {
123    fn schema_name() -> std::borrow::Cow<'static, str> {
124        "io.k8s.api.flowcontrol.v1.PriorityLevelConfigurationSpec".into()
125    }
126
127    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
128        crate::schemars::json_schema!({
129            "description": "PriorityLevelConfigurationSpec specifies the configuration of a priority level.",
130            "type": "object",
131            "properties": {
132                "exempt": ({
133                    let mut schema_obj = __gen.subschema_for::<crate::api::flowcontrol::v1::ExemptPriorityLevelConfiguration>();
134                    schema_obj.ensure_object().insert("description".into(), "`exempt` specifies how requests are handled for an exempt priority level. This field MUST be empty if `type` is `\"Limited\"`. This field MAY be non-empty if `type` is `\"Exempt\"`. If empty and `type` is `\"Exempt\"` then the default values for `ExemptPriorityLevelConfiguration` apply.".into());
135                    schema_obj
136                }),
137                "limited": ({
138                    let mut schema_obj = __gen.subschema_for::<crate::api::flowcontrol::v1::LimitedPriorityLevelConfiguration>();
139                    schema_obj.ensure_object().insert("description".into(), "`limited` specifies how requests are handled for a Limited priority level. This field must be non-empty if and only if `type` is `\"Limited\"`.".into());
140                    schema_obj
141                }),
142                "type": {
143                    "description": "`type` indicates whether this priority level is subject to limitation on request execution.  A value of `\"Exempt\"` means that requests of this priority level are not subject to a limit (and thus are never queued) and do not detract from the capacity made available to other priority levels.  A value of `\"Limited\"` means that (a) requests of this priority level _are_ subject to limits and (b) some of the server's limited capacity is made available exclusively to this priority level. Required.",
144                    "type": "string",
145                },
146            },
147            "required": [
148                "type",
149            ],
150        })
151    }
152}