#
k8s_openapi/v1_35/api/flowcontrol/v1/
flow_schema_spec.rs

    1// Generated from definition io.k8s.api.flowcontrol.v1.FlowSchemaSpec
    2
    3/// 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.
    7    pub distinguisher_method: Option<crate::api::flowcontrol::v1::FlowDistinguisherMethod>,
    8
    9    /// `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.
    10    pub matching_precedence: Option<i32>,
    11
    12    /// `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.
    13    pub priority_level_configuration: crate::api::flowcontrol::v1::PriorityLevelConfigurationReference,
    14
    15    /// `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.
    16    pub rules: Option<std::vec::Vec<crate::api::flowcontrol::v1::PolicyRulesWithSubjects>>,
    17}
    18
    19impl crate::DeepMerge for FlowSchemaSpec {
    20    fn merge_from(&mut self, other: Self) {
    21        crate::DeepMerge::merge_from(&mut self.distinguisher_method, other.distinguisher_method);
    22        crate::DeepMerge::merge_from(&mut self.matching_precedence, other.matching_precedence);
    23        crate::DeepMerge::merge_from(&mut self.priority_level_configuration, other.priority_level_configuration);
    24        crate::merge_strategies::list::atomic(&mut self.rules, other.rules);
    25    }
    26}
    27
    28impl<'de> crate::serde::Deserialize<'de> for FlowSchemaSpec {
    29    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    30        #[allow(non_camel_case_types)]
    31        enum Field {
    32            Key_distinguisher_method,
    33            Key_matching_precedence,
    34            Key_priority_level_configuration,
    35            Key_rules,
    36            Other,
    37        }
    38
    39        impl<'de> crate::serde::Deserialize<'de> for Field {
    40            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    41                struct Visitor;
    42
    43                impl crate::serde::de::Visitor<'_> for Visitor {
    44                    type Value = Field;
    45
    46                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    47                        f.write_str("field identifier")
    48                    }
    49
    50                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    51                        Ok(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                }
    60
    61                deserializer.deserialize_identifier(Visitor)
    62            }
    63        }
    64
    65        struct Visitor;
    66
    67        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    68            type Value = FlowSchemaSpec;
    69
    70            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    71                f.write_str("FlowSchemaSpec")
    72            }
    73
    74            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    75                let mut value_distinguisher_method: Option<crate::api::flowcontrol::v1::FlowDistinguisherMethod> = None;
    76                let mut value_matching_precedence: Option<i32> = None;
    77                let mut value_priority_level_configuration: Option<crate::api::flowcontrol::v1::PriorityLevelConfigurationReference> = None;
    78                let mut value_rules: Option<std::vec::Vec<crate::api::flowcontrol::v1::PolicyRulesWithSubjects>> = None;
    79
    80                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    81                    match 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                }
    89
    90                Ok(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        }
    98
    99        deserializer.deserialize_struct(
    100            "FlowSchemaSpec",
    101            &[
    102                "distinguisherMethod",
    103                "matchingPrecedence",
    104                "priorityLevelConfiguration",
    105                "rules",
    106            ],
    107            Visitor,
    108        )
    109    }
    110}
    111
    112impl crate::serde::Serialize for FlowSchemaSpec {
    113    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    114        let mut state = serializer.serialize_struct(
    115            "FlowSchemaSpec",
    116            1 +
    117            self.distinguisher_method.as_ref().map_or(0, |_| 1) +
    118            self.matching_precedence.as_ref().map_or(0, |_| 1) +
    119            self.rules.as_ref().map_or(0, |_| 1),
    120        )?;
    121        if let Some(value) = &self.distinguisher_method {
    122            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "distinguisherMethod", value)?;
    123        }
    124        if let Some(value) = &self.matching_precedence {
    125            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "matchingPrecedence", value)?;
    126        }
    127        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "priorityLevelConfiguration", &self.priority_level_configuration)?;
    128        if let Some(value) = &self.rules {
    129            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "rules", value)?;
    130        }
    131        crate::serde::ser::SerializeStruct::end(state)
    132    }
    133}
    134
    135#[cfg(feature = "schemars")]
    136impl crate::schemars::JsonSchema for FlowSchemaSpec {
    137    fn schema_name() -> std::borrow::Cow<'static, str> {
    138        "io.k8s.api.flowcontrol.v1.FlowSchemaSpec".into()
    139    }
    140
    141    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    142        crate::schemars::json_schema!({
    143            "description": "FlowSchemaSpec describes how the FlowSchema's specification looks like.",
    144            "type": "object",
    145            "properties": {
    146                "distinguisherMethod": ({
    147                    let mut schema_obj = __gen.subschema_for::<crate::api::flowcontrol::v1::FlowDistinguisherMethod>();
    148                    schema_obj.ensure_object().insert("description".into(), "`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());
    149                    schema_obj
    150                }),
    151                "matchingPrecedence": {
    152                    "description": "`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.",
    153                    "type": "integer",
    154                    "format": "int32",
    155                },
    156                "priorityLevelConfiguration": ({
    157                    let mut schema_obj = __gen.subschema_for::<crate::api::flowcontrol::v1::PriorityLevelConfigurationReference>();
    158                    schema_obj.ensure_object().insert("description".into(), "`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());
    159                    schema_obj
    160                }),
    161                "rules": {
    162                    "description": "`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.",
    163                    "type": "array",
    164                    "items": (__gen.subschema_for::<crate::api::flowcontrol::v1::PolicyRulesWithSubjects>()),
    165                },
    166            },
    167            "required": [
    168                "priorityLevelConfiguration",
    169            ],
    170        })
    171    }
    172}