#
k8s_openapi/v1_35/api/networking/v1/
ingress_rule.rs

    1// Generated from definition io.k8s.api.networking.v1.IngressRule
    2
    3/// IngressRule represents the rules mapping the paths under a specified host to the related backend services. Incoming requests are first evaluated for a host match, then routed to the backend associated with the matching IngressRuleValue.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct IngressRule {
    6    /// host is the fully qualified domain name of a network host, as defined by RFC 3986. Note the following deviations from the "host" part of the URI as defined in RFC 3986: 1. IPs are not allowed. Currently an IngressRuleValue can only apply to
    7    ///    the IP in the Spec of the parent Ingress.
    8    /// 2. The `:` delimiter is not respected because ports are not allowed.
    9    ///       Currently the port of an Ingress is implicitly :80 for http and
    10    ///       :443 for https.
    11    /// Both these may change in the future. Incoming requests are matched against the host before the IngressRuleValue. If the host is unspecified, the Ingress routes all traffic based on the specified IngressRuleValue.
    12    ///
    13    /// host can be "precise" which is a domain name without the terminating dot of a network host (e.g. "foo.bar.com") or "wildcard", which is a domain name prefixed with a single wildcard label (e.g. "*.foo.com"). The wildcard character '*' must appear by itself as the first DNS label and matches only a single label. You cannot have a wildcard label by itself (e.g. Host == "*"). Requests will be matched against the Host field in the following way: 1. If host is precise, the request matches this rule if the http host header is equal to Host. 2. If host is a wildcard, then the request matches this rule if the http host header is to equal to the suffix (removing the first label) of the wildcard rule.
    14    pub host: Option<std::string::String>,
    15
    16    pub http: Option<crate::api::networking::v1::HTTPIngressRuleValue>,
    17}
    18
    19impl crate::DeepMerge for IngressRule {
    20    fn merge_from(&mut self, other: Self) {
    21        crate::DeepMerge::merge_from(&mut self.host, other.host);
    22        crate::DeepMerge::merge_from(&mut self.http, other.http);
    23    }
    24}
    25
    26impl<'de> crate::serde::Deserialize<'de> for IngressRule {
    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_host,
    31            Key_http,
    32            Other,
    33        }
    34
    35        impl<'de> crate::serde::Deserialize<'de> for Field {
    36            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    37                struct Visitor;
    38
    39                impl crate::serde::de::Visitor<'_> for Visitor {
    40                    type Value = Field;
    41
    42                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    43                        f.write_str("field identifier")
    44                    }
    45
    46                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    47                        Ok(match v {
    48                            "host" => Field::Key_host,
    49                            "http" => Field::Key_http,
    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 = IngressRule;
    63
    64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    65                f.write_str("IngressRule")
    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_host: Option<std::string::String> = None;
    70                let mut value_http: Option<crate::api::networking::v1::HTTPIngressRuleValue> = None;
    71
    72                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    73                    match key {
    74                        Field::Key_host => value_host = crate::serde::de::MapAccess::next_value(&mut map)?,
    75                        Field::Key_http => value_http = crate::serde::de::MapAccess::next_value(&mut map)?,
    76                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    77                    }
    78                }
    79
    80                Ok(IngressRule {
    81                    host: value_host,
    82                    http: value_http,
    83                })
    84            }
    85        }
    86
    87        deserializer.deserialize_struct(
    88            "IngressRule",
    89            &[
    90                "host",
    91                "http",
    92            ],
    93            Visitor,
    94        )
    95    }
    96}
    97
    98impl crate::serde::Serialize for IngressRule {
    99    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    100        let mut state = serializer.serialize_struct(
    101            "IngressRule",
    102            self.host.as_ref().map_or(0, |_| 1) +
    103            self.http.as_ref().map_or(0, |_| 1),
    104        )?;
    105        if let Some(value) = &self.host {
    106            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "host", value)?;
    107        }
    108        if let Some(value) = &self.http {
    109            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "http", value)?;
    110        }
    111        crate::serde::ser::SerializeStruct::end(state)
    112    }
    113}
    114
    115#[cfg(feature = "schemars")]
    116impl crate::schemars::JsonSchema for IngressRule {
    117    fn schema_name() -> std::borrow::Cow<'static, str> {
    118        "io.k8s.api.networking.v1.IngressRule".into()
    119    }
    120
    121    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    122        crate::schemars::json_schema!({
    123            "description": "IngressRule represents the rules mapping the paths under a specified host to the related backend services. Incoming requests are first evaluated for a host match, then routed to the backend associated with the matching IngressRuleValue.",
    124            "type": "object",
    125            "properties": {
    126                "host": {
    127                    "description": "host is the fully qualified domain name of a network host, as defined by RFC 3986. Note the following deviations from the \"host\" part of the URI as defined in RFC 3986: 1. IPs are not allowed. Currently an IngressRuleValue can only apply to\n   the IP in the Spec of the parent Ingress.\n2. The `:` delimiter is not respected because ports are not allowed.\n\t  Currently the port of an Ingress is implicitly :80 for http and\n\t  :443 for https.\nBoth these may change in the future. Incoming requests are matched against the host before the IngressRuleValue. If the host is unspecified, the Ingress routes all traffic based on the specified IngressRuleValue.\n\nhost can be \"precise\" which is a domain name without the terminating dot of a network host (e.g. \"foo.bar.com\") or \"wildcard\", which is a domain name prefixed with a single wildcard label (e.g. \"*.foo.com\"). The wildcard character '*' must appear by itself as the first DNS label and matches only a single label. You cannot have a wildcard label by itself (e.g. Host == \"*\"). Requests will be matched against the Host field in the following way: 1. If host is precise, the request matches this rule if the http host header is equal to Host. 2. If host is a wildcard, then the request matches this rule if the http host header is to equal to the suffix (removing the first label) of the wildcard rule.",
    128                    "type": "string",
    129                },
    130                "http": __gen.subschema_for::<crate::api::networking::v1::HTTPIngressRuleValue>(),
    131            },
    132        })
    133    }
    134}