k8s_openapi/v1_33/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::string::String {
140        "io.k8s.api.networking.v1.IngressSpec".into()
141    }
142
143    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
144        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
145            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
146                description: Some("IngressSpec describes the Ingress the user wishes to exist.".into()),
147                ..Default::default()
148            })),
149            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
150            object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
151                properties: [
152                    (
153                        "defaultBackend".into(),
154                        {
155                            let mut schema_obj = __gen.subschema_for::<crate::api::networking::v1::IngressBackend>().into_object();
156                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
157                                description: Some("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()),
158                                ..Default::default()
159                            }));
160                            crate::schemars::schema::Schema::Object(schema_obj)
161                        },
162                    ),
163                    (
164                        "ingressClassName".into(),
165                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
166                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
167                                description: Some("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.".into()),
168                                ..Default::default()
169                            })),
170                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
171                            ..Default::default()
172                        }),
173                    ),
174                    (
175                        "rules".into(),
176                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
177                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
178                                description: Some("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.".into()),
179                                ..Default::default()
180                            })),
181                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
182                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
183                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::networking::v1::IngressRule>()))),
184                                ..Default::default()
185                            })),
186                            ..Default::default()
187                        }),
188                    ),
189                    (
190                        "tls".into(),
191                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
192                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
193                                description: Some("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.".into()),
194                                ..Default::default()
195                            })),
196                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
197                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
198                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::networking::v1::IngressTLS>()))),
199                                ..Default::default()
200                            })),
201                            ..Default::default()
202                        }),
203                    ),
204                ].into(),
205                ..Default::default()
206            })),
207            ..Default::default()
208        })
209    }
210}