openshift_openapi/v4_5/api/route/v1/
route_spec.rs

1// Generated from definition com.github.openshift.api.route.v1.RouteSpec
2
3/// RouteSpec describes the hostname or path the route exposes, any security information, and one to four backends (services) the route points to. Requests are distributed among the backends depending on the weights assigned to each backend. When using roundrobin scheduling the portion of requests that go to each backend is the backend weight divided by the sum of all of the backend weights. When the backend has more than one endpoint the requests that end up on the backend are roundrobin distributed among the endpoints. Weights are between 0 and 256 with default 1. Weight 0 causes no requests to the backend. If all weights are zero the route will be considered to have no backends and return a standard 503 response.
4///
5/// The `tls` field is optional and allows specific certificates or behavior for the route. Routers typically configure a default certificate on a wildcard domain to terminate routes without explicit certificates, but custom hostnames usually must choose passthrough (send traffic directly to the backend via the TLS Server-Name- Indication field) or provide a certificate.
6#[derive(Clone, Debug, Default, PartialEq)]
7pub struct RouteSpec {
8    /// alternateBackends allows up to 3 additional backends to be assigned to the route. Only the Service kind is allowed, and it will be defaulted to Service. Use the weight field in RouteTargetReference object to specify relative preference.
9    pub alternate_backends: Option<Vec<crate::api::route::v1::RouteTargetReference>>,
10
11    /// host is an alias/DNS that points to the service. Optional. If not specified a route name will typically be automatically chosen. Must follow DNS952 subdomain conventions.
12    pub host: String,
13
14    /// Path that the router watches for, to route traffic for to the service. Optional
15    pub path: Option<String>,
16
17    /// If specified, the port to be used by the router. Most routers will use all endpoints exposed by the service by default - set this value to instruct routers which port to use.
18    pub port: Option<crate::api::route::v1::RoutePort>,
19
20    /// The tls field provides the ability to configure certificates and termination for the route.
21    pub tls: Option<crate::api::route::v1::TLSConfig>,
22
23    /// to is an object the route should use as the primary backend. Only the Service kind is allowed, and it will be defaulted to Service. If the weight field (0-256 default 1) is set to zero, no traffic will be sent to this backend.
24    pub to: crate::api::route::v1::RouteTargetReference,
25
26    /// Wildcard policy if any for the route. Currently only 'Subdomain' or 'None' is allowed.
27    pub wildcard_policy: Option<String>,
28}
29
30impl<'de> serde::Deserialize<'de> for RouteSpec {
31    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
32        #[allow(non_camel_case_types)]
33        enum Field {
34            Key_alternate_backends,
35            Key_host,
36            Key_path,
37            Key_port,
38            Key_tls,
39            Key_to,
40            Key_wildcard_policy,
41            Other,
42        }
43
44        impl<'de> serde::Deserialize<'de> for Field {
45            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
46                struct Visitor;
47
48                impl<'de> serde::de::Visitor<'de> for Visitor {
49                    type Value = Field;
50
51                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52                        f.write_str("field identifier")
53                    }
54
55                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: serde::de::Error {
56                        Ok(match v {
57                            "alternateBackends" => Field::Key_alternate_backends,
58                            "host" => Field::Key_host,
59                            "path" => Field::Key_path,
60                            "port" => Field::Key_port,
61                            "tls" => Field::Key_tls,
62                            "to" => Field::Key_to,
63                            "wildcardPolicy" => Field::Key_wildcard_policy,
64                            _ => Field::Other,
65                        })
66                    }
67                }
68
69                deserializer.deserialize_identifier(Visitor)
70            }
71        }
72
73        struct Visitor;
74
75        impl<'de> serde::de::Visitor<'de> for Visitor {
76            type Value = RouteSpec;
77
78            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79                f.write_str("RouteSpec")
80            }
81
82            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: serde::de::MapAccess<'de> {
83                let mut value_alternate_backends: Option<Vec<crate::api::route::v1::RouteTargetReference>> = None;
84                let mut value_host: Option<String> = None;
85                let mut value_path: Option<String> = None;
86                let mut value_port: Option<crate::api::route::v1::RoutePort> = None;
87                let mut value_tls: Option<crate::api::route::v1::TLSConfig> = None;
88                let mut value_to: Option<crate::api::route::v1::RouteTargetReference> = None;
89                let mut value_wildcard_policy: Option<String> = None;
90
91                while let Some(key) = serde::de::MapAccess::next_key::<Field>(&mut map)? {
92                    match key {
93                        Field::Key_alternate_backends => value_alternate_backends = serde::de::MapAccess::next_value(&mut map)?,
94                        Field::Key_host => value_host = Some(serde::de::MapAccess::next_value(&mut map)?),
95                        Field::Key_path => value_path = serde::de::MapAccess::next_value(&mut map)?,
96                        Field::Key_port => value_port = serde::de::MapAccess::next_value(&mut map)?,
97                        Field::Key_tls => value_tls = serde::de::MapAccess::next_value(&mut map)?,
98                        Field::Key_to => value_to = Some(serde::de::MapAccess::next_value(&mut map)?),
99                        Field::Key_wildcard_policy => value_wildcard_policy = serde::de::MapAccess::next_value(&mut map)?,
100                        Field::Other => { let _: serde::de::IgnoredAny = serde::de::MapAccess::next_value(&mut map)?; },
101                    }
102                }
103
104                Ok(RouteSpec {
105                    alternate_backends: value_alternate_backends,
106                    host: value_host.ok_or_else(|| serde::de::Error::missing_field("host"))?,
107                    path: value_path,
108                    port: value_port,
109                    tls: value_tls,
110                    to: value_to.ok_or_else(|| serde::de::Error::missing_field("to"))?,
111                    wildcard_policy: value_wildcard_policy,
112                })
113            }
114        }
115
116        deserializer.deserialize_struct(
117            "RouteSpec",
118            &[
119                "alternateBackends",
120                "host",
121                "path",
122                "port",
123                "tls",
124                "to",
125                "wildcardPolicy",
126            ],
127            Visitor,
128        )
129    }
130}
131
132impl serde::Serialize for RouteSpec {
133    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
134        let mut state = serializer.serialize_struct(
135            "RouteSpec",
136            2 +
137            self.alternate_backends.as_ref().map_or(0, |_| 1) +
138            self.path.as_ref().map_or(0, |_| 1) +
139            self.port.as_ref().map_or(0, |_| 1) +
140            self.tls.as_ref().map_or(0, |_| 1) +
141            self.wildcard_policy.as_ref().map_or(0, |_| 1),
142        )?;
143        if let Some(value) = &self.alternate_backends {
144            serde::ser::SerializeStruct::serialize_field(&mut state, "alternateBackends", value)?;
145        }
146        serde::ser::SerializeStruct::serialize_field(&mut state, "host", &self.host)?;
147        if let Some(value) = &self.path {
148            serde::ser::SerializeStruct::serialize_field(&mut state, "path", value)?;
149        }
150        if let Some(value) = &self.port {
151            serde::ser::SerializeStruct::serialize_field(&mut state, "port", value)?;
152        }
153        if let Some(value) = &self.tls {
154            serde::ser::SerializeStruct::serialize_field(&mut state, "tls", value)?;
155        }
156        serde::ser::SerializeStruct::serialize_field(&mut state, "to", &self.to)?;
157        if let Some(value) = &self.wildcard_policy {
158            serde::ser::SerializeStruct::serialize_field(&mut state, "wildcardPolicy", value)?;
159        }
160        serde::ser::SerializeStruct::end(state)
161    }
162}