1// Generated from definition io.k8s.api.flowcontrol.v1.FlowSchemaSpec
23/// FlowSchemaSpec describes how the FlowSchema's specification looks like.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct FlowSchemaSpec {
6/// `distinguisherMethod` defines how to compute the flow distinguisher for requests that match this schema. `nil` specifies that the distinguisher is disabled and thus will always be the empty string.
7pub distinguisher_method: Option<crate::api::flowcontrol::v1::FlowDistinguisherMethod>,
89/// `matchingPrecedence` is used to choose among the FlowSchemas that match a given request. The chosen FlowSchema is among those with the numerically lowest (which we take to be logically highest) MatchingPrecedence. Each MatchingPrecedence value must be ranged in \[1,10000\]. Note that if the precedence is not specified, it will be set to 1000 as default.
10pub matching_precedence: Option<i32>,
1112/// `priorityLevelConfiguration` should reference a PriorityLevelConfiguration in the cluster. If the reference cannot be resolved, the FlowSchema will be ignored and marked as invalid in its status. Required.
13pub priority_level_configuration: crate::api::flowcontrol::v1::PriorityLevelConfigurationReference,
1415/// `rules` describes which requests will match this flow schema. This FlowSchema matches a request if and only if at least one member of rules matches the request. if it is an empty slice, there will be no requests matching the FlowSchema.
16pub rules: Option<std::vec::Vec<crate::api::flowcontrol::v1::PolicyRulesWithSubjects>>,
17}
1819impl crate::DeepMerge for FlowSchemaSpec {
20fn merge_from(&mut self, other: Self) {
21crate::DeepMerge::merge_from(&mut self.distinguisher_method, other.distinguisher_method);
22crate::DeepMerge::merge_from(&mut self.matching_precedence, other.matching_precedence);
23crate::DeepMerge::merge_from(&mut self.priority_level_configuration, other.priority_level_configuration);
24crate::merge_strategies::list::atomic(&mut self.rules, other.rules);
25 }
26}
2728impl<'de> crate::serde::Deserialize<'de> for FlowSchemaSpec {
29fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
30#[allow(non_camel_case_types)]
31enum Field {
32 Key_distinguisher_method,
33 Key_matching_precedence,
34 Key_priority_level_configuration,
35 Key_rules,
36 Other,
37 }
3839impl<'de> crate::serde::Deserialize<'de> for Field {
40fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
41struct Visitor;
4243impl crate::serde::de::Visitor<'_> for Visitor {
44type Value = Field;
4546fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
47 f.write_str("field identifier")
48 }
4950fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
51Ok(match v {
52"distinguisherMethod" => Field::Key_distinguisher_method,
53"matchingPrecedence" => Field::Key_matching_precedence,
54"priorityLevelConfiguration" => Field::Key_priority_level_configuration,
55"rules" => Field::Key_rules,
56_ => Field::Other,
57 })
58 }
59 }
6061 deserializer.deserialize_identifier(Visitor)
62 }
63 }
6465struct Visitor;
6667impl<'de> crate::serde::de::Visitor<'de> for Visitor {
68type Value = FlowSchemaSpec;
6970fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71 f.write_str("FlowSchemaSpec")
72 }
7374fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
75let mut value_distinguisher_method: Option<crate::api::flowcontrol::v1::FlowDistinguisherMethod> = None;
76let mut value_matching_precedence: Option<i32> = None;
77let mut value_priority_level_configuration: Option<crate::api::flowcontrol::v1::PriorityLevelConfigurationReference> = None;
78let mut value_rules: Option<std::vec::Vec<crate::api::flowcontrol::v1::PolicyRulesWithSubjects>> = None;
7980while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
81match key {
82 Field::Key_distinguisher_method => value_distinguisher_method = crate::serde::de::MapAccess::next_value(&mut map)?,
83 Field::Key_matching_precedence => value_matching_precedence = crate::serde::de::MapAccess::next_value(&mut map)?,
84 Field::Key_priority_level_configuration => value_priority_level_configuration = crate::serde::de::MapAccess::next_value(&mut map)?,
85 Field::Key_rules => value_rules = crate::serde::de::MapAccess::next_value(&mut map)?,
86 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
87 }
88 }
8990Ok(FlowSchemaSpec {
91 distinguisher_method: value_distinguisher_method,
92 matching_precedence: value_matching_precedence,
93 priority_level_configuration: value_priority_level_configuration.unwrap_or_default(),
94 rules: value_rules,
95 })
96 }
97 }
9899 deserializer.deserialize_struct(
100"FlowSchemaSpec",
101&[
102"distinguisherMethod",
103"matchingPrecedence",
104"priorityLevelConfiguration",
105"rules",
106 ],
107 Visitor,
108 )
109 }
110}
111112impl crate::serde::Serialize for FlowSchemaSpec {
113fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
114let mut state = serializer.serialize_struct(
115"FlowSchemaSpec",
1161 +
117self.distinguisher_method.as_ref().map_or(0, |_| 1) +
118self.matching_precedence.as_ref().map_or(0, |_| 1) +
119self.rules.as_ref().map_or(0, |_| 1),
120 )?;
121if let Some(value) = &self.distinguisher_method {
122crate::serde::ser::SerializeStruct::serialize_field(&mut state, "distinguisherMethod", value)?;
123 }
124if let Some(value) = &self.matching_precedence {
125crate::serde::ser::SerializeStruct::serialize_field(&mut state, "matchingPrecedence", value)?;
126 }
127crate::serde::ser::SerializeStruct::serialize_field(&mut state, "priorityLevelConfiguration", &self.priority_level_configuration)?;
128if let Some(value) = &self.rules {
129crate::serde::ser::SerializeStruct::serialize_field(&mut state, "rules", value)?;
130 }
131crate::serde::ser::SerializeStruct::end(state)
132 }
133}
134135#[cfg(feature = "schemars")]
136impl crate::schemars::JsonSchema for FlowSchemaSpec {
137fn schema_name() -> std::string::String {
138"io.k8s.api.flowcontrol.v1.FlowSchemaSpec".into()
139 }
140141fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
142crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
143 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
144 description: Some("FlowSchemaSpec describes how the FlowSchema's specification looks like.".into()),
145 ..Default::default()
146 })),
147 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
148 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
149 properties: [
150 (
151"distinguisherMethod".into(),
152 {
153let mut schema_obj = __gen.subschema_for::<crate::api::flowcontrol::v1::FlowDistinguisherMethod>().into_object();
154 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
155 description: Some("`distinguisherMethod` defines how to compute the flow distinguisher for requests that match this schema. `nil` specifies that the distinguisher is disabled and thus will always be the empty string.".into()),
156 ..Default::default()
157 }));
158crate::schemars::schema::Schema::Object(schema_obj)
159 },
160 ),
161 (
162"matchingPrecedence".into(),
163crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
164 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
165 description: Some("`matchingPrecedence` is used to choose among the FlowSchemas that match a given request. The chosen FlowSchema is among those with the numerically lowest (which we take to be logically highest) MatchingPrecedence. Each MatchingPrecedence value must be ranged in [1,10000]. Note that if the precedence is not specified, it will be set to 1000 as default.".into()),
166 ..Default::default()
167 })),
168 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Integer))),
169 format: Some("int32".into()),
170 ..Default::default()
171 }),
172 ),
173 (
174"priorityLevelConfiguration".into(),
175 {
176let mut schema_obj = __gen.subschema_for::<crate::api::flowcontrol::v1::PriorityLevelConfigurationReference>().into_object();
177 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
178 description: Some("`priorityLevelConfiguration` should reference a PriorityLevelConfiguration in the cluster. If the reference cannot be resolved, the FlowSchema will be ignored and marked as invalid in its status. Required.".into()),
179 ..Default::default()
180 }));
181crate::schemars::schema::Schema::Object(schema_obj)
182 },
183 ),
184 (
185"rules".into(),
186crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
187 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
188 description: Some("`rules` describes which requests will match this flow schema. This FlowSchema matches a request if and only if at least one member of rules matches the request. if it is an empty slice, there will be no requests matching the FlowSchema.".into()),
189 ..Default::default()
190 })),
191 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
192 array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
193 items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::flowcontrol::v1::PolicyRulesWithSubjects>()))),
194 ..Default::default()
195 })),
196 ..Default::default()
197 }),
198 ),
199 ].into(),
200 required: [
201"priorityLevelConfiguration".into(),
202 ].into(),
203 ..Default::default()
204 })),
205 ..Default::default()
206 })
207 }
208}