Skip to content

Commit 07b2851

Browse files
committed
implement GEP-718: rework RouteForwardTo
For #718
1 parent 6d30ac6 commit 07b2851

15 files changed

+671
-869
lines changed

apis/v1alpha2/httproute_types.go

+24-101
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,19 @@ type HTTPRouteRule struct {
240240
// +kubebuilder:validation:MaxItems=16
241241
Filters []HTTPRouteFilter `json:"filters,omitempty"`
242242

243-
// ForwardTo defines the backend(s) where matching requests should be sent.
244-
// If unspecified, the rule performs no forwarding. If unspecified and no
245-
// filters are specified that would result in a response being sent, a 503
246-
// error code is returned.
243+
// BackendRefs defines the backend(s) where matching requests should be
244+
// sent. If unspecified, the rule performs no forwarding. If unspecified and
245+
// no filters are specified that would result in a response being sent,
246+
// a HTTP 503 status code is returned.
247+
//
248+
// Support: Core for Kubernetes Service
249+
// Support: Custom for any other resource
250+
//
251+
// Support for weight: Core
247252
//
248253
// +optional
249254
// +kubebuilder:validation:MaxItems=16
250-
ForwardTo []HTTPRouteForwardTo `json:"forwardTo,omitempty"`
255+
BackendRefs []HTTPBackendRef `json:"backendRefs,omitempty"`
251256
}
252257

