k8s_openapi/v1_34/api/networking/v1/
ingress_spec.rs

1// Generated from definition io.k8s.api.networking.v1.IngressSpec
2
3/// IngressSpec describes the Ingress the user wishes to exist.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct IngressSpec {
6    /// defaultBackend is the backend that should handle requests that don't match any rule. If Rules are not specified, DefaultBackend must be specified. If DefaultBackend is not set, the handling of requests that do not match any of the rules will be up to the Ingress controller.
7    pub default_backend: Option<crate::api::networking::v1::IngressBackend>,
8
9    /// ingressClassName is the name of an IngressClass cluster resource. Ingress controller implementations use this field to know whether they should be serving this Ingress resource, by a transitive connection (controller -\> IngressClass -\> Ingress resource). Although the `kubernetes.io/ingress.class` annotation (simple constant name) was never formally defined, it was widely supported by Ingress controllers to create a direct binding between Ingress controller and Ingress resources. Newly created Ingress resources should prefer using the field. However, even though the annotation is officially deprecated, for backwards compatibility reasons, ingress controllers should still honor that annotation if present.
10    pub ingress_class_name: Option<std::string::String>,
11
12    /// rules is a list of host rules used to configure the Ingress. If unspecified, or no rule matches, all traffic is sent to the default backend.
13    pub rules: Option<std::vec::Vec<crate::api::networking::v1::IngressRule>>,
14
15    /// tls represents the TLS configuration. Currently the Ingress only supports a single TLS port, 443. If multiple members of this list specify different hosts, they will be multiplexed on the same port according to the hostname specified through the SNI TLS extension, if the ingress controller fulfilling the ingress supports SNI.
16    pub tls: Option<std::vec::Vec<crate::api::networking::v1::IngressTLS>>,
17}
18
19impl crate::DeepMerge for IngressSpec {
20    fn merge_from(&mut self, other: Self) {
21        crate::DeepMerge::merge_from(&mut self.default_backend, other.default_backend);
22        crate::DeepMerge::merge_from(&mut self.ingress_class_name, other.ingress_class_name);
23        crate::merge_strategies::list::atomic(&mut self.rules, other.rules);
24        crate::merge_strategies::list::atomic(&mut self.tls, other.tls);
25    }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for IngressSpec {
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_default_backend,
33            Key_ingress_class_name,
34            Key_rules,
35            Key_tls,
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                            "defaultBackend" => Field::Key_default_backend,
53                            "ingressClassName" => Field::Key_ingress_class_name,
54                            "rules" => Field::Key_rules,
55                            "tls" => Field::Key_tls,
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 = IngressSpec;
69
70            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71                f.write_str("IngressSpec")
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_default_backend: Option<crate::api::networking::v1::IngressBackend> = None;
76                let mut value_ingress_class_name: Option<std::string::String> = None;
77                let mut value_rules: Option<std::vec::Vec<crate::api::networking::v1::IngressRule>> = None;
78                let mut value_tls: Option<std::vec::Vec<crate::api::networking::v1::IngressTLS>> = None;
79
80                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
81                    match key {
82                        Field::Key_default_backend => value_default_backend = crate::serde::de::MapAccess::next_value(&mut map)?,
83                        Field::Key_ingress_class_name => value_ingress_class_name = crate::serde::de::MapAccess::next_value(&mut map)?,
84                        Field::Key_rules => value_rules = crate::serde::de::MapAccess::next_value(&mut map)?,
85                        Field::Key_tls => value_tls = 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(IngressSpec {
91                    default_backend: value_default_backend,
92                    ingress_class_name: value_ingress_class_name,
93                    rules: value_rules,
94                    tls: value_tls,
95                })
96            }
97        }
98
99        deserializer.deserialize_struct(
100            "IngressSpec",
101            &[
102                "defaultBackend",
103                "ingressClassName",
104                "rules",
105                "tls",
106            ],
107            Visitor,
108        )
109    }
110}
111
112impl crate::serde::Serialize for IngressSpec {
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            "IngressSpec",
116            self.default_backend.as_ref().map_or(0, |_| 1) +
117            self.ingress_class_name.as_ref().map_or(0, |_| 1) +
118            self.rules.as_ref().map_or(0, |_| 1) +
119            self.tls.as_ref().map_or(0, |_| 1),
120        )?;
121        if let Some(value) = &self.default_backend {
122            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "defaultBackend", value)?;
123        }
124        if let Some(value) = &self.ingress_class_name {
125            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "ingressClassName", value)?;
126        }
127        if let Some(value) = &self.rules {
128            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "rules", value)?;
129        }
130        if let Some(value) = &self.tls {
131            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "tls", value)?;
132        }
133        crate::serde::ser::SerializeStruct::end(state)
134    }
135}
136
137#[cfg(feature = "schemars")]
138impl crate::schemars::JsonSchema for IngressSpec {
139    fn schema_name() -> std::borrow::Cow<'static, str> {
140        "io.k8s.api.networking.v1.IngressSpec".into()
141    }
142
143    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
144        crate::schemars::json_schema!({
145            "description": "IngressSpec describes the Ingress the user wishes to exist.",
146            "type": "object",
147            "properties": {
148                "defaultBackend": ({
149                    let mut schema_obj = __gen.subschema_for::<crate::api::networking::v1::IngressBackend>();
150                    schema_obj.ensure_object().insert("description".into(), "defaultBackend is the backend that should handle requests that don't match any rule. If Rules are not specified, DefaultBackend must be specified. If DefaultBackend is not set, the handling of requests that do not match any of the rules will be up to the Ingress controller.".into());
151                    schema_obj
152                }),
153                "ingressClassName": {
154                    "description": "ingressClassName is the name of an IngressClass cluster resource. Ingress controller implementations use this field to know whether they should be serving this Ingress resource, by a transitive connection (controller -> IngressClass -> Ingress resource). Although the `kubernetes.io/ingress.class` annotation (simple constant name) was never formally defined, it was widely supported by Ingress controllers to create a direct binding between Ingress controller and Ingress resources. Newly created Ingress resources should prefer using the field. However, even though the annotation is officially deprecated, for backwards compatibility reasons, ingress controllers should still honor that annotation if present.",
155                    "type": "string",
156                },
157                "rules": {
158                    "description": "rules is a list of host rules used to configure the Ingress. If unspecified, or no rule matches, all traffic is sent to the default backend.",
159                    "type": "array",
160                    "items": (__gen.subschema_for::<crate::api::networking::v1::IngressRule>()),
161                },
162                "tls": {
163                    "description": "tls represents the TLS configuration. Currently the Ingress only supports a single TLS port, 443. If multiple members of this list specify different hosts, they will be multiplexed on the same port according to the hostname specified through the SNI TLS extension, if the ingress controller fulfilling the ingress supports SNI.",
164                    "type": "array",
165                    "items": (__gen.subschema_for::<crate::api::networking::v1::IngressTLS>()),
166                },
167            },
168        })
169    }
170}