k8s_gateway_api/
shared.rs

1use k8s_openapi::apimachinery::pkg::apis::meta::v1 as metav1;
2
3use crate::BackendObjectReference;
4
5/// ParentReference identifies an API object (usually a Gateway) that can be considered
6/// a parent of this resource (usually a route). The only kind of parent resource
7/// with "Core" support is Gateway. This API may be extended in the future to
8/// support additional kinds of parent resources, such as HTTPRoute.
9///
10/// The API object must be valid in the cluster; the Group and Kind must
11/// be registered in the cluster for this reference to be valid.
12#[derive(
13    Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema,
14)]
15#[serde(rename_all = "camelCase")]
16pub struct ParentReference {
17    /// Group is the group of the referent.
18    ///
19    /// Support: Core
20    pub group: Option<Group>,
21
22    /// Kind is kind of the referent.
23    ///
24    /// Support: Core (Gateway)
25    /// Support: Custom (Other Resources)
26    pub kind: Option<Kind>,
27
28    /// Namespace is the namespace of the referent. When unspecified (or empty
29    /// string), this refers to the local namespace of the Route.
30    ///
31    /// Support: Core
32    pub namespace: Option<Namespace>,
33
34    /// Name is the name of the referent.
35    ///
36    /// Support: Core
37    pub name: ObjectName,
38
39    /// SectionName is the name of a section within the target resource. In the
40    /// following resources, SectionName is interpreted as the following:
41    ///
42    /// * Gateway: Listener Name. When both Port (experimental) and SectionName
43    /// are specified, the name and port of the selected listener must match
44    /// both specified values.
45    ///
46    /// Implementations MAY choose to support attaching Routes to other
47    /// resources.  If that is the case, they MUST clearly document how
48    /// SectionName is interpreted.
49    ///
50    /// When unspecified (empty string), this will reference the entire
51    /// resource.  For the purpose of status, an attachment is considered
52    /// successful if at least one section in the parent resource accepts it.
53    /// For example, Gateway listeners can restrict which Routes can attach to
54    /// them by Route kind, namespace, or hostname. If 1 of 2 Gateway listeners
55    /// accept attachment from the referencing Route, the Route MUST be
56    /// considered successfully attached. If no Gateway listeners accept
57    /// attachment from this Route, the Route MUST be considered detached from
58    /// the Gateway.
59    ///
60    /// Support: Core
61    pub section_name: Option<SectionName>,
62
63    /// Port is the network port this Route targets. It can be interpreted
64    /// differently based on the type of parent resource:
65    ///
66    /// * Gateway: All listeners listening on the specified port that also
67    /// support this kind of Route(and select this Route). It's not recommended
68    /// to set `Port` unless the networking behaviors specified in a Route must
69    /// apply to a specific port as opposed to a listener(s) whose port(s) may
70    /// be changed. When both Port and SectionName are specified, the name and
71    /// port of the selected listener must match both specified values.
72    ///
73    /// Implementations MAY choose to support other parent resources.
74    /// Implementations supporting other types of parent resources MUST clearly
75    /// document how/if Port is interpreted.
76    ///
77    /// For the purpose of status, an attachment is considered successful as
78    /// long as the parent resource accepts it partially. For example, Gateway
79    /// listeners can restrict which Routes can attach to them by Route kind,
80    /// namespace, or hostname. If 1 of 2 Gateway listeners accept attachment
81    /// from the referencing Route, the Route MUST be considered successfully
82    /// attached. If no Gateway listeners accept attachment from this Route, the
83    /// Route MUST be considered detached from the Gateway.
84    ///
85    /// Support: Extended
86    pub port: Option<PortNumber>,
87}
88
89/// CommonRouteSpec defines the common attributes that all Routes MUST include
90/// within their spec.
91#[derive(
92    Clone, Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema,
93)]
94#[serde(rename_all = "camelCase")]
95pub struct CommonRouteSpec {
96    /// ParentRefs references the resources (usually Gateways) that a Route
97    /// wants to be attached to. Note that the referenced parent resource needs
98    /// to allow this for the attachment to be complete. For Gateways, that
99    /// means the Gateway needs to allow attachment from Routes of this kind and
100    /// namespace.
101    ///
102    /// The only kind of parent resource with "Core" support is Gateway. This
103    /// API may be extended in the future to support additional kinds of parent
104    /// resources such as one of the route kinds.
105    ///
106    /// It is invalid to reference an identical parent more than once. It is
107    /// valid to reference multiple distinct sections within the same parent
108    /// resource, such as 2 Listeners within a Gateway.
109    ///
110    /// It is possible to separately reference multiple distinct objects that
111    /// may be collapsed by an implementation. For example, some implementations
112    /// may choose to merge compatible Gateway Listeners together. If that is
113    /// the case, the list of routes attached to those resources should also be
114    /// merged.
115    ///
116    /// Note that for ParentRefs that cross namespace boundaries, there are specific
117    /// rules. Cross-namespace references are only valid if they are explicitly
118    /// allowed by something in the namespace they are referring to. For example,
119    /// Gateway has the AllowedRoutes field, and ReferenceGrant provides a
120    /// generic way to enable other kinds of cross-namespace reference.
121    ///
122    /// ParentRefs from a Route to a Service in the same namespace are "producer"
123    /// routes, which apply default routing rules to inbound connections from
124    /// any namespace to the Service.
125    ///
126    /// ParentRefs from a Route to a Service in a different namespace are
127    /// "consumer" routes, and these routing rules are only applied to outbound
128    /// connections originating from the same namespace as the Route, for which
129    /// the intended destination of the connections are a Service targeted as a
130    /// ParentRef of the Route.
131    pub parent_refs: Option<Vec<ParentReference>>,
132}
133
134/// PortNumber defines a network port.
135pub type PortNumber = u16;
136
137/// BackendRef defines how a Route should forward a request to a Kubernetes
138/// resource.
139///
140/// Note that when a namespace is specified, a ReferencePolicy object is
141/// required in the referent namespace to allow that namespace's owner to accept
142/// the reference. See the ReferencePolicy documentation for details.
143#[derive(
144    Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema,
145)]
146pub struct BackendRef {
147    /// Weight specifies the proportion of requests forwarded to the referenced
148    /// backend. This is computed as weight/(sum of all weights in this
149    /// BackendRefs list). For non-zero values, there may be some epsilon from
150    /// the exact proportion defined here depending on the precision an
151    /// implementation supports. Weight is not a percentage and the sum of
152    /// weights does not need to equal 100.
153    ///
154    /// If only one backend is specified and it has a weight greater than 0,
155    /// 100% of the traffic is forwarded to that backend. If weight is set to 0,
156    /// no traffic should be forwarded for this entry. If unspecified, weight
157    /// defaults to 1.
158    ///
159    /// Support for this field varies based on the context where used.
160    pub weight: Option<u16>,
161
162    /// BackendObjectReference references a Kubernetes object.
163    #[serde(flatten)]
164    pub inner: BackendObjectReference,
165}
166
167/// RouteConditionType is a type of condition for a route.
168pub type RouteConditionType = String;
169
170/// RouteConditionReason is a reason for a route condition.
171pub type RouteConditionReason = String;
172
173/// RouteParentStatus describes the status of a route with respect to an
174/// associated Parent.
175#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
176#[serde(rename_all = "camelCase")]
177pub struct RouteParentStatus {
178    /// ParentRef corresponds with a ParentRef in the spec that this
179    /// RouteParentStatus struct describes the status of.
180    pub parent_ref: ParentReference,
181
182    /// ControllerName is a domain/path string that indicates the name of the
183    /// controller that wrote this status. This corresponds with the
184    /// controllerName field on GatewayClass.
185    ///
186    /// Example: "example.net/gateway-controller".
187    ///
188    /// The format of this field is DOMAIN "/" PATH, where DOMAIN and PATH are
189    /// valid Kubernetes [names][names].
190    ///
191    /// Controllers MUST populate this field when writing status. Controllers should ensure that
192    /// entries to status populated with their ControllerName are cleaned up when they are no
193    /// longer necessary.
194    ///
195    /// [names]: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
196    pub controller_name: GatewayController,
197
198    /// Conditions describes the status of the route with respect to the
199    /// Gateway. Note that the route's availability is also subject to the
200    /// Gateway's own status conditions and listener status.
201    ///
202    /// If the Route's ParentRef specifies an existing Gateway that supports
203    /// Routes of this kind AND that Gateway's controller has sufficient access,
204    /// then that Gateway's controller MUST set the "Accepted" condition on the
205    /// Route, to indicate whether the route has been accepted or rejected by
206    /// the Gateway, and why.
207    ///
208    /// A Route MUST be considered "Accepted" if at least one of the Route's
209    /// rules is implemented by the Gateway.
210    ///
211    /// There are a number of cases where the "Accepted" condition may not be
212    /// set due to lack of controller visibility, that includes when:
213    ///
214    /// * The Route refers to a non-existent parent.
215    /// * The Route is of a type that the controller does not support.
216    /// * The Route is in a namespace the the controller does not have access to.
217    pub conditions: Vec<metav1::Condition>,
218}
219
220/// RouteStatus defines the common attributes that all Routes MUST include
221/// within their status.
222#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
223pub struct RouteStatus {
224    /// Parents is a list of parent resources (usually Gateways) that are
225    /// associated with the route, and the status of the route with respect to
226    /// each parent. When this route attaches to a parent, the controller that
227    /// manages the parent must add an entry to this list when the controller
228    /// first sees the route and should update the entry as appropriate when the
229    /// route or gateway is modified.
230    ///
231    /// Note that parent references that cannot be resolved by an implementation
232    /// of this API will not be added to this list. Implementations of this API
233    /// can only populate Route status for the Gateways/parent resources they
234    /// are responsible for.
235    ///
236    /// A maximum of 32 Gateways will be represented in this list. An empty list
237    /// means the route has not been attached to any Gateway.
238    pub parents: Vec<RouteParentStatus>,
239}
240
241/// Hostname is the fully qualified domain name of a network host. This matches
242/// the RFC 1123 definition of a hostname with 2 notable exceptions:
243///
244/// 1. IPs are not allowed.
245/// 2. A hostname may be prefixed with a wildcard label (`*.`). The wildcard
246///    label must appear by itself as the first label.
247///
248/// Hostname can be "precise" which is a domain name without the terminating dot
249/// of a network host (e.g. "foo.example.com") or "wildcard", which is a domain
250/// name prefixed with a single wildcard label (e.g. `*.example.com`).
251///
252/// Note that as per RFC1035 and RFC1123, a *label* must consist of lower case
253/// alphanumeric characters or '-', and must start and end with an alphanumeric
254/// character. No other punctuation is allowed.
255pub type Hostname = String;
256
257/// PreciseHostname is the fully qualified domain name of a network host. This
258/// matches the RFC 1123 definition of a hostname with 1 notable exception that
259/// numeric IP addresses are not allowed.
260///
261/// Note that as per RFC1035 and RFC1123, a *label* must consist of lower case
262/// alphanumeric characters or '-', and must start and end with an alphanumeric
263/// character. No other punctuation is allowed.
264pub type PreciseHostname = String;
265
266/// Group refers to a Kubernetes Group. It must either be an empty string or a
267/// RFC 1123 subdomain.
268///
269/// This validation is based off of the corresponding Kubernetes validation:
270/// <https://github.com/kubernetes/apimachinery/blob/02cfb53916346d085a6c6c7c66f882e3c6b0eca6/pkg/util/validation/validation.go#L208>
271///
272/// Valid values include:
273///
274/// * "" - empty string implies core Kubernetes API group
275/// * "networking.k8s.io"
276/// * "foo.example.com"
277///
278/// Invalid values include:
279///
280/// * "example.com/bar" - "/" is an invalid character
281pub type Group = String;
282
283/// Kind refers to a Kubernetes Kind.
284///
285/// Valid values include:
286///
287/// * "Service"
288/// * "HTTPRoute"
289///
290/// Invalid values include:
291///
292/// * "invalid/kind" - "/" is an invalid character
293pub type Kind = String;
294
295/// ObjectName refers to the name of a Kubernetes object.
296///
297/// Object names can have a variety of forms, including RFC1123 subdomains, RFC
298/// 1123 labels, or RFC 1035 labels.
299pub type ObjectName = String;
300
301/// Namespace refers to a Kubernetes namespace. It must be a RFC 1123 label.
302///
303/// This validation is based off of the corresponding Kubernetes validation:
304/// <https://github.com/kubernetes/apimachinery/blob/02cfb53916346d085a6c6c7c66f882e3c6b0eca6/pkg/util/validation/validation.go#L187>
305///
306/// This is used for Namespace name validation here:
307/// <https://github.com/kubernetes/apimachinery/blob/02cfb53916346d085a6c6c7c66f882e3c6b0eca6/pkg/api/validation/generic.go#L63>
308///
309/// Valid values include:
310///
311/// * "example"
312///
313/// Invalid values include:
314///
315/// * "example.com" - "." is an invalid character
316pub type Namespace = String;
317
318/// SectionName is the name of a section in a Kubernetes resource.
319///
320/// This validation is based off of the corresponding Kubernetes validation:
321/// <https://github.com/kubernetes/apimachinery/blob/02cfb53916346d085a6c6c7c66f882e3c6b0eca6/pkg/util/validation/validation.go#L208>
322///
323/// Valid values include:
324///
325/// * "example.com"
326/// * "foo.example.com"
327///
328/// Invalid values include:
329///
330/// * "example.com/bar" - "/" is an invalid character
331pub type SectionName = String;
332
333/// GatewayController is the name of a Gateway API controller. It must be a
334/// domain prefixed path.
335///
336/// Valid values include:
337///
338/// * "example.com/bar"
339///
340/// Invalid values include:
341///
342/// * "example.com" - must include path
343/// * "foo.example.com" - must include path
344pub type GatewayController = String;
345
346/// AnnotationKey is the key of an annotation in Gateway API. This is used for
347/// validation of maps such as TLS options. This matches the Kubernetes
348/// "qualified name" validation that is used for annotations and other common
349/// values.
350///
351/// Valid values include:
352///
353/// * example
354/// * example.com
355/// * example.com/path
356/// * example.com/path.html
357///
358/// Invalid values include:
359///
360/// * example~ - "~" is an invalid character
361/// * example.com. - can not start or end with "."
362pub type AnnotationKey = String;
363
364/// AnnotationValue is the value of an annotation in Gateway API. This is used
365/// for validation of maps such as TLS options. This roughly matches Kubernetes
366/// annotation validation, although the length validation in that case is based
367/// on the entire size of the annotations struct.
368pub type AnnotationValue = String;
369
370/// AddressType defines how a network address is represented as a text string.
371pub type AddressType = String;