253258
// PathMatchType specifies the semantics of how HTTP paths should be compared.
@@ -563,7 +568,7 @@ const (
563568
//
564569
// Support in HTTPRouteRule: Core
565570
//
566-
// Support in HTTPRouteForwardTo: Extended
571+
// Support in HTTPBackendRef: Extended
567572
HTTPRouteFilterRequestHeaderModifier HTTPRouteFilterType = "RequestHeaderModifier"
568573

569574
// HTTPRouteFilterRequestRedirect can be used to redirect a request to
@@ -572,7 +577,7 @@ const (
572577
//
573578
// Support in HTTPRouteRule: Core
574579
//
575-
// Support in HTTPRouteForwardTo: Extended
580+
// Support in HTTPBackendRef: Extended
576581
HTTPRouteFilterRequestRedirect HTTPRouteFilterType = "RequestRedirect"
577582

578583
// HTTPRouteFilterRequestMirror can be used to mirror HTTP requests to a
@@ -581,15 +586,15 @@ const (
581586
//
582587
// Support in HTTPRouteRule: Extended
583588
//
584-
// Support in HTTPRouteForwardTo: Extended
589+
// Support in HTTPBackendRef: Extended
585590
HTTPRouteFilterRequestMirror HTTPRouteFilterType = "RequestMirror"
586591

587592
// HTTPRouteFilterExtensionRef should be used for configuring custom
588593
// HTTP filters.
589594
//
590595
// Support in HTTPRouteRule: Custom
591596
//
592-
// Support in HTTPRouteForwardTo: Custom
597+
// Support in HTTPBackendRef: Custom
593598
HTTPRouteFilterExtensionRef HTTPRouteFilterType = "ExtensionRef"
594599
)
595600

@@ -716,112 +721,30 @@ type HTTPRequestRedirect struct {
716721

717722
// HTTPRequestMirrorFilter defines configuration for the RequestMirror filter.
718723
type HTTPRequestMirrorFilter struct {
719-
// ServiceName refers to the name of the Service to mirror matched requests
720-
// to. When specified, this takes the place of BackendRef. If both
721-
// BackendRef and ServiceName are specified, ServiceName will be given
722-
// precedence.
724+
// BackendRef references a resource where mirrored requests are sent.
723725
//
724726
// If the referent cannot be found, the rule is not included in the route.
725727
// The controller should raise the "ResolvedRefs" condition on the Gateway
726728
// with the "DegradedRoutes" reason. The gateway status for this route should
727729
// be updated with a condition that describes the error more specifically.
728730
//
729-
// Support: Core
731+
// Support: Extended for Kubernetes Service
732+
// Support: Custom for any other resource
730733
//
731734
// +optional
732-
// +kubebuilder:validation:MaxLength=253
733-
ServiceName *string `json:"serviceName,omitempty"`
735+
BackendRef *BackendObjectReference `json:"backendRef,omitempty"`
736+
}
734737

735-
// BackendRef is a local object reference to mirror matched requests to. If
736-
// both BackendRef and ServiceName are specified, ServiceName will be given
737-
// precedence.
738+
// HTTPBackendRef defines how a HTTPRoute should forward an HTTP request.
739+
type HTTPBackendRef struct {
740+
// BackendRef defines how a Route should forward a request to a Kubernetes
741+
// resource.
738742
//
739743
// If the referent cannot be found, the rule is not included in the route.
740744
// The controller should raise the "ResolvedRefs" condition on the Gateway
741745
// with the "DegradedRoutes" reason. The gateway status for this route should
742746
// be updated with a condition that describes the error more specifically.
743-
//
744-
// Support: Custom
745-
//
746-
// +optional
747-
BackendRef *LocalObjectReference `json:"backendRef,omitempty"`
748-
749-
// Port specifies the destination port number to use for the
750-
// backend referenced by the ServiceName or BackendRef field.
751-
//
752-
// If unspecified, the destination port in the request is used
753-
// when forwarding to a backendRef or serviceName.
754-
//
755-
// +optional
756-
Port *PortNumber `json:"port,omitempty"`
757-
}
758-
759-
// HTTPRouteForwardTo defines how a HTTPRoute should forward a request.
760-
type HTTPRouteForwardTo struct {
761-
// ServiceName refers to the name of the Service to forward matched requests
762-
// to. When specified, this takes the place of BackendRef. If both
763-
// BackendRef and ServiceName are specified, ServiceName will be given
764-
// precedence.
765-
//
766-
// If the referent cannot be found, the route must be dropped
767-
// from the Gateway. The controller should raise the "ResolvedRefs"
768-
// condition on the Gateway with the "DegradedRoutes" reason.
769-
// The gateway status for this route should be updated with a
770-
// condition that describes the error more specifically.
771-
//
772-
// The protocol to use should be specified with the AppProtocol field on
773-
// Service resources.
774-
//
775-
// Support: Core
776-
//
777-
// +optional
778-
// +kubebuilder:validation:MaxLength=253
779-
ServiceName *string `json:"serviceName,omitempty"`
780-
781-
// BackendRef is a reference to a backend to forward matched requests to. If
782-
// both BackendRef and ServiceName are specified, ServiceName will be given
783-
// precedence.
784-
//
785-
// If the referent cannot be found, the route must be dropped
786-
// from the Gateway. The controller should raise the "ResolvedRefs"
787-
// condition on the Gateway with the "DegradedRoutes" reason.
788-
// The gateway status for this route should be updated with a
789-
// condition that describes the error more specifically.
790-
//
791-
// Support: Custom
792-
//
793-
// +optional
794-
BackendRef *LocalObjectReference `json:"backendRef,omitempty"`
795-
796-
// Port specifies the destination port number to use for the
797-
// backend referenced by the ServiceName or BackendRef field.
798-
// If unspecified, the destination port in the request is used
799-
// when forwarding to a backendRef or serviceName.
800-
//
801-
// Support: Core
802-
//
803-
// +optional
804-
Port *PortNumber `json:"port,omitempty"`
805-
806-
// Weight specifies the proportion of HTTP requests forwarded to the backend
807-
// referenced by the ServiceName or BackendRef field. This is computed as
808-
// weight/(sum of all weights in this ForwardTo list). For non-zero values,
809-
// there may be some epsilon from the exact proportion defined here
810-
// depending on the precision an implementation supports. Weight is not a
811-
// percentage and the sum of weights does not need to equal 100.
812-
//
813-
// If only one backend is specified and it has a weight greater than 0, 100%
814-
// of the traffic is forwarded to that backend. If weight is set to 0,
815-
// traffic must not be forwarded for this entry. If unspecified, weight
816-
// defaults to 1.
817-
//
818-
// Support: Core
819-
//
820-
// +optional
821-
// +kubebuilder:default=1
822-
// +kubebuilder:validation:Minimum=0
823-
// +kubebuilder:validation:Maximum=1000000
824-
Weight *int32 `json:"weight,omitempty"`
747+
BackendRef `json:",inline"`
825748

826749
// Filters defined at this-level should be executed if and only if the
827750
// request is being forwarded to the backend defined here.

apis/v1alpha2/shared_types.go

+31-37
Original file line numberDiff line numberDiff line change
@@ -77,53 +77,47 @@ type GatewayReference struct {
7777
Namespace string `json:"namespace"`
7878
}
7979

80-
// RouteForwardTo defines how a Route should forward a request.
81-
type RouteForwardTo struct {
82-
// ServiceName refers to the name of the Service to forward matched requests
83-
// to. When specified, this takes the place of BackendRef. If both
84-
// BackendRef and ServiceName are specified, ServiceName will be given
85-
// precedence.
80+
// BackendObjectReference defines how an ObjectReference that is
81+
// specific to BackendRef. It includes a few additional fields and features
82+
// than a regular ObjectReference.
83+
type BackendObjectReference struct {
84+
// Group is the group of the referent.
85+
// When unspecified (empty string), core API group is inferred.
8686
//
87-
// If the referent cannot be found, the rule is not included in the route.
88-
// The controller should raise the "ResolvedRefs" condition on the Gateway
89-
// with the "DegradedRoutes" reason. The gateway status for this route should
90-
// be updated with a condition that describes the error more specifically.
91-
//
92-
// The protocol to use should be specified with the AppProtocol field on
93-
// Service resources.
94-
//
95-
// Support: Core
96-
//
97-
// +optional
9887
// +kubebuilder:validation:MaxLength=253
99-
ServiceName *string `json:"serviceName,omitempty"`
88+
Group string `json:"group"`
10089

101-
// BackendRef is a reference to a backend to forward matched requests to. If
102-
// both BackendRef and ServiceName are specified, ServiceName will be given
103-
// precedence.
104-
//
105-
// If the referent cannot be found, the rule is not included in the route.
106-
// The controller should raise the "ResolvedRefs" condition on the Gateway
107-
// with the "DegradedRoutes" reason. The gateway status for this route should
108-
// be updated with a condition that describes the error more specifically.
109-
//
110-
// Support: Custom
90+
// Kind is kind of the referent.
11191
//
11292
// +optional
113-
BackendRef *LocalObjectReference `json:"backendRef,omitempty"`
93+
// +kubebuilder:default=Service
94+
// +kubebuilder:validation:MinLength=1
95+
// +kubebuilder:validation:MaxLength=253
96+
Kind *string `json:"kind"`
11497

115-
// Port specifies the destination port number to use for the
116-
// backend referenced by the ServiceName or BackendRef field.
117-
// If unspecified, the destination port in the request is used
118-
// when forwarding to a backendRef or serviceName.
98+
// Name is the name of the referent.
11999
//
120-
// Support: Core
100+
// +kubebuilder:validation:MinLength=1
101+
// +kubebuilder:validation:MaxLength=253
102+
Name string `json:"name"`
103+
104+
// Port specifies the destination port number to use for this resource.
105+
// Port is required when the referent is a Kubernetes Service.
106+
// For other resources, destination port can be derived from the referent
107+
// resource or this field.
121108
//
122109
// +optional
123110
Port *PortNumber `json:"port,omitempty"`
111+
}
112+
113+
// BackendRef defines how a Route should forward a request to a Kubernetes
114+
// resource.
115+
type BackendRef struct {
116+
// BackendObjectReference references a Kubernetes object.
117+
BackendObjectReference `json:",inline"`
124118

125-
// Weight specifies the proportion of HTTP requests forwarded to the backend
126-
// referenced by the ServiceName or BackendRef field. This is computed as
119+
// Weight specifies the proportion of HTTP requests forwarded to the
120+
// referenced backend. This is computed as
127121
// weight/(sum of all weights in this ForwardTo list). For non-zero values,
128122
// there may be some epsilon from the exact proportion defined here
129123
// depending on the precision an implementation supports. Weight is not a
@@ -134,7 +128,7 @@ type RouteForwardTo struct {
134128
// traffic should be forwarded for this entry. If unspecified, weight
135129
// defaults to 1.
136130
//
137-
// Support: Extended
131+
// Support for this field varies based on the context where used.
138132
//
139133
// +optional
140134
// +kubebuilder:default=1

apis/v1alpha2/tcproute_types.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,17 @@ type TCPRouteRule struct {
9292
// +kubebuilder:validation:MaxItems=8
9393
Matches []TCPRouteMatch `json:"matches,omitempty"`
9494

95-
// ForwardTo defines the backend(s) where matching requests should
96-
// be sent.
95+
// BackendRefs defines the backend(s) where matching requests should be
96+
// sent. If unspecified, this rule MUST not match.
9797
//
98-
// +kubebuilder:validation:MinItems=1
98+
// Support: Core for Kubernetes Service
99+
// Support: Custom for any other resource
100+
//
101+
// Support for weight: Extended
102+
//
103+
// +optional
99104
// +kubebuilder:validation:MaxItems=16
100-
ForwardTo []RouteForwardTo `json:"forwardTo"`
105+
BackendRefs []BackendRef `json:"backendRefs,omitempty"`
101106
}
102107

103108
// TCPRouteMatch defines the predicate used to match connections to a

apis/v1alpha2/tlsroute_types.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,17 @@ type TLSRouteRule struct {
127127
// +kubebuilder:validation:MaxItems=8
128128
Matches []TLSRouteMatch `json:"matches,omitempty"`
129129

130-
// ForwardTo defines the backend(s) where matching requests should be
131-
// sent.
130+
// BackendRefs defines the backend(s) where matching requests should be
131+
// sent. If unspecified, this rule MUST not match.
132132
//
133-
// +kubebuilder:validation:MinItems=1
133+
// Support: Core for Kubernetes Service
134+
// Support: Custom for any other resource
135+
//
136+
// Support for weight: Extended
137+
//
138+
// +optional
134139
// +kubebuilder:validation:MaxItems=16
135-
ForwardTo []RouteForwardTo `json:"forwardTo"`
140+
BackendRefs []BackendRef `json:"backendRefs,omitempty"`
136141
}
137142

138143
// TLSRouteMatch defines the predicate used to match connections to a

apis/v1alpha2/udproute_types.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,17 @@ type UDPRouteRule struct {
9292
// +kubebuilder:validation:MaxItems=8
9393
Matches []UDPRouteMatch `json:"matches,omitempty"`
9494

95-
// ForwardTo defines the backend(s) where matching requests should
96-
// be sent.
95+
// BackendRefs defines the backend(s) where matching requests should be
96+
// sent. If unspecified, this rule MUST not match.
9797
//
98-
// +kubebuilder:validation:MinItems=1
98+
// Support: Core for Kubernetes Service
99+
// Support: Custom for any other resource
100+
//
101+
// Support for weight: Extended
102+
//
103+
// +optional
99104
// +kubebuilder:validation:MaxItems=16
100-
ForwardTo []RouteForwardTo `json:"forwardTo"`
105+
BackendRefs []BackendRef `json:"backendRefs,omitempty"`
101106
}
102107

103108
// UDPRouteMatch defines the predicate used to match packets to a

0 commit comments

Comments
 (0)