k8s_gateway_api/
gateway.rs

1use crate::*;
2use k8s_openapi::apimachinery::pkg::apis::meta::v1 as metav1;
3use std::collections::BTreeMap;
4
5/// Gateway represents an instance of a service-traffic handling infrastructure
6/// by binding Listeners to a set of IP addresses.
7#[derive(
8    Clone, Debug, kube::CustomResource, serde::Deserialize, serde::Serialize, schemars::JsonSchema,
9)]
10#[kube(
11    group = "gateway.networking.k8s.io",
12    version = "v1beta1",
13    kind = "Gateway",
14    status = "GatewayStatus",
15    namespaced
16)]
17#[serde(rename_all = "camelCase")]
18pub struct GatewaySpec {
19    /// GatewayClassName used for this Gateway. This is the name of a
20    /// GatewayClass resource.
21    pub gateway_class_name: ObjectName,
22
23    /// Listeners associated with this Gateway. Listeners define logical
24    /// endpoints that are bound on this Gateway's addresses.  At least one
25    /// Listener MUST be specified.
26    ///
27    /// Each listener in a Gateway must have a unique combination of Hostname,
28    /// Port, and Protocol.
29    ///
30    /// An implementation MAY group Listeners by Port and then collapse each
31    /// group of Listeners into a single Listener if the implementation
32    /// determines that the Listeners in the group are "compatible". An
33    /// implementation MAY also group together and collapse compatible Listeners
34    /// belonging to different Gateways.
35    ///
36    /// For example, an implementation might consider Listeners to be compatible
37    /// with each other if all of the following conditions are met:
38    ///
39    /// 1. Either each Listener within the group specifies the "HTTP" Protocol or
40    /// each Listener within the group specifies either the "HTTPS" or "TLS"
41    /// Protocol.
42    ///
43    /// 2. Each Listener within the group specifies a Hostname that is unique
44    /// within the group.
45    ///
46    /// 3. As a special case, one Listener within a group may omit Hostname, in
47    /// which case this Listener matches when no other Listener matches.
48    ///
49    /// If the implementation does collapse compatible Listeners, the hostname
50    /// provided in the incoming client request MUST be matched to a Listener to
51    /// find the correct set of Routes.  The incoming hostname MUST be matched
52    /// using the Hostname field for each Listener in order of most to least
53    /// specific. That is, exact matches must be processed before wildcard
54    /// matches.
55    ///
56    /// If this field specifies multiple Listeners that have the same Port value
57    /// but are not compatible, the implementation must raise a "Conflicted"
58    /// condition in the Listener status.
59    ///
60    /// Support: Core
61    pub listeners: Vec<Listener>,
62
63    /// Addresses requested for this Gateway. This is optional and behavior can
64    /// depend on the implementation. If a value is set in the spec and the
65    /// requested address is invalid or unavailable, the implementation MUST
66    /// indicate this in the associated entry in GatewayStatus.Addresses.
67    ///
68    /// The Addresses field represents a request for the address(es) on the
69    /// "outside of the Gateway", that traffic bound for this Gateway will use.
70    /// This could be the IP address or hostname of an external load balancer or
71    /// other networking infrastructure, or some other address that traffic will
72    /// be sent to.
73    ///
74    /// The .listener.hostname field is used to route traffic that has already
75    /// arrived at the Gateway to the correct in-cluster destination.
76    ///
77    /// If no Addresses are specified, the implementation MAY schedule the
78    /// Gateway in an implementation-specific manner, assigning an appropriate
79    /// set of Addresses.
80    ///
81    /// The implementation MUST bind all Listeners to every GatewayAddress that
82    /// it assigns to the Gateway and add a corresponding entry in
83    /// GatewayStatus.Addresses.
84    ///
85    /// Support: Extended
86    pub addresses: Option<Vec<GatewayAddress>>,
87}
88
89/// Listener embodies the concept of a logical endpoint where a Gateway accepts
90/// network connections.
91#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
92#[serde(rename_all = "camelCase")]
93pub struct Listener {
94    /// Name is the name of the Listener. This name MUST be unique within a
95    /// Gateway.
96    ///
97    /// Support: Core
98    pub name: String,
99
100    /// Hostname specifies the virtual hostname to match for protocol types that
101    /// define this concept. When unspecified, all hostnames are matched. This
102    /// field is ignored for protocols that don't require hostname based
103    /// matching.
104    ///
105    /// Implementations MUST apply Hostname matching appropriately for each of
106    /// the following protocols:
107    ///
108    /// * TLS: The Listener Hostname MUST match the SNI.  * HTTP: The Listener
109    /// Hostname MUST match the Host header of the request.  * HTTPS: The
110    /// Listener Hostname SHOULD match at both the TLS and HTTP protocol layers
111    /// as described above. If an implementation does not ensure that both the
112    /// SNI and Host header match the Listener hostname, it MUST clearly document
113    /// that.
114    ///
115    /// For HTTPRoute and TLSRoute resources, there is an interaction with the
116    /// `spec.hostnames` array. When both listener and route specify hostnames,
117    /// there MUST be an intersection between the values for a Route to be
118    /// accepted. For more information, refer to the Route specific Hostnames
119    /// documentation.
120    ///
121    /// Support: Core
122    pub hostname: Option<Hostname>,
123
124    /// Port is the network port. Multiple listeners may use the same port,
125    /// subject to the Listener compatibility rules.
126    pub port: PortNumber,
127
128    /// Protocol specifies the network protocol this listener expects to receive.
129    ///
130    /// Support: Core
131    pub protocol: ProtocolType,
132
133    /// TLS is the TLS configuration for the Listener. This field is required if
134    /// the Protocol field is "HTTPS" or "TLS". It is invalid to set this field
135    /// if the Protocol field is "HTTP", "TCP", or "UDP".
136    ///
137    /// The association of SNIs to Certificate defined in GatewayTLSConfig is
138    /// defined based on the Hostname field for this listener.
139    ///
140    /// The GatewayClass MUST use the longest matching SNI out of all available
141    /// certificates for any TLS handshake.
142    ///
143    /// Support: Core
144    pub tls: Option<GatewayTlsConfig>,
145
146    /// AllowedRoutes defines the types of routes that MAY be attached to a
147    /// Listener and the trusted namespaces where those Route resources MAY be
148    /// present.
149    ///
150    /// Although a client request may match multiple route rules, only one rule
151    /// may ultimately receive the request. Matching precedence MUST be
152    /// determined in order of the following criteria:
153    ///
154    /// * The most specific match as defined by the Route type.
155    /// * The oldest Route based on creation timestamp. For example, a Route
156    ///   with a creation timestamp of "2020-09-08 01:02:03" is given precedence
157    ///   over a Route with a creation timestamp of "2020-09-08 01:02:04".
158    /// * If everything else is equivalent, the Route appearing first in
159    ///   alphabetical order (namespace/name) should be given precedence. For
160    ///   example, foo/bar is given precedence over foo/baz.
161    ///
162    /// All valid rules within a Route attached to this Listener should be
163    /// implemented. Invalid Route rules can be ignored (sometimes that will
164    /// mean the full Route). If a Route rule transitions from valid to invalid,
165    /// support for that Route rule should be dropped to ensure consistency. For
166    /// example, even if a filter specified by a Route rule is invalid, the rest
167    /// of the rules within that Route should still be supported.
168    ///
169    /// Support: Core
170    pub allowed_routes: Option<AllowedRoutes>,
171}
172
173/// ProtocolType defines the application protocol accepted by a Listener.
174/// Implementations are not required to accept all the defined protocols.
175/// If an implementation does not support a specified protocol, it
176/// should raise a "Detached" condition for the affected Listener with
177/// a reason of "UnsupportedProtocol".
178///
179/// Core ProtocolType values are listed in the table below.
180///
181/// Implementations can define their own protocols if a core ProtocolType does not
182/// exist. Such definitions must use prefixed name, such as
183/// `mycompany.com/my-custom-protocol`. Un-prefixed names are reserved for core
184/// protocols. Any protocol defined by implementations will fall under custom
185/// conformance.
186///
187/// Valid values include:
188///
189/// * "HTTP" - Core support
190/// * "example.com/bar" - Implementation-specific support
191///
192/// Invalid values include:
193///
194/// * "example.com" - must include path if domain is used
195/// * "foo.example.com" - must include path if domain is used
196///
197pub type ProtocolType = String;
198
199/// GatewayTLSConfig describes a TLS configuration.
200#[derive(
201    Clone, Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema,
202)]
203#[serde(rename_all = "camelCase")]
204pub struct GatewayTlsConfig {
205    /// Mode defines the TLS behavior for the TLS session initiated by the
206    /// client.  There are two possible modes:
207    ///
208    /// - Terminate: The TLS session between the downstream client and the
209    ///   Gateway is terminated at the Gateway. This mode requires
210    ///   certificateRefs to be set and contain at least one element.
211    /// - Passthrough: The TLS session is NOT terminated by the Gateway. This
212    ///   implies that the Gateway can't decipher the TLS stream except for the
213    ///   ClientHello message of the TLS protocol. CertificateRefs field is
214    ///   ignored in this mode.
215    ///
216    /// Support: Core
217    pub mode: Option<TlsModeType>,
218
219    /// CertificateRefs contains a series of references to Kubernetes objects
220    /// that contains TLS certificates and private keys. These certificates are
221    /// used to establish a TLS handshake for requests that match the hostname
222    /// of the associated listener.
223    ///
224    /// A single CertificateRef to a Kubernetes Secret has "Core" support.
225    /// Implementations MAY choose to support attaching multiple certificates to
226    /// a Listener, but this behavior is implementation-specific.
227    ///
228    /// References to a resource in different namespace are invalid UNLESS there
229    /// is a ReferencePolicy in the target namespace that allows the certificate
230    /// to be attached. If a ReferencePolicy does not allow this reference, the
231    /// "ResolvedRefs" condition MUST be set to False for this listener with the
232    /// "InvalidCertificateRef" reason.
233    ///
234    /// This field is required to have at least one element when the mode is set
235    /// to "Terminate" (default) and is optional otherwise.
236    ///
237    /// CertificateRefs can reference to standard Kubernetes resources, i.e.
238    /// Secret, or implementation-specific custom resources.
239    ///
240    /// Support: Core - A single reference to a Kubernetes Secret of type
241    /// kubernetes.io/tls
242    ///
243    /// Support: Implementation-specific (More than one reference or other
244    /// resource types)
245    pub certificate_refs: Option<Vec<SecretObjectReference>>,
246
247    /// Options are a list of key/value pairs to enable extended TLS
248    /// configuration for each implementation. For example, configuring the
249    /// minimum TLS version or supported cipher suites.
250    ///
251    /// A set of common keys MAY be defined by the API in the future. To avoid
252    /// any ambiguity, implementation-specific definitions MUST use
253    /// domain-prefixed names, such as `example.com/my-custom-option`.
254    /// Un-prefixed names are reserved for key names defined by Gateway API.
255    ///
256    /// Support: Implementation-specific
257    pub options: Option<BTreeMap<String, String>>,
258}
259
260/// TLSModeType type defines how a Gateway handles TLS sessions.
261pub type TlsModeType = String;
262
263/// AllowedRoutes defines which Routes may be attached to this Listener.
264#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
265#[serde(rename_all = "camelCase")]
266pub struct AllowedRoutes {
267    /// Namespaces indicates namespaces from which Routes may be attached to
268    /// this Listener. This is restricted to the namespace of this Gateway by
269    /// default.
270    ///
271    /// Support: Core
272    pub namespaces: Option<RouteNamespaces>,
273
274    /// Kinds specifies the groups and kinds of Routes that are allowed to bind
275    /// to this Gateway Listener. When unspecified or empty, the kinds of Routes
276    /// selected are determined using the Listener protocol.
277    ///
278    /// A RouteGroupKind MUST correspond to kinds of Routes that are compatible
279    /// with the application protocol specified in the Listener's Protocol
280    /// field.  If an implementation does not support or recognize this resource
281    /// type, it MUST set the "ResolvedRefs" condition to False for this
282    /// Listener with the "InvalidRouteKinds" reason.
283    ///
284    /// Support: Core
285    pub kinds: Option<Vec<RouteGroupKind>>,
286}
287
288/// FromNamespaces specifies namespace from which Routes may be attached to a
289/// Gateway.
290pub type FromNamespaces = String;
291
292/// RouteNamespaces indicate which namespaces Routes should be selected from.
293#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
294pub struct RouteNamespaces {
295    /// From indicates where Routes will be selected for this Gateway. Possible
296    /// values are:
297    /// * All: Routes in all namespaces may be used by this Gateway.
298    /// * Selector: Routes in namespaces selected by the selector may be used by
299    ///   this Gateway.
300    /// * Same: Only Routes in the same namespace may be used by this Gateway.
301    ///
302    /// Support: Core
303    pub from: Option<FromNamespaces>,
304
305    /// Selector must be specified when From is set to "Selector". In that case,
306    /// only Routes in Namespaces matching this Selector will be selected by this
307    /// Gateway. This field is ignored for other values of "From".
308    ///
309    /// Support: Core
310    pub selector: Option<metav1::LabelSelector>,
311}
312
313/// RouteGroupKind indicates the group and kind of a Route resource.
314#[derive(
315    Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema,
316)]
317pub struct RouteGroupKind {
318    /// Group is the group of the Route.
319    pub group: Option<String>,
320
321    /// Kind is the kind of the Route.
322    pub kind: String,
323}
324
325/// GatewayAddress describes an address that can be bound to a Gateway.
326#[derive(
327    Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema,
328)]
329pub struct GatewayAddress {
330    /// Type of the address.
331    pub r#type: Option<AddressType>,
332
333    /// Value of the address. The validity of the values will depend on the type
334    /// and support by the controller.
335    ///
336    /// Examples: `1.2.3.4`, `128::1`, `my-ip-address`.
337    pub value: String,
338}
339
340/// GatewayStatus defines the observed state of Gateway.
341#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
342pub struct GatewayStatus {
343    /// Addresses lists the IP addresses that have actually been bound to the
344    /// Gateway. These addresses may differ from the addresses in the Spec, e.g.
345    /// if the Gateway automatically assigns an address from a reserved pool.
346    pub addresses: Option<Vec<GatewayAddress>>,
347
348    /// Conditions describe the current conditions of the Gateway.
349    ///
350    /// Implementations should prefer to express Gateway conditions using the
351    /// `GatewayConditionType` and `GatewayConditionReason` constants so that
352    /// operators and tools can converge on a common vocabulary to describe
353    /// Gateway state.
354    ///
355    /// Known condition types are:
356    ///
357    /// * "Scheduled"
358    /// * "Ready"
359    pub conditions: Option<Vec<metav1::Condition>>,
360
361    /// Routes is a list of routes bound to the Gateway.
362    pub listeners: Option<Vec<ListenerStatus>>,
363}
364
365/// GatewayConditionType is a type of condition associated with a
366/// Gateway. This type should be used with the GatewayStatus.Conditions
367/// field.
368pub type GatewayConditionType = String;
369
370/// GatewayConditionReason defines the set of reasons that explain why a
371/// particular Gateway condition type has been raised.
372pub type GatewayConditionReason = String;
373
374/// ListenerStatus is the status associated with a Listener.
375#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
376#[serde(rename_all = "camelCase")]
377pub struct ListenerStatus {
378    /// Name is the name of the Listener that this status corresponds to.
379    pub name: SectionName,
380
381    /// SupportedKinds is the list indicating the Kinds supported by this
382    /// listener. This MUST represent the kinds an implementation supports for
383    /// that Listener configuration.
384    ///
385    /// If kinds are specified in Spec that are not supported, they MUST NOT
386    /// appear in this list and an implementation MUST set the "ResolvedRefs"
387    /// condition to "False" with the "InvalidRouteKinds" reason. If both valid
388    /// and invalid Route kinds are specified, the implementation MUST reference
389    /// the valid Route kinds that have been specified.
390    pub supported_kinds: Vec<RouteGroupKind>,
391
392    /// AttachedRoutes represents the total number of Routes that have been
393    /// successfully attached to this Listener.
394    pub attached_routes: u16,
395
396    /// Conditions describe the current condition of this listener.
397    pub conditions: Vec<metav1::Condition>,
398}
399
400/// ListenerConditionType is a type of condition associated with the listener.
401/// This type should be used with the ListenerStatus.Conditions field.
402pub type ListenerConditionType = String;
403
404/// ListenerConditionReason defines the set of reasons that explain why a
405/// particular Listener condition type has been raised.
406pub type ListenerConditionReason = String;