From 95fe2e19b192aba602e60c01ecde146d017b3c16 Mon Sep 17 00:00:00 2001 From: John Howard Date: Wed, 17 Apr 2024 12:30:40 -0700 Subject: [PATCH] Add section name to each route --- apis/v1/grpcroute_types.go | 6 ++++++ apis/v1/httproute_types.go | 6 ++++++ apis/v1alpha2/tcproute_types.go | 6 ++++++ apis/v1alpha2/tlsroute_types.go | 6 ++++++ apis/v1alpha2/udproute_types.go | 6 ++++++ 5 files changed, 30 insertions(+) diff --git a/apis/v1/grpcroute_types.go b/apis/v1/grpcroute_types.go index 691f8e6219..ba134805e5 100644 --- a/apis/v1/grpcroute_types.go +++ b/apis/v1/grpcroute_types.go @@ -143,6 +143,7 @@ type GRPCRouteSpec struct { // // +optional // +kubebuilder:validation:MaxItems=16 + // +kubebuilder:validation:XValidation:message="Route name must be unique within the route",rule="self.filter(k,has(k.name)).map(l1,self.filter(k,has(k.name)).exists_one(l2,l1.name == l2.name))" Rules []GRPCRouteRule `json:"rules,omitempty"` } @@ -150,6 +151,11 @@ type GRPCRouteSpec struct { // conditions (matches), processing it (filters), and forwarding the request to // an API object (backendRefs). type GRPCRouteRule struct { + // Name is the name of the route rule. This name MUST be unique within a Route if it is set. + // + // Support: Extended + Name SectionName `json:"name,omitempty"` + // Matches define conditions used for matching the rule against incoming // gRPC requests. Each match is independent, i.e. this rule will be matched // if **any** one of the matches is satisfied. diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index 252a635074..11b4e8ae91 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -117,6 +117,7 @@ type HTTPRouteSpec struct { // Rules are a list of HTTP matchers, filters and actions. // // +optional + // +kubebuilder:validation:XValidation:message="Route name must be unique within the route",rule="self.filter(k,has(k.name)).map(l1,self.filter(k,has(k.name)).exists_one(l2,l1.name == l2.name))" // +kubebuilder:validation:MaxItems=16 // +kubebuilder:default={{matches: {{path: {type: "PathPrefix", value: "/"}}}}} Rules []HTTPRouteRule `json:"rules,omitempty"` @@ -132,6 +133,11 @@ type HTTPRouteSpec struct { // +kubebuilder:validation:XValidation:message="Within backendRefs, when using RequestRedirect filter with path.replacePrefixMatch, exactly one PathPrefix match must be specified",rule="(has(self.backendRefs) && self.backendRefs.exists_one(b, (has(b.filters) && b.filters.exists_one(f, has(f.requestRedirect) && has(f.requestRedirect.path) && f.requestRedirect.path.type == 'ReplacePrefixMatch' && has(f.requestRedirect.path.replacePrefixMatch))) )) ? ((size(self.matches) != 1 || !has(self.matches[0].path) || self.matches[0].path.type != 'PathPrefix') ? false : true) : true" // +kubebuilder:validation:XValidation:message="Within backendRefs, When using URLRewrite filter with path.replacePrefixMatch, exactly one PathPrefix match must be specified",rule="(has(self.backendRefs) && self.backendRefs.exists_one(b, (has(b.filters) && b.filters.exists_one(f, has(f.urlRewrite) && has(f.urlRewrite.path) && f.urlRewrite.path.type == 'ReplacePrefixMatch' && has(f.urlRewrite.path.replacePrefixMatch))) )) ? ((size(self.matches) != 1 || !has(self.matches[0].path) || self.matches[0].path.type != 'PathPrefix') ? false : true) : true" type HTTPRouteRule struct { + // Name is the name of the route rule. This name MUST be unique within a Route if it is set. + // + // Support: Extended + Name SectionName `json:"name,omitempty"` + // Matches define conditions used for matching the rule against incoming // HTTP requests. Each match is independent, i.e. this rule will be matched // if **any** one of the matches is satisfied. diff --git a/apis/v1alpha2/tcproute_types.go b/apis/v1alpha2/tcproute_types.go index fe927ab8d4..3cb28a8951 100644 --- a/apis/v1alpha2/tcproute_types.go +++ b/apis/v1alpha2/tcproute_types.go @@ -49,6 +49,7 @@ type TCPRouteSpec struct { // // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=16 + // +kubebuilder:validation:XValidation:message="Route name must be unique within the route",rule="self.filter(k,has(k.name)).map(l1,self.filter(k,has(k.name)).exists_one(l2,l1.name == l2.name))" Rules []TCPRouteRule `json:"rules"` } @@ -59,6 +60,11 @@ type TCPRouteStatus struct { // TCPRouteRule is the configuration for a given rule. type TCPRouteRule struct { + // Name is the name of the route rule. This name MUST be unique within a Route if it is set. + // + // Support: Extended + Name SectionName `json:"name,omitempty"` + // BackendRefs defines the backend(s) where matching requests should be // sent. If unspecified or invalid (refers to a non-existent resource or a // Service with no endpoints), the underlying implementation MUST actively diff --git a/apis/v1alpha2/tlsroute_types.go b/apis/v1alpha2/tlsroute_types.go index afe34d82d6..b247ef0b8a 100644 --- a/apis/v1alpha2/tlsroute_types.go +++ b/apis/v1alpha2/tlsroute_types.go @@ -90,6 +90,7 @@ type TLSRouteSpec struct { // // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=16 + // +kubebuilder:validation:XValidation:message="Route name must be unique within the route",rule="self.filter(k,has(k.name)).map(l1,self.filter(k,has(k.name)).exists_one(l2,l1.name == l2.name))" Rules []TLSRouteRule `json:"rules"` } @@ -100,6 +101,11 @@ type TLSRouteStatus struct { // TLSRouteRule is the configuration for a given rule. type TLSRouteRule struct { + // Name is the name of the route rule. This name MUST be unique within a Route if it is set. + // + // Support: Extended + Name SectionName `json:"name,omitempty"` + // BackendRefs defines the backend(s) where matching requests should be // sent. If unspecified or invalid (refers to a non-existent resource or // a Service with no endpoints), the rule performs no forwarding; if no diff --git a/apis/v1alpha2/udproute_types.go b/apis/v1alpha2/udproute_types.go index 9e3770c293..8bf127f693 100644 --- a/apis/v1alpha2/udproute_types.go +++ b/apis/v1alpha2/udproute_types.go @@ -49,6 +49,7 @@ type UDPRouteSpec struct { // // +kubebuilder:validation:MinItems=1 // +kubebuilder:validation:MaxItems=16 + // +kubebuilder:validation:XValidation:message="Route name must be unique within the route",rule="self.filter(k,has(k.name)).map(l1,self.filter(k,has(k.name)).exists_one(l2,l1.name == l2.name))" Rules []UDPRouteRule `json:"rules"` } @@ -59,6 +60,11 @@ type UDPRouteStatus struct { // UDPRouteRule is the configuration for a given rule. type UDPRouteRule struct { + // Name is the name of the route rule. This name MUST be unique within a Route if it is set. + // + // Support: Extended + Name SectionName `json:"name,omitempty"` + // BackendRefs defines the backend(s) where matching requests should be // sent. If unspecified or invalid (refers to a non-existent resource or a // Service with no endpoints), the underlying implementation MUST actively