|
| 1 | +/* |
| 2 | +Copyright 2020 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1alpha3 |
| 18 | + |
| 19 | +import ( |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | + |
| 22 | + "sigs.k8s.io/gateway-api/apis/v1alpha2" |
| 23 | +) |
| 24 | + |
| 25 | +// +genclient |
| 26 | +// +kubebuilder:object:root=true |
| 27 | +// +kubebuilder:resource:categories=gateway-api |
| 28 | +// +kubebuilder:subresource:status |
| 29 | +// +kubebuilder:storageversion |
| 30 | +// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` |
| 31 | + |
| 32 | +// The TLSRoute resource is similar to TCPRoute, but can be configured |
| 33 | +// to match against TLS-specific metadata. This allows more flexibility |
| 34 | +// in matching streams for a given TLS listener. |
| 35 | +// |
| 36 | +// If you need to forward traffic to a single target for a TLS listener, you |
| 37 | +// could choose to use a TCPRoute with a TLS listener. |
| 38 | +type TLSRoute struct { |
| 39 | + metav1.TypeMeta `json:",inline"` |
| 40 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 41 | + |
| 42 | + // Spec defines the desired state of TLSRoute. |
| 43 | + Spec TLSRouteSpec `json:"spec"` |
| 44 | + |
| 45 | + // Status defines the current state of TLSRoute. |
| 46 | + Status v1alpha2.TLSRouteStatus `json:"status,omitempty"` |
| 47 | +} |
| 48 | + |
| 49 | +// TLSRouteSpec defines the desired state of a TLSRoute resource. |
| 50 | +type TLSRouteSpec struct { |
| 51 | + CommonRouteSpec `json:",inline"` |
| 52 | + |
| 53 | + // Hostnames defines a set of SNI hostnames that should match against the |
| 54 | + // SNI attribute of TLS ClientHello message in TLS handshake. This matches |
| 55 | + // the RFC 1123 definition of a hostname with 2 notable exceptions: |
| 56 | + // |
| 57 | + // 1. IPs are not allowed in SNI hostnames per RFC 6066. |
| 58 | + // 2. A hostname may be prefixed with a wildcard label (`*.`). The wildcard |
| 59 | + // label must appear by itself as the first label. |
| 60 | + // |
| 61 | + // If a hostname is specified by both the Listener and TLSRoute, there |
| 62 | + // must be at least one intersecting hostname for the TLSRoute to be |
| 63 | + // attached to the Listener. For example: |
| 64 | + // |
| 65 | + // * A Listener with `test.example.com` as the hostname matches TLSRoutes |
| 66 | + // that have either not specified any hostnames, or have specified at |
| 67 | + // least one of `test.example.com` or `*.example.com`. |
| 68 | + // * A Listener with `*.example.com` as the hostname matches TLSRoutes |
| 69 | + // that have either not specified any hostnames or have specified at least |
| 70 | + // one hostname that matches the Listener hostname. For example, |
| 71 | + // `test.example.com` and `*.example.com` would both match. On the other |
| 72 | + // hand, `example.com` and `test.example.net` would not match. |
| 73 | + // |
| 74 | + // If both the Listener and TLSRoute have specified hostnames, any |
| 75 | + // TLSRoute hostnames that do not match the Listener hostname MUST be |
| 76 | + // ignored. For example, if a Listener specified `*.example.com`, and the |
| 77 | + // TLSRoute specified `test.example.com` and `test.example.net`, |
| 78 | + // `test.example.net` must not be considered for a match. |
| 79 | + // |
| 80 | + // If both the Listener and TLSRoute have specified hostnames, and none |
| 81 | + // match with the criteria above, then the TLSRoute is not accepted. The |
| 82 | + // implementation must raise an 'Accepted' Condition with a status of |
| 83 | + // `False` in the corresponding RouteParentStatus. |
| 84 | + // |
| 85 | + // Support: Core |
| 86 | + // |
| 87 | + // +kubebuilder:validation:MinItems=1 |
| 88 | + // +kubebuilder:validation:MaxItems=16 |
| 89 | + Hostnames []Hostname `json:"hostnames,omitempty"` |
| 90 | + |
| 91 | + // Rules are a list of TLS matchers and actions. |
| 92 | + // |
| 93 | + // +kubebuilder:validation:MinItems=1 |
| 94 | + // +kubebuilder:validation:MaxItems=16 |
| 95 | + // <gateway:experimental:validation:XValidation:message="Rule name must be unique within the route",rule="self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name))"> |
| 96 | + Rules []v1alpha2.TLSRouteRule `json:"rules"` |
| 97 | +} |
| 98 | + |
| 99 | +// +kubebuilder:object:root=true |
| 100 | + |
| 101 | +// TLSRouteList contains a list of TLSRoute |
| 102 | +type TLSRouteList struct { |
| 103 | + metav1.TypeMeta `json:",inline"` |
| 104 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 105 | + Items []TLSRoute `json:"items"` |
| 106 | +} |
0 commit comments