Skip to content

Commit 4a29f93

Browse files
authored
Port Go documentation for all types and fields (#3)
Signed-off-by: Oliver Gould <[email protected]>
1 parent b5b18b7 commit 4a29f93

13 files changed

+899
-40
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "k8s-gateway-api"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
edition = "2021"
55
license = "Apache-2.0"
66
repository = "https://github.com/linkerd/k8s-gateway-api"

LICENSE

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189+
Copyright 2020 The Kubernetes Authors
189190
Copyright 2022 The Linkerd Authors
190191

191192
Licensed under the Apache License, Version 2.0 (the "License");

README.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
11
# k8s-gateway-api
22

3-
Rust bindings for the [Kubernetes Gateway API][ref].
3+
(Unofficial) Rust bindings for the [Kubernetes Gateway API][ref].
44

55
Based on <https://github.com/kubernetes-sigs/gateway-api/releases/tag/v0.4.3>.
66

7+
[![Crates.io][crate-badge]][crate-url]
8+
[![Documentation][docs-badge]][docs-url]
9+
[![License][lic-badge]](LICENSE)
10+
11+
[crate-badge]: https://img.shields.io/crates/v/k8s-gateway-api.svg
12+
[crate-url]: https://crates.io/crates/k8s-gateway-api
13+
[docs-badge]: https://docs.rs/k8s-gateway-api/badge.svg
14+
[docs-url]: https://docs.rs/k8s-gateway-api
15+
[docs-url]: https://img.shields.io/crates/l/k8s-gateway-api
16+
[lic-badge]: https://img.shields.io/crates/l/k8s-gateway-api
17+
18+
## Status
19+
20+
This crate is experimental.
21+
22+
It defines all of the v1alpha2 Gateway API types with documentation.
23+
24+
### TODO
25+
26+
* Express validation constraints
27+
* Rustify/Linkify documentation
28+
* Support Linkerd-specific extensions (via feature flag).
29+
730
[ref]: https://gateway-api.sigs.k8s.io/

src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1+
//! Unofficial Rust bindings for the [Kubernetes Gateway API][gh].
2+
//!
3+
//! [gh]: https://github.com/kubernetes-sigs/gateway-api
4+
5+
#![deny(warnings, rust_2018_idioms)]
6+
#![forbid(unsafe_code)]
7+
8+
// TODO(ver): We should deny missing_docs, but this doesn't play with
9+
// CustomResource derivations.
10+
11+
/// The v1alpha2 API version.
112
pub mod v1alpha2;

src/v1alpha2/gateway.rs

+88-25
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct GatewaySpec {
1919
/// GatewayClass resource.
2020
pub gateway_class_name: ObjectName,
2121

22-
// Listeners associated with this Gateway. Listeners define logical
22+
/// Listeners associated with this Gateway. Listeners define logical
2323
/// endpoints that are bound on this Gateway's addresses. At least one
2424
/// Listener MUST be specified.
2525
///
@@ -59,29 +59,29 @@ pub struct GatewaySpec {
5959
/// Support: Core
6060
pub listeners: Vec<Listener>,
6161

62-
// Addresses requested for this Gateway. This is optional and behavior can
63-
// depend on the implementation. If a value is set in the spec and the
64-
// requested address is invalid or unavailable, the implementation MUST
65-
// indicate this in the associated entry in GatewayStatus.Addresses.
66-
//
67-
// The Addresses field represents a request for the address(es) on the
68-
// "outside of the Gateway", that traffic bound for this Gateway will use.
69-
// This could be the IP address or hostname of an external load balancer or
70-
// other networking infrastructure, or some other address that traffic will
71-
// be sent to.
72-
//
73-
// The .listener.hostname field is used to route traffic that has already
74-
// arrived at the Gateway to the correct in-cluster destination.
75-
//
76-
// If no Addresses are specified, the implementation MAY schedule the
77-
// Gateway in an implementation-specific manner, assigning an appropriate
78-
// set of Addresses.
79-
//
80-
// The implementation MUST bind all Listeners to every GatewayAddress that
81-
// it assigns to the Gateway and add a corresponding entry in
82-
// GatewayStatus.Addresses.
83-
//
84-
// Support: Extended
62+
/// Addresses requested for this Gateway. This is optional and behavior can
63+
/// depend on the implementation. If a value is set in the spec and the
64+
/// requested address is invalid or unavailable, the implementation MUST
65+
/// indicate this in the associated entry in GatewayStatus.Addresses.
66+
///
67+
/// The Addresses field represents a request for the address(es) on the
68+
/// "outside of the Gateway", that traffic bound for this Gateway will use.
69+
/// This could be the IP address or hostname of an external load balancer or
70+
/// other networking infrastructure, or some other address that traffic will
71+
/// be sent to.
72+
///
73+
/// The .listener.hostname field is used to route traffic that has already
74+
/// arrived at the Gateway to the correct in-cluster destination.
75+
///
76+
/// If no Addresses are specified, the implementation MAY schedule the
77+
/// Gateway in an implementation-specific manner, assigning an appropriate
78+
/// set of Addresses.
79+
///
80+
/// The implementation MUST bind all Listeners to every GatewayAddress that
81+
/// it assigns to the Gateway and add a corresponding entry in
82+
/// GatewayStatus.Addresses.
83+
///
84+
/// Support: Extended
8585
pub addresses: Option<Vec<GatewayAddress>>,
8686
}
8787

@@ -129,8 +129,43 @@ pub struct Listener {
129129
/// Support: Core
130130
pub protocol: ProtocolType,
131131

132+
/// TLS is the TLS configuration for the Listener. This field is required if
133+
/// the Protocol field is "HTTPS" or "TLS". It is invalid to set this field
134+
/// if the Protocol field is "HTTP", "TCP", or "UDP".
135+
///
136+
/// The association of SNIs to Certificate defined in GatewayTLSConfig is
137+
/// defined based on the Hostname field for this listener.
138+
///
139+
/// The GatewayClass MUST use the longest matching SNI out of all available
140+
/// certificates for any TLS handshake.
141+
///
142+
/// Support: Core
132143
pub tls: Option<GatewayTlsConfig>,
133144

145+
/// AllowedRoutes defines the types of routes that MAY be attached to a
146+
/// Listener and the trusted namespaces where those Route resources MAY be
147+
/// present.
148+
///
149+
/// Although a client request may match multiple route rules, only one rule
150+
/// may ultimately receive the request. Matching precedence MUST be
151+
/// determined in order of the following criteria:
152+
///
153+
/// * The most specific match as defined by the Route type.
154+
/// * The oldest Route based on creation timestamp. For example, a Route
155+
/// with a creation timestamp of "2020-09-08 01:02:03" is given precedence
156+
/// over a Route with a creation timestamp of "2020-09-08 01:02:04".
157+
/// * If everything else is equivalent, the Route appearing first in
158+
/// alphabetical order (namespace/name) should be given precedence. For
159+
/// example, foo/bar is given precedence over foo/baz.
160+
///
161+
/// All valid rules within a Route attached to this Listener should be
162+
/// implemented. Invalid Route rules can be ignored (sometimes that will
163+
/// mean the full Route). If a Route rule transitions from valid to invalid,
164+
/// support for that Route rule should be dropped to ensure consistency. For
165+
/// example, even if a filter specified by a Route rule is invalid, the rest
166+
/// of the rules within that Route should still be supported.
167+
///
168+
/// Support: Core
134169
pub allowed_routes: Option<AllowedRoutes>,
135170
}
136171

@@ -222,6 +257,7 @@ pub struct GatewayTlsConfig {
222257
/// TLSModeType type defines how a Gateway handles TLS sessions.
223258
pub type TlsModeType = String;
224259

260+
/// AllowedRoutes defines which Routes may be attached to this Listener.
225261
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
226262
#[serde(rename_all = "camelCase")]
227263
pub struct AllowedRoutes {
@@ -250,13 +286,28 @@ pub struct AllowedRoutes {
250286
/// Gateway.
251287
pub type FromNamespaces = String;
252288

289+
/// RouteNamespaces indicate which namespaces Routes should be selected from.
253290
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
254291
pub struct RouteNamespaces {
292+
/// From indicates where Routes will be selected for this Gateway. Possible
293+
/// values are:
294+
/// * All: Routes in all namespaces may be used by this Gateway.
295+
/// * Selector: Routes in namespaces selected by the selector may be used by
296+
/// this Gateway.
297+
/// * Same: Only Routes in the same namespace may be used by this Gateway.
298+
///
299+
/// Support: Core
255300
pub from: Option<FromNamespaces>,
256301

257-
pub selector: metav1::LabelSelector,
302+
/// Selector must be specified when From is set to "Selector". In that case,
303+
/// only Routes in Namespaces matching this Selector will be selected by this
304+
/// Gateway. This field is ignored for other values of "From".
305+
///
306+
/// Support: Core
307+
pub selector: Option<metav1::LabelSelector>,
258308
}
259309

310+
/// RouteGroupKind indicates the group and kind of a Route resource.
260311
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
261312
pub struct RouteGroupKind {
262313
/// Group is the group of the Route.
@@ -266,6 +317,7 @@ pub struct RouteGroupKind {
266317
pub kind: String,
267318
}
268319

320+
/// GatewayAddress describes an address that can be bound to a Gateway.
269321
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
270322
pub struct GatewayAddress {
271323
/// Type of the address.
@@ -278,6 +330,7 @@ pub struct GatewayAddress {
278330
pub value: String,
279331
}
280332

333+
/// GatewayStatus defines the observed state of Gateway.
281334
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
282335
pub struct GatewayStatus {
283336
/// Addresses lists the IP addresses that have actually been bound to the
@@ -302,10 +355,16 @@ pub struct GatewayStatus {
302355
pub listeners: Option<Vec<ListenerStatus>>,
303356
}
304357

358+
/// GatewayConditionType is a type of condition associated with a
359+
/// Gateway. This type should be used with the GatewayStatus.Conditions
360+
/// field.
305361
pub type GatewayConditionType = String;
306362

363+
/// GatewayConditionReason defines the set of reasons that explain why a
364+
/// particular Gateway condition type has been raised.
307365
pub type GatewayConditionReason = String;
308366

367+
/// ListenerStatus is the status associated with a Listener.
309368
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
310369
pub struct ListenerStatus {
311370
/// Name is the name of the Listener that this status corresponds to.
@@ -330,6 +389,10 @@ pub struct ListenerStatus {
330389
pub conditions: Vec<metav1::Condition>,
331390
}
332391

392+
/// ListenerConditionType is a type of condition associated with the listener.
393+
/// This type should be used with the ListenerStatus.Conditions field.
333394
pub type ListenerConditionType = String;
334395

396+
/// ListenerConditionReason defines the set of reasons that explain why a
397+
/// particular Listener condition type has been raised.
335398
pub type ListenerConditionReason = String;

src/v1alpha2/gatewayclass.rs

+37-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
use super::*;
22

3-
/// Gateway represents an instance of a service-traffic handling infrastructure
4-
/// by binding Listeners to a set of IP addresses.
3+
// GatewayClass describes a class of Gateways available to the user for creating
4+
// Gateway resources.
5+
//
6+
// It is recommended that this resource be used as a template for Gateways. This
7+
// means that a Gateway is based on the state of the GatewayClass at the time it
8+
// was created and changes to the GatewayClass or associated parameters are not
9+
// propagated down to existing Gateways. This recommendation is intended to
10+
// limit the blast radius of changes to GatewayClass or associated parameters.
11+
// If implementations choose to propagate GatewayClass changes to existing
12+
// Gateways, that MUST be clearly documented by the implementation.
13+
//
14+
// Whenever one or more Gateways are using a GatewayClass, implementations MUST
15+
// add the `gateway-exists-finalizer.gateway.networking.k8s.io` finalizer on the
16+
// associated GatewayClass. This ensures that a GatewayClass associated with a
17+
// Gateway is not deleted while in use.
18+
//
19+
// GatewayClass is a Cluster level resource.
520
#[derive(
621
Clone, Debug, kube::CustomResource, serde::Deserialize, serde::Serialize, schemars::JsonSchema,
722
)]
823
#[kube(
924
group = "gateway.networking.k8s.io/v1alpha2",
1025
version = "v1alpha2",
1126
kind = "GatewayClass",
12-
status = "GatewayClassStatus",
13-
namespaced
27+
status = "GatewayClassStatus"
1428
)]
1529
#[serde(rename_all = "camelCase")]
1630
pub struct GatewayClassSpec {
@@ -41,19 +55,36 @@ pub struct GatewayClassSpec {
4155
pub description: Option<String>,
4256
}
4357

58+
/// ParametersReference identifies an API object containing controller-specific
59+
/// configuration resource within the cluster.
4460
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
4561
pub struct ParametersReference {
62+
/// Group is the group of the referent.
4663
pub group: Group,
64+
65+
/// Kind is the kind of the referent.
4766
pub kind: Kind,
67+
68+
/// Name is the name of the referent.
4869
pub name: String,
70+
71+
/// Namespace is the namespace of the referent.
72+
///
73+
/// This field is required when referring to a Namespace-scoped resource and
74+
/// MUST be unset when referring to a Cluster-scoped resource.
4975
pub namespace: Option<String>,
5076
}
5177

78+
/// GatewayClassConditionType is the type for status conditions on
79+
/// Gateway resources. This type should be used with the
80+
/// GatewayClassStatus.Conditions field.
5281
pub type GatewayClassConditionType = String;
53-
pub type GatewayClassConditionReason = String;
5482

55-
pub type GatewayController = String;
83+
/// GatewayClassConditionReason defines the set of reasons that explain why a
84+
/// particular GatewayClass condition type has been raised.
85+
pub type GatewayClassConditionReason = String;
5686

87+
/// GatewayClassStatus is the current status for the GatewayClass.
5788
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
5889
pub struct GatewayClassStatus {
5990
/// Conditions is the current status from the controller for this

0 commit comments

Comments
 (0)