From e6beaefb85ec764cf87d30feb4d713e28aaf8cc3 Mon Sep 17 00:00:00 2001 From: jakebennert <33203530+jakebennert@users.noreply.github.com> Date: Sat, 29 Jun 2024 17:29:43 -0400 Subject: [PATCH 01/67] Create index.md --- geps/gep-3171/index.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 geps/gep-3171/index.md diff --git a/geps/gep-3171/index.md b/geps/gep-3171/index.md new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/geps/gep-3171/index.md @@ -0,0 +1 @@ + From 2506395234b0aa5d0ac50ec519b4cc6e9f6e7eb7 Mon Sep 17 00:00:00 2001 From: jakebennert <33203530+jakebennert@users.noreply.github.com> Date: Sat, 29 Jun 2024 17:30:06 -0400 Subject: [PATCH 02/67] Create metadata.yaml --- geps/gep-3171/metadata.yaml | 1 + 1 file changed, 1 insertion(+) create mode 100644 geps/gep-3171/metadata.yaml diff --git a/geps/gep-3171/metadata.yaml b/geps/gep-3171/metadata.yaml new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/geps/gep-3171/metadata.yaml @@ -0,0 +1 @@ + From 377eb60dd47c64de82db182b0c89c04065a874ca Mon Sep 17 00:00:00 2001 From: jakebennert <33203530+jakebennert@users.noreply.github.com> Date: Sat, 29 Jun 2024 20:49:56 -0400 Subject: [PATCH 03/67] Update index.md --- geps/gep-3171/index.md | 84 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/geps/gep-3171/index.md b/geps/gep-3171/index.md index 8b13789179..080c862035 100644 --- a/geps/gep-3171/index.md +++ b/geps/gep-3171/index.md @@ -1 +1,85 @@ +# GEP-3171: Percentage-based Request Mirroring +* Issue: [#3171](https://github.com/kubernetes-sigs/gateway-api/issues/3171) +* Status: **Provisional** + +(See status definitions [here](/geps/overview/#gep-states).) + +## TLDR + +Enhance the existing [Request Mirroring](https://gateway-api.sigs.k8s.io/guides/http-request-mirroring/) feature by allowing users to specify a percentage of requests they'd like mirrored. + +## Goals + +Successfully implement the feature. + +## Introduction + +[Request Mirroring](https://gateway-api.sigs.k8s.io/guides/http-request-mirroring/) is a feature that allows a user to mirror requests going to some backend A along to some other specified backend B. Right now Request Mirroring is an all or nothing feature – either 100% of request are mirrored, or 0% are. Percentage-based Request Mirroring will allow users to specify a percentage of requests they'd like mirrored as opposed to every single request. + +This feature is already [supported by Envoy](https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#envoy-v3-api-msg-config-route-v3-routeaction-requestmirrorpolicy), so adding it for the Gateway API would enable better integration between the two products. There's also an existing user desire for this feature on the [HAProxy side](https://www.haproxy.com/blog/haproxy-traffic-mirroring-for-real-world-testing) and [NGINX side](https://alex.dzyoba.com/blog/nginx-mirror/). Since Request Mirroring is already supported by the Gateway API, Percentage-based Request Mirroring would a clear improvement on this pre-existing feature. + +## API + +This GEP proposes the following API changes: + +* Add utility type `Fraction` to [v1/shared_types.go](https://github.com/kubernetes-sigs/gateway-api/blob/cb5bf1541fa70f0692aebde8c64bba434cf331b6/apis/v1/shared_types.go) and include the equivalent type `Percentage`: + + +```go +type Fraction struct { + // +optional + // +kubebuilder:validation:Minimum=0 + Numerator int32 `json:"numerator,omitempty"` + + // +optional + // +kubebuilder:default=100 + // +kubebuilder:validation:Minimum=1 + Denominator int32 `json:"denominator,omitempty"` +} + +type Percentage Fraction +``` + + +* Update the `HTTPRequestMirrorFilter` struct to include a `MirrorPercent` field of type `Percentage`: + + +```go +// HTTPRequestMirrorFilter defines configuration for the RequestMirror filter. +type HTTPRequestMirrorFilter struct { + // BackendRef references a resource where mirrored requests are sent. + // + // Mirrored requests must be sent only to a single destination endpoint + // within this BackendRef, irrespective of how many endpoints are present + // within this BackendRef. + // + // If the referent cannot be found, this BackendRef is invalid and must be + // dropped from the Gateway. The controller must ensure the "ResolvedRefs" + // condition on the Route status is set to `status: False` and not configure + // this backend in the underlying implementation. + // + // If there is a cross-namespace reference to an *existing* object + // that is not allowed by a ReferenceGrant, the controller must ensure the + // "ResolvedRefs" condition on the Route is set to `status: False`, + // with the "RefNotPermitted" reason and not configure this backend in the + // underlying implementation. + // + // In either error case, the Message of the `ResolvedRefs` Condition + // should be used to provide more detail about the problem. + // + // Support: Extended for Kubernetes Service + // + // Support: Implementation-specific for any other resource + BackendRef BackendObjectReference `json:"backendRef"` + + // MirrorPercent represents the fraction of requests that should be + // mirrored to BackendRef. + // + // If MirrorPercent is not specified, then 100% of requests will be + // mirrored. + // + // +optional + MirrorPercent Percentage `json:"mirrorPercent,omitempty"` +} +``` From 6ad651130690f60990d56aba127c137aec69c4c2 Mon Sep 17 00:00:00 2001 From: jakebennert <33203530+jakebennert@users.noreply.github.com> Date: Sat, 29 Jun 2024 21:04:27 -0400 Subject: [PATCH 04/67] Update metadata.yaml --- geps/gep-3171/metadata.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/geps/gep-3171/metadata.yaml b/geps/gep-3171/metadata.yaml index 8b13789179..e7a9c6c020 100644 --- a/geps/gep-3171/metadata.yaml +++ b/geps/gep-3171/metadata.yaml @@ -1 +1,11 @@ - +apiVersion: internal.gateway.networking.k8s.io/v1alpha2 +kind: GEPDetails +number: 3171 +name: Percentage-based Request Mirroring +status: Provisional +authors: + - jakebennert +references: + - https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io%2fv1.HTTPRequestMirrorFilter +featureNames: + - Percentage-based Request Mirroring From dd1f61bb064a062639a15154c5d9ec8a9fe03f1c Mon Sep 17 00:00:00 2001 From: jakebennert <33203530+jakebennert@users.noreply.github.com> Date: Sat, 29 Jun 2024 21:05:48 -0400 Subject: [PATCH 05/67] Remove 'omitempty' from Fraction fields --- geps/gep-3171/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/geps/gep-3171/index.md b/geps/gep-3171/index.md index 080c862035..5ce4aee3d0 100644 --- a/geps/gep-3171/index.md +++ b/geps/gep-3171/index.md @@ -30,12 +30,12 @@ This GEP proposes the following API changes: type Fraction struct { // +optional // +kubebuilder:validation:Minimum=0 - Numerator int32 `json:"numerator,omitempty"` + Numerator int32 `json:"numerator"` // +optional // +kubebuilder:default=100 // +kubebuilder:validation:Minimum=1 - Denominator int32 `json:"denominator,omitempty"` + Denominator int32 `json:"denominator"` } type Percentage Fraction From 494d1ac7ad3d6498acb9ac7ccb0eb576b00715b6 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 22 Jul 2024 13:45:30 -0400 Subject: [PATCH 06/67] Split MirrorPercent into two fields: MirrorPercent and MirrorFraction. --- geps/gep-3171/index.md | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/geps/gep-3171/index.md b/geps/gep-3171/index.md index 5ce4aee3d0..64c6aa124c 100644 --- a/geps/gep-3171/index.md +++ b/geps/gep-3171/index.md @@ -23,12 +23,13 @@ This feature is already [supported by Envoy](https://www.envoyproxy.io/docs/envo This GEP proposes the following API changes: -* Add utility type `Fraction` to [v1/shared_types.go](https://github.com/kubernetes-sigs/gateway-api/blob/cb5bf1541fa70f0692aebde8c64bba434cf331b6/apis/v1/shared_types.go) and include the equivalent type `Percentage`: +* Add utility type `Fraction` to [v1/shared_types.go](https://github.com/kubernetes-sigs/gateway-api/blob/cb5bf1541fa70f0692aebde8c64bba434cf331b6/apis/v1/shared_types.go): ```go type Fraction struct { // +optional + // +kubebuilder:default=100 // +kubebuilder:validation:Minimum=0 Numerator int32 `json:"numerator"` @@ -37,8 +38,6 @@ type Fraction struct { // +kubebuilder:validation:Minimum=1 Denominator int32 `json:"denominator"` } - -type Percentage Fraction ``` @@ -73,13 +72,32 @@ type HTTPRequestMirrorFilter struct { // Support: Implementation-specific for any other resource BackendRef BackendObjectReference `json:"backendRef"` - // MirrorPercent represents the fraction of requests that should be + // MirrorPercent represents the percentage of requests that should be + // mirrored to BackendRef. Its minimum value is 0 (indicating 0% of + // requests) and its maximum value is 100 (indicating 100% of requests). + // + // If both MirrorPercent and MirrorFraction are specified, MirrorFraction + // will take priority. If MirrorPercent is unspecified, it will have a + // default value of 100. If MirrorFraction is unspecified, it will have + // a default value of 100/100. This means that if neither field is + // specified, 100% of requests will be mirrored. + // + // +optional + // +kubebuilder:default=100 + // +kubebuilder:validation:Minimum=0 + // +kubebuilder:validation:Maximum=100 + MirrorPercent int32 `json:"mirrorPercent,omitempty"` + + // MirrorFraction represents the fraction of requests that should be // mirrored to BackendRef. // - // If MirrorPercent is not specified, then 100% of requests will be - // mirrored. + // If both MirrorPercent and MirrorFraction are specified, MirrorFraction + // will take priority. If MirrorPercent is unspecified, it will have a + // default value of 100. If MirrorFraction is unspecified, it will have + // a default value of 100/100. This means that if neither field is + // specified, 100% of requests will be mirrored. // // +optional - MirrorPercent Percentage `json:"mirrorPercent,omitempty"` + MirrorFraction Fraction `json:"mirrorFraction,omitempty"` } ``` From d99862161c116f86fb3b12e40ca88964cbee14c7 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 22 Jul 2024 14:54:33 -0400 Subject: [PATCH 07/67] Update index.md --- geps/gep-3171/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geps/gep-3171/index.md b/geps/gep-3171/index.md index 64c6aa124c..0c42b36694 100644 --- a/geps/gep-3171/index.md +++ b/geps/gep-3171/index.md @@ -41,7 +41,7 @@ type Fraction struct { ``` -* Update the `HTTPRequestMirrorFilter` struct to include a `MirrorPercent` field of type `Percentage`: +* Update the `HTTPRequestMirrorFilter` struct to include a `MirrorPercent` field of type `int32`, and a `MirrorFraction` field of type `Fraction`: ```go From 58b8d453767f6dfc5068916204f5cd200eac8508 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 22 Jul 2024 15:09:17 -0400 Subject: [PATCH 08/67] Add config examples. --- geps/gep-3171/index.md | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/geps/gep-3171/index.md b/geps/gep-3171/index.md index 0c42b36694..0d97e57bce 100644 --- a/geps/gep-3171/index.md +++ b/geps/gep-3171/index.md @@ -101,3 +101,65 @@ type HTTPRequestMirrorFilter struct { MirrorFraction Fraction `json:"mirrorFraction,omitempty"` } ``` + +## Example + +An example with MirrorPercent: + + +``` +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: http-filter-mirror + labels: + gateway: mirror-gateway +spec: + parentRefs: + - name: mirror-gateway + hostnames: + - mirror.example + rules: + - backendRefs: + - name: foo-v1 + port: 8080 + filters: + - type: RequestMirror + requestMirror: + backendRef: + name: foo-v2 + port: 8080 + mirrorPercent: 42 +``` +This would result in 42% of requests going to `foo-v1` to be mirrored to `foo-v2`. + +An example with MirrorFraction: + + +``` +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: http-filter-mirror + labels: + gateway: mirror-gateway +spec: + parentRefs: + - name: mirror-gateway + hostnames: + - mirror.example + rules: + - backendRefs: + - name: foo-v1 + port: 8080 + filters: + - type: RequestMirror + requestMirror: + backendRef: + name: foo-v2 + port: 8080 + mirrorFraction: + numerator: 5 + denominator: 1000 +``` +This would result in 0.5% of requests going to `foo-v1` to be mirrored to `foo-v2`. From 4768da74387def6434e45db0091faa021f48ce43 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 22 Jul 2024 16:16:57 -0400 Subject: [PATCH 09/67] Add Existing Support Table --- geps/gep-3171/index.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/geps/gep-3171/index.md b/geps/gep-3171/index.md index 0d97e57bce..825f61a5fc 100644 --- a/geps/gep-3171/index.md +++ b/geps/gep-3171/index.md @@ -19,6 +19,15 @@ Successfully implement the feature. This feature is already [supported by Envoy](https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#envoy-v3-api-msg-config-route-v3-routeaction-requestmirrorpolicy), so adding it for the Gateway API would enable better integration between the two products. There's also an existing user desire for this feature on the [HAProxy side](https://www.haproxy.com/blog/haproxy-traffic-mirroring-for-real-world-testing) and [NGINX side](https://alex.dzyoba.com/blog/nginx-mirror/). Since Request Mirroring is already supported by the Gateway API, Percentage-based Request Mirroring would a clear improvement on this pre-existing feature. +## Existing Support in Implementations + +| Implementation | Support | +|----------------|------------| +| Envoy | [config.route.v3.RouteAction.RequestMirrorPolicy](config.route.v3.RouteAction.RequestMirrorPolicy) | +| HAProxy | [HAProxy SPOP](https://github.com/haproxytech/spoa-mirror) | +| NGINX | [ngx_http_mirror_module](https://nginx.org/en/docs/http/ngx_http_mirror_module.html) | +| gCloud | [RequestMirrorPolicy](https://cloud.google.com/python/docs/reference/compute/latest/google.cloud.compute_v1.types.RequestMirrorPolicy) | + ## API This GEP proposes the following API changes: From 9c8f6724cd8124d7d0216ef08424409423a27239 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 22 Jul 2024 17:21:44 -0400 Subject: [PATCH 10/67] Update field names to avoid 'stuttering' in names. --- geps/gep-3171/index.md | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/geps/gep-3171/index.md b/geps/gep-3171/index.md index 825f61a5fc..585e620a22 100644 --- a/geps/gep-3171/index.md +++ b/geps/gep-3171/index.md @@ -50,7 +50,7 @@ type Fraction struct { ``` -* Update the `HTTPRequestMirrorFilter` struct to include a `MirrorPercent` field of type `int32`, and a `MirrorFraction` field of type `Fraction`: +* Update the `HTTPRequestMirrorFilter` struct to include a `Percent` field of type `int32`, and a `Fraction` field of type `Fraction`: ```go @@ -81,39 +81,39 @@ type HTTPRequestMirrorFilter struct { // Support: Implementation-specific for any other resource BackendRef BackendObjectReference `json:"backendRef"` - // MirrorPercent represents the percentage of requests that should be + // Percent represents the percentage of requests that should be // mirrored to BackendRef. Its minimum value is 0 (indicating 0% of // requests) and its maximum value is 100 (indicating 100% of requests). // - // If both MirrorPercent and MirrorFraction are specified, MirrorFraction - // will take priority. If MirrorPercent is unspecified, it will have a - // default value of 100. If MirrorFraction is unspecified, it will have - // a default value of 100/100. This means that if neither field is - // specified, 100% of requests will be mirrored. + // If both Percent and Fraction are specified, Fraction will take + // priority. If Percent is unspecified, it will have a default value of + // 100. If Fraction is unspecified, it will have a default value of + // 100/100. This means that if neither field is specified, 100% of + // requests will be mirrored. // // +optional // +kubebuilder:default=100 // +kubebuilder:validation:Minimum=0 // +kubebuilder:validation:Maximum=100 - MirrorPercent int32 `json:"mirrorPercent,omitempty"` + Percent int32 `json:"percent,omitempty"` - // MirrorFraction represents the fraction of requests that should be + // Fraction represents the fraction of requests that should be // mirrored to BackendRef. // - // If both MirrorPercent and MirrorFraction are specified, MirrorFraction - // will take priority. If MirrorPercent is unspecified, it will have a - // default value of 100. If MirrorFraction is unspecified, it will have - // a default value of 100/100. This means that if neither field is - // specified, 100% of requests will be mirrored. + // If both Percent and Fraction are specified, Fraction will take + // priority. If Percent is unspecified, it will have a default value of + // 100. If Fraction is unspecified, it will have a default value of + // 100/100. This means that if neither field is specified, 100% of + // requests will be mirrored. // // +optional - MirrorFraction Fraction `json:"mirrorFraction,omitempty"` + Fraction Fraction `json:"fraction,omitempty"` } ``` ## Example -An example with MirrorPercent: +An example with Percent: ``` @@ -138,11 +138,11 @@ spec: backendRef: name: foo-v2 port: 8080 - mirrorPercent: 42 + percent: 42 ``` This would result in 42% of requests going to `foo-v1` to be mirrored to `foo-v2`. -An example with MirrorFraction: +An example with Fraction: ``` @@ -167,7 +167,7 @@ spec: backendRef: name: foo-v2 port: 8080 - mirrorFraction: + fraction: numerator: 5 denominator: 1000 ``` From dbbe4de421ae464a7349baf8b377f63a8ff753d3 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 29 Jul 2024 13:17:13 -0400 Subject: [PATCH 11/67] Update geps/gep-3171/index.md Co-authored-by: Rob Scott --- geps/gep-3171/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geps/gep-3171/index.md b/geps/gep-3171/index.md index 585e620a22..4927411c9b 100644 --- a/geps/gep-3171/index.md +++ b/geps/gep-3171/index.md @@ -1,7 +1,7 @@ # GEP-3171: Percentage-based Request Mirroring * Issue: [#3171](https://github.com/kubernetes-sigs/gateway-api/issues/3171) -* Status: **Provisional** +* Status: **Implementable** (See status definitions [here](/geps/overview/#gep-states).) From 6f0b6f95056b89fceda954d2602e6ec757a2bda2 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 19 Aug 2024 21:51:24 -0400 Subject: [PATCH 12/67] Add Fraction type --- apis/v1/shared_types.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apis/v1/shared_types.go b/apis/v1/shared_types.go index 954c605428..5384f6405e 100644 --- a/apis/v1/shared_types.go +++ b/apis/v1/shared_types.go @@ -855,3 +855,15 @@ const ( // Support: Extended PermanentCookieLifetimeType CookieLifetimeType = "Permanent" ) + +type Fraction struct { + // +optional + // +kubebuilder:default=100 + // +kubebuilder:validation:Minimum=0 + Numerator int32 `json:"numerator"` + + // +optional + // +kubebuilder:default=100 + // +kubebuilder:validation:Minimum=1 + Denominator int32 `json:"denominator"` +} From 219602fe04b61b49de116b6b0df539c1c562d9d4 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 19 Aug 2024 21:54:13 -0400 Subject: [PATCH 13/67] Add percent and fraction to HTTPRequestMirrorFilter --- apis/v1/httproute_types.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index b6c2e936ef..934cb2d40d 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -1153,6 +1153,34 @@ type HTTPRequestMirrorFilter struct { // // Support: Implementation-specific for any other resource BackendRef BackendObjectReference `json:"backendRef"` + + // Percent represents the percentage of requests that should be + // mirrored to BackendRef. Its minimum value is 0 (indicating 0% of + // requests) and its maximum value is 100 (indicating 100% of requests). + // + // If both Percent and Fraction are specified, Fraction will take + // priority. If Percent is unspecified, it will have a default value of + // 100. If Fraction is unspecified, it will have a default value of + // 100/100. This means that if neither field is specified, 100% of + // requests will be mirrored. + // + // +optional + // +kubebuilder:default=100 + // +kubebuilder:validation:Minimum=0 + // +kubebuilder:validation:Maximum=100 + Percent int32 `json:"percent,omitempty"` + + // Fraction represents the fraction of requests that should be + // mirrored to BackendRef. + // + // If both Percent and Fraction are specified, Fraction will take + // priority. If Percent is unspecified, it will have a default value of + // 100. If Fraction is unspecified, it will have a default value of + // 100/100. This means that if neither field is specified, 100% of + // requests will be mirrored. + // + // +optional + Fraction Fraction `json:"fraction,omitempty"` } // HTTPBackendRef defines how a HTTPRoute forwards a HTTP request. From 205726afdc0856174747df85ec06e21b94f562df Mon Sep 17 00:00:00 2001 From: jakebennert Date: Tue, 20 Aug 2024 21:50:55 -0400 Subject: [PATCH 14/67] Update apis/v1/httproute_types.go Co-authored-by: Rob Scott --- apis/v1/httproute_types.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index 934cb2d40d..96af49b74f 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -1168,7 +1168,8 @@ type HTTPRequestMirrorFilter struct { // +kubebuilder:default=100 // +kubebuilder:validation:Minimum=0 // +kubebuilder:validation:Maximum=100 - Percent int32 `json:"percent,omitempty"` + + Percent int32 `json:"percent,omitempty"` // Fraction represents the fraction of requests that should be // mirrored to BackendRef. From dc6c3e4f7050cad72e5e5a92d67206326c33471d Mon Sep 17 00:00:00 2001 From: jakebennert Date: Tue, 20 Aug 2024 21:51:52 -0400 Subject: [PATCH 15/67] Update apis/v1/shared_types.go Co-authored-by: Rob Scott --- apis/v1/shared_types.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/apis/v1/shared_types.go b/apis/v1/shared_types.go index 5384f6405e..54b0ac5058 100644 --- a/apis/v1/shared_types.go +++ b/apis/v1/shared_types.go @@ -857,8 +857,6 @@ const ( ) type Fraction struct { - // +optional - // +kubebuilder:default=100 // +kubebuilder:validation:Minimum=0 Numerator int32 `json:"numerator"` From 1b8f84d4edea1f7754d380037df84c05790858ee Mon Sep 17 00:00:00 2001 From: jakebennert Date: Tue, 20 Aug 2024 22:47:27 -0400 Subject: [PATCH 16/67] Add CEL validation to Fraction type --- apis/v1/shared_types.go | 1 + 1 file changed, 1 insertion(+) diff --git a/apis/v1/shared_types.go b/apis/v1/shared_types.go index 54b0ac5058..0649a0d66e 100644 --- a/apis/v1/shared_types.go +++ b/apis/v1/shared_types.go @@ -856,6 +856,7 @@ const ( PermanentCookieLifetimeType CookieLifetimeType = "Permanent" ) +// +kubebuilder:validation:XValidation:message="numerator must be less than or equal to denominator",rule="self.numerator <= self.denominator" type Fraction struct { // +kubebuilder:validation:Minimum=0 Numerator int32 `json:"numerator"` From b7d943cbd0e734739b32e6560587b408795e1756 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Tue, 20 Aug 2024 23:27:27 -0400 Subject: [PATCH 17/67] Add CEL validation to HttpRequestMirrorFilter Also updated field descriptions to match the validation. Removed the default value for Percent. --- apis/v1/httproute_types.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index 96af49b74f..1ac4423d2e 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -1128,6 +1128,8 @@ type HTTPURLRewriteFilter struct { } // HTTPRequestMirrorFilter defines configuration for the RequestMirror filter. +// +// +kubebuilder:validation:XValidation:message="Only one of fraction or percent may be specified",rule="!(has(self.percent) && has(self.fraction))" type HTTPRequestMirrorFilter struct { // BackendRef references a resource where mirrored requests are sent. // @@ -1158,14 +1160,10 @@ type HTTPRequestMirrorFilter struct { // mirrored to BackendRef. Its minimum value is 0 (indicating 0% of // requests) and its maximum value is 100 (indicating 100% of requests). // - // If both Percent and Fraction are specified, Fraction will take - // priority. If Percent is unspecified, it will have a default value of - // 100. If Fraction is unspecified, it will have a default value of - // 100/100. This means that if neither field is specified, 100% of - // requests will be mirrored. + // Only one of Fraction or Percent may be specified. If neither field + // is specified, 100% of requests will be mirrored. // // +optional - // +kubebuilder:default=100 // +kubebuilder:validation:Minimum=0 // +kubebuilder:validation:Maximum=100 @@ -1174,11 +1172,8 @@ type HTTPRequestMirrorFilter struct { // Fraction represents the fraction of requests that should be // mirrored to BackendRef. // - // If both Percent and Fraction are specified, Fraction will take - // priority. If Percent is unspecified, it will have a default value of - // 100. If Fraction is unspecified, it will have a default value of - // 100/100. This means that if neither field is specified, 100% of - // requests will be mirrored. + // Only one of Fraction or Percent may be specified. If neither field + // is specified, 100% of requests will be mirrored. // // +optional Fraction Fraction `json:"fraction,omitempty"` From a38970f06e7e508bfb861fe2cdb33da818d20ae3 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Wed, 21 Aug 2024 00:40:35 -0400 Subject: [PATCH 18/67] Add CEL validation test for HTTPRequestMirrorFilter --- pkg/test/cel/httproute_experimental_test.go | 40 +++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pkg/test/cel/httproute_experimental_test.go b/pkg/test/cel/httproute_experimental_test.go index e46ee9299f..7cb04474b2 100644 --- a/pkg/test/cel/httproute_experimental_test.go +++ b/pkg/test/cel/httproute_experimental_test.go @@ -432,3 +432,43 @@ func TestHTTPRouteRuleExperimental(t *testing.T) { }) } } + +func TestHTTPRequestMirrorFilter(t *testing.T) { + tests := []struct { + name string + wantErrors []string + rules []gatewayv1.HTTPRouteRule + }{ + { + name: "Only one of fraction or percent may be specified", + wantErrors: []string{"Only one of fraction or percent may be specified"}, + rules: []gatewayv1.HTTPRouteRule{{ + Type: gatewayv1.HTTPRouteFilterRequestMirror, + RequestMirror: &gatewayv1.HTTPRequestMirrorFilter{ + BackendRef: gatewayv1.BackendObjectReference{ + Name: testService, + Port: ptrTo(gatewayv1.PortNumber(8081)), + }, + Percent: 42, + Fraction{ + Numerator: 567, + Denominator: 1000, + }, + }, + }}, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + route := &gatewayv1.HTTPRoute{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("foo-%v", time.Now().UnixNano()), + Namespace: metav1.NamespaceDefault, + }, + Spec: gatewayv1.HTTPRouteSpec{Rules: tc.rules}, + } + validateHTTPRoute(t, route, tc.wantErrors) + }) + } +} From fece6d38985bc604eef15ec6c02e775ba4f57bdd Mon Sep 17 00:00:00 2001 From: Jake Bennert Date: Wed, 21 Aug 2024 22:12:55 +0000 Subject: [PATCH 19/67] Ran /hack/update-codegen.sh --- apis/applyconfiguration/apis/v1/fraction.go | 48 +++++ .../apis/v1/httprequestmirrorfilter.go | 18 ++ apis/applyconfiguration/internal/internal.go | 18 ++ apis/applyconfiguration/utils.go | 2 + apis/v1/httproute_types.go | 3 +- apis/v1/zz_generated.deepcopy.go | 16 ++ .../gateway.networking.k8s.io_grpcroutes.yaml | 182 ++++++++++++++++++ .../gateway.networking.k8s.io_httproutes.yaml | 182 ++++++++++++++++++ .../gateway.networking.k8s.io_grpcroutes.yaml | 14 ++ .../gateway.networking.k8s.io_httproutes.yaml | 14 ++ pkg/generated/openapi/zz_generated.openapi.go | 44 ++++- 11 files changed, 539 insertions(+), 2 deletions(-) create mode 100644 apis/applyconfiguration/apis/v1/fraction.go diff --git a/apis/applyconfiguration/apis/v1/fraction.go b/apis/applyconfiguration/apis/v1/fraction.go new file mode 100644 index 0000000000..5d828f6178 --- /dev/null +++ b/apis/applyconfiguration/apis/v1/fraction.go @@ -0,0 +1,48 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +// FractionApplyConfiguration represents an declarative configuration of the Fraction type for use +// with apply. +type FractionApplyConfiguration struct { + Numerator *int32 `json:"numerator,omitempty"` + Denominator *int32 `json:"denominator,omitempty"` +} + +// FractionApplyConfiguration constructs an declarative configuration of the Fraction type for use with +// apply. +func Fraction() *FractionApplyConfiguration { + return &FractionApplyConfiguration{} +} + +// WithNumerator sets the Numerator field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Numerator field is set to the value of the last call. +func (b *FractionApplyConfiguration) WithNumerator(value int32) *FractionApplyConfiguration { + b.Numerator = &value + return b +} + +// WithDenominator sets the Denominator field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Denominator field is set to the value of the last call. +func (b *FractionApplyConfiguration) WithDenominator(value int32) *FractionApplyConfiguration { + b.Denominator = &value + return b +} diff --git a/apis/applyconfiguration/apis/v1/httprequestmirrorfilter.go b/apis/applyconfiguration/apis/v1/httprequestmirrorfilter.go index 1809ff078a..55c2246b34 100644 --- a/apis/applyconfiguration/apis/v1/httprequestmirrorfilter.go +++ b/apis/applyconfiguration/apis/v1/httprequestmirrorfilter.go @@ -22,6 +22,8 @@ package v1 // with apply. type HTTPRequestMirrorFilterApplyConfiguration struct { BackendRef *BackendObjectReferenceApplyConfiguration `json:"backendRef,omitempty"` + Percent *int32 `json:"percent,omitempty"` + Fraction *FractionApplyConfiguration `json:"fraction,omitempty"` } // HTTPRequestMirrorFilterApplyConfiguration constructs an declarative configuration of the HTTPRequestMirrorFilter type for use with @@ -37,3 +39,19 @@ func (b *HTTPRequestMirrorFilterApplyConfiguration) WithBackendRef(value *Backen b.BackendRef = value return b } + +// WithPercent sets the Percent field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Percent field is set to the value of the last call. +func (b *HTTPRequestMirrorFilterApplyConfiguration) WithPercent(value int32) *HTTPRequestMirrorFilterApplyConfiguration { + b.Percent = &value + return b +} + +// WithFraction sets the Fraction field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Fraction field is set to the value of the last call. +func (b *HTTPRequestMirrorFilterApplyConfiguration) WithFraction(value *FractionApplyConfiguration) *HTTPRequestMirrorFilterApplyConfiguration { + b.Fraction = value + return b +} diff --git a/apis/applyconfiguration/internal/internal.go b/apis/applyconfiguration/internal/internal.go index 31e4bb33e6..1e76d5b0a6 100644 --- a/apis/applyconfiguration/internal/internal.go +++ b/apis/applyconfiguration/internal/internal.go @@ -282,6 +282,17 @@ var schemaYAML = typed.YAMLObject(`types: - name: lifetimeType type: scalar: string +- name: io.k8s.sigs.gateway-api.apis.v1.Fraction + map: + fields: + - name: denominator + type: + scalar: numeric + default: 0 + - name: numerator + type: + scalar: numeric + default: 0 - name: io.k8s.sigs.gateway-api.apis.v1.FrontendTLSValidation map: fields: @@ -756,6 +767,13 @@ var schemaYAML = typed.YAMLObject(`types: type: namedType: io.k8s.sigs.gateway-api.apis.v1.BackendObjectReference default: {} + - name: fraction + type: + namedType: io.k8s.sigs.gateway-api.apis.v1.Fraction + default: {} + - name: percent + type: + scalar: numeric - name: io.k8s.sigs.gateway-api.apis.v1.HTTPRequestRedirectFilter map: fields: diff --git a/apis/applyconfiguration/utils.go b/apis/applyconfiguration/utils.go index e457c32b52..c88ae790dd 100644 --- a/apis/applyconfiguration/utils.go +++ b/apis/applyconfiguration/utils.go @@ -45,6 +45,8 @@ func ForKind(kind schema.GroupVersionKind) interface{} { return &apisv1.CommonRouteSpecApplyConfiguration{} case v1.SchemeGroupVersion.WithKind("CookieConfig"): return &apisv1.CookieConfigApplyConfiguration{} + case v1.SchemeGroupVersion.WithKind("Fraction"): + return &apisv1.FractionApplyConfiguration{} case v1.SchemeGroupVersion.WithKind("FrontendTLSValidation"): return &apisv1.FrontendTLSValidationApplyConfiguration{} case v1.SchemeGroupVersion.WithKind("Gateway"): diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index 1ac4423d2e..723b2c75be 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -1166,7 +1166,7 @@ type HTTPRequestMirrorFilter struct { // +optional // +kubebuilder:validation:Minimum=0 // +kubebuilder:validation:Maximum=100 - + // Percent int32 `json:"percent,omitempty"` // Fraction represents the fraction of requests that should be @@ -1176,6 +1176,7 @@ type HTTPRequestMirrorFilter struct { // is specified, 100% of requests will be mirrored. // // +optional + // Fraction Fraction `json:"fraction,omitempty"` } diff --git a/apis/v1/zz_generated.deepcopy.go b/apis/v1/zz_generated.deepcopy.go index 02906dc1a6..2411bd4830 100644 --- a/apis/v1/zz_generated.deepcopy.go +++ b/apis/v1/zz_generated.deepcopy.go @@ -150,6 +150,21 @@ func (in *CookieConfig) DeepCopy() *CookieConfig { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Fraction) DeepCopyInto(out *Fraction) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Fraction. +func (in *Fraction) DeepCopy() *Fraction { + if in == nil { + return nil + } + out := new(Fraction) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *FrontendTLSValidation) DeepCopyInto(out *FrontendTLSValidation) { *out = *in @@ -971,6 +986,7 @@ func (in *HTTPQueryParamMatch) DeepCopy() *HTTPQueryParamMatch { func (in *HTTPRequestMirrorFilter) DeepCopyInto(out *HTTPRequestMirrorFilter) { *out = *in in.BackendRef.DeepCopyInto(&out.BackendRef) + out.Fraction = in.Fraction } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HTTPRequestMirrorFilter. diff --git a/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml b/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml index e47547eac1..265fc0ab2b 100644 --- a/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml +++ b/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml @@ -843,9 +843,55 @@ spec: - message: Must have port for Service reference rule: '(size(self.group) == 0 && self.kind == ''Service'') ? has(self.port) : true' + fraction: + description: |+ + Fraction represents the fraction of requests that should be + mirrored to BackendRef. + + + Only one of Fraction or Percent may be specified. If neither field + is specified, 100% of requests will be mirrored. + + + properties: + denominator: + default: 100 + format: int32 + minimum: 1 + type: integer + numerator: + format: int32 + minimum: 0 + type: integer + required: + - numerator + type: object + x-kubernetes-validations: + - message: numerator must be less than or equal + to denominator + rule: self.numerator <= self.denominator + percent: + description: |+ + Percent represents the percentage of requests that should be + mirrored to BackendRef. Its minimum value is 0 (indicating 0% of + requests) and its maximum value is 100 (indicating 100% of requests). + + + Only one of Fraction or Percent may be specified. If neither field + is specified, 100% of requests will be mirrored. + + + format: int32 + maximum: 100 + minimum: 0 + type: integer required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of fraction or percent may be + specified + rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response @@ -1513,9 +1559,54 @@ spec: - message: Must have port for Service reference rule: '(size(self.group) == 0 && self.kind == ''Service'') ? has(self.port) : true' + fraction: + description: |+ + Fraction represents the fraction of requests that should be + mirrored to BackendRef. + + + Only one of Fraction or Percent may be specified. If neither field + is specified, 100% of requests will be mirrored. + + + properties: + denominator: + default: 100 + format: int32 + minimum: 1 + type: integer + numerator: + format: int32 + minimum: 0 + type: integer + required: + - numerator + type: object + x-kubernetes-validations: + - message: numerator must be less than or equal to + denominator + rule: self.numerator <= self.denominator + percent: + description: |+ + Percent represents the percentage of requests that should be + mirrored to BackendRef. Its minimum value is 0 (indicating 0% of + requests) and its maximum value is 100 (indicating 100% of requests). + + + Only one of Fraction or Percent may be specified. If neither field + is specified, 100% of requests will be mirrored. + + + format: int32 + maximum: 100 + minimum: 0 + type: integer required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of fraction or percent may be specified + rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response @@ -3207,9 +3298,55 @@ spec: - message: Must have port for Service reference rule: '(size(self.group) == 0 && self.kind == ''Service'') ? has(self.port) : true' + fraction: + description: |+ + Fraction represents the fraction of requests that should be + mirrored to BackendRef. + + + Only one of Fraction or Percent may be specified. If neither field + is specified, 100% of requests will be mirrored. + + + properties: + denominator: + default: 100 + format: int32 + minimum: 1 + type: integer + numerator: + format: int32 + minimum: 0 + type: integer + required: + - numerator + type: object + x-kubernetes-validations: + - message: numerator must be less than or equal + to denominator + rule: self.numerator <= self.denominator + percent: + description: |+ + Percent represents the percentage of requests that should be + mirrored to BackendRef. Its minimum value is 0 (indicating 0% of + requests) and its maximum value is 100 (indicating 100% of requests). + + + Only one of Fraction or Percent may be specified. If neither field + is specified, 100% of requests will be mirrored. + + + format: int32 + maximum: 100 + minimum: 0 + type: integer required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of fraction or percent may be + specified + rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response @@ -3877,9 +4014,54 @@ spec: - message: Must have port for Service reference rule: '(size(self.group) == 0 && self.kind == ''Service'') ? has(self.port) : true' + fraction: + description: |+ + Fraction represents the fraction of requests that should be + mirrored to BackendRef. + + + Only one of Fraction or Percent may be specified. If neither field + is specified, 100% of requests will be mirrored. + + + properties: + denominator: + default: 100 + format: int32 + minimum: 1 + type: integer + numerator: + format: int32 + minimum: 0 + type: integer + required: + - numerator + type: object + x-kubernetes-validations: + - message: numerator must be less than or equal to + denominator + rule: self.numerator <= self.denominator + percent: + description: |+ + Percent represents the percentage of requests that should be + mirrored to BackendRef. Its minimum value is 0 (indicating 0% of + requests) and its maximum value is 100 (indicating 100% of requests). + + + Only one of Fraction or Percent may be specified. If neither field + is specified, 100% of requests will be mirrored. + + + format: int32 + maximum: 100 + minimum: 0 + type: integer required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of fraction or percent may be specified + rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response diff --git a/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml b/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml index 18ace973b6..40851b6d8e 100644 --- a/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml +++ b/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml @@ -835,9 +835,55 @@ spec: - message: Must have port for Service reference rule: '(size(self.group) == 0 && self.kind == ''Service'') ? has(self.port) : true' + fraction: + description: |+ + Fraction represents the fraction of requests that should be + mirrored to BackendRef. + + + Only one of Fraction or Percent may be specified. If neither field + is specified, 100% of requests will be mirrored. + + + properties: + denominator: + default: 100 + format: int32 + minimum: 1 + type: integer + numerator: + format: int32 + minimum: 0 + type: integer + required: + - numerator + type: object + x-kubernetes-validations: + - message: numerator must be less than or equal + to denominator + rule: self.numerator <= self.denominator + percent: + description: |+ + Percent represents the percentage of requests that should be + mirrored to BackendRef. Its minimum value is 0 (indicating 0% of + requests) and its maximum value is 100 (indicating 100% of requests). + + + Only one of Fraction or Percent may be specified. If neither field + is specified, 100% of requests will be mirrored. + + + format: int32 + maximum: 100 + minimum: 0 + type: integer required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of fraction or percent may be + specified + rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -1846,9 +1892,54 @@ spec: - message: Must have port for Service reference rule: '(size(self.group) == 0 && self.kind == ''Service'') ? has(self.port) : true' + fraction: + description: |+ + Fraction represents the fraction of requests that should be + mirrored to BackendRef. + + + Only one of Fraction or Percent may be specified. If neither field + is specified, 100% of requests will be mirrored. + + + properties: + denominator: + default: 100 + format: int32 + minimum: 1 + type: integer + numerator: + format: int32 + minimum: 0 + type: integer + required: + - numerator + type: object + x-kubernetes-validations: + - message: numerator must be less than or equal to + denominator + rule: self.numerator <= self.denominator + percent: + description: |+ + Percent represents the percentage of requests that should be + mirrored to BackendRef. Its minimum value is 0 (indicating 0% of + requests) and its maximum value is 100 (indicating 100% of requests). + + + Only one of Fraction or Percent may be specified. If neither field + is specified, 100% of requests will be mirrored. + + + format: int32 + maximum: 100 + minimum: 0 + type: integer required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of fraction or percent may be specified + rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -4098,9 +4189,55 @@ spec: - message: Must have port for Service reference rule: '(size(self.group) == 0 && self.kind == ''Service'') ? has(self.port) : true' + fraction: + description: |+ + Fraction represents the fraction of requests that should be + mirrored to BackendRef. + + + Only one of Fraction or Percent may be specified. If neither field + is specified, 100% of requests will be mirrored. + + + properties: + denominator: + default: 100 + format: int32 + minimum: 1 + type: integer + numerator: + format: int32 + minimum: 0 + type: integer + required: + - numerator + type: object + x-kubernetes-validations: + - message: numerator must be less than or equal + to denominator + rule: self.numerator <= self.denominator + percent: + description: |+ + Percent represents the percentage of requests that should be + mirrored to BackendRef. Its minimum value is 0 (indicating 0% of + requests) and its maximum value is 100 (indicating 100% of requests). + + + Only one of Fraction or Percent may be specified. If neither field + is specified, 100% of requests will be mirrored. + + + format: int32 + maximum: 100 + minimum: 0 + type: integer required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of fraction or percent may be + specified + rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -5109,9 +5246,54 @@ spec: - message: Must have port for Service reference rule: '(size(self.group) == 0 && self.kind == ''Service'') ? has(self.port) : true' + fraction: + description: |+ + Fraction represents the fraction of requests that should be + mirrored to BackendRef. + + + Only one of Fraction or Percent may be specified. If neither field + is specified, 100% of requests will be mirrored. + + + properties: + denominator: + default: 100 + format: int32 + minimum: 1 + type: integer + numerator: + format: int32 + minimum: 0 + type: integer + required: + - numerator + type: object + x-kubernetes-validations: + - message: numerator must be less than or equal to + denominator + rule: self.numerator <= self.denominator + percent: + description: |+ + Percent represents the percentage of requests that should be + mirrored to BackendRef. Its minimum value is 0 (indicating 0% of + requests) and its maximum value is 100 (indicating 100% of requests). + + + Only one of Fraction or Percent may be specified. If neither field + is specified, 100% of requests will be mirrored. + + + format: int32 + maximum: 100 + minimum: 0 + type: integer required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of fraction or percent may be specified + rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the diff --git a/config/crd/standard/gateway.networking.k8s.io_grpcroutes.yaml b/config/crd/standard/gateway.networking.k8s.io_grpcroutes.yaml index 01fc863825..8406d38533 100644 --- a/config/crd/standard/gateway.networking.k8s.io_grpcroutes.yaml +++ b/config/crd/standard/gateway.networking.k8s.io_grpcroutes.yaml @@ -817,6 +817,10 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of fraction or percent may be + specified + rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response @@ -1487,6 +1491,9 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of fraction or percent may be specified + rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response @@ -3024,6 +3031,10 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of fraction or percent may be + specified + rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response @@ -3694,6 +3705,9 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of fraction or percent may be specified + rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response diff --git a/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml b/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml index 6a4a9b6fe1..a1e3efd244 100644 --- a/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml +++ b/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml @@ -809,6 +809,10 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of fraction or percent may be + specified + rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -1820,6 +1824,9 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of fraction or percent may be specified + rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -3915,6 +3922,10 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of fraction or percent may be + specified + rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -4926,6 +4937,9 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of fraction or percent may be specified + rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index b57c621df3..654e998967 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -86,6 +86,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "sigs.k8s.io/gateway-api/apis/v1.BackendRef": schema_sigsk8sio_gateway_api_apis_v1_BackendRef(ref), "sigs.k8s.io/gateway-api/apis/v1.CommonRouteSpec": schema_sigsk8sio_gateway_api_apis_v1_CommonRouteSpec(ref), "sigs.k8s.io/gateway-api/apis/v1.CookieConfig": schema_sigsk8sio_gateway_api_apis_v1_CookieConfig(ref), + "sigs.k8s.io/gateway-api/apis/v1.Fraction": schema_sigsk8sio_gateway_api_apis_v1_Fraction(ref), "sigs.k8s.io/gateway-api/apis/v1.FrontendTLSValidation": schema_sigsk8sio_gateway_api_apis_v1_FrontendTLSValidation(ref), "sigs.k8s.io/gateway-api/apis/v1.GRPCBackendRef": schema_sigsk8sio_gateway_api_apis_v1_GRPCBackendRef(ref), "sigs.k8s.io/gateway-api/apis/v1.GRPCHeaderMatch": schema_sigsk8sio_gateway_api_apis_v1_GRPCHeaderMatch(ref), @@ -2916,6 +2917,33 @@ func schema_sigsk8sio_gateway_api_apis_v1_CookieConfig(ref common.ReferenceCallb } } +func schema_sigsk8sio_gateway_api_apis_v1_Fraction(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "numerator": { + SchemaProps: spec.SchemaProps{ + Default: 0, + Type: []string{"integer"}, + Format: "int32", + }, + }, + "denominator": { + SchemaProps: spec.SchemaProps{ + Default: 0, + Type: []string{"integer"}, + Format: "int32", + }, + }, + }, + Required: []string{"numerator"}, + }, + }, + } +} + func schema_sigsk8sio_gateway_api_apis_v1_FrontendTLSValidation(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -4371,12 +4399,26 @@ func schema_sigsk8sio_gateway_api_apis_v1_HTTPRequestMirrorFilter(ref common.Ref Ref: ref("sigs.k8s.io/gateway-api/apis/v1.BackendObjectReference"), }, }, + "percent": { + SchemaProps: spec.SchemaProps{ + Description: "Percent represents the percentage of requests that should be mirrored to BackendRef. Its minimum value is 0 (indicating 0% of requests) and its maximum value is 100 (indicating 100% of requests).\n\nOnly one of Fraction or Percent may be specified. If neither field is specified, 100% of requests will be mirrored.\n\n", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "fraction": { + SchemaProps: spec.SchemaProps{ + Description: "Fraction represents the fraction of requests that should be mirrored to BackendRef.\n\nOnly one of Fraction or Percent may be specified. If neither field is specified, 100% of requests will be mirrored.\n\n", + Default: map[string]interface{}{}, + Ref: ref("sigs.k8s.io/gateway-api/apis/v1.Fraction"), + }, + }, }, Required: []string{"backendRef"}, }, }, Dependencies: []string{ - "sigs.k8s.io/gateway-api/apis/v1.BackendObjectReference"}, + "sigs.k8s.io/gateway-api/apis/v1.BackendObjectReference", "sigs.k8s.io/gateway-api/apis/v1.Fraction"}, } } From a121d72660adca5ec36ff8271ae2c265c6537d09 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Thu, 22 Aug 2024 15:44:57 -0400 Subject: [PATCH 20/67] Update httproute_experimental_test.go --- pkg/test/cel/httproute_experimental_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/test/cel/httproute_experimental_test.go b/pkg/test/cel/httproute_experimental_test.go index 7cb04474b2..f11b3b67bd 100644 --- a/pkg/test/cel/httproute_experimental_test.go +++ b/pkg/test/cel/httproute_experimental_test.go @@ -434,6 +434,7 @@ func TestHTTPRouteRuleExperimental(t *testing.T) { } func TestHTTPRequestMirrorFilter(t *testing.T) { + testService := gatewayv1.ObjectName("test-service") tests := []struct { name string wantErrors []string From 8ac9286982303f770cb8d35f19ebdf3b2d5f9b58 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Thu, 22 Aug 2024 16:50:02 -0400 Subject: [PATCH 21/67] Update httproute_experimental_test.go --- pkg/test/cel/httproute_experimental_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/test/cel/httproute_experimental_test.go b/pkg/test/cel/httproute_experimental_test.go index f11b3b67bd..42f5b30bf5 100644 --- a/pkg/test/cel/httproute_experimental_test.go +++ b/pkg/test/cel/httproute_experimental_test.go @@ -451,7 +451,7 @@ func TestHTTPRequestMirrorFilter(t *testing.T) { Port: ptrTo(gatewayv1.PortNumber(8081)), }, Percent: 42, - Fraction{ + Fraction: gatewayv1.Fraction{ Numerator: 567, Denominator: 1000, }, From ce85d11883173f7e232d4c862a87a0a56de45725 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Thu, 22 Aug 2024 17:15:58 -0400 Subject: [PATCH 22/67] Update httproute_experimental_test.go --- pkg/test/cel/httproute_experimental_test.go | 24 +++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pkg/test/cel/httproute_experimental_test.go b/pkg/test/cel/httproute_experimental_test.go index 42f5b30bf5..e3c282f021 100644 --- a/pkg/test/cel/httproute_experimental_test.go +++ b/pkg/test/cel/httproute_experimental_test.go @@ -444,18 +444,20 @@ func TestHTTPRequestMirrorFilter(t *testing.T) { name: "Only one of fraction or percent may be specified", wantErrors: []string{"Only one of fraction or percent may be specified"}, rules: []gatewayv1.HTTPRouteRule{{ - Type: gatewayv1.HTTPRouteFilterRequestMirror, - RequestMirror: &gatewayv1.HTTPRequestMirrorFilter{ - BackendRef: gatewayv1.BackendObjectReference{ - Name: testService, - Port: ptrTo(gatewayv1.PortNumber(8081)), + Filters: []gatewayv1.HTTPRouteFilter{{ + Type: gatewayv1.HTTPRouteFilterRequestMirror, + RequestMirror: &gatewayv1.HTTPRequestMirrorFilter{ + BackendRef: gatewayv1.BackendObjectReference{ + Name: testService, + Port: ptrTo(gatewayv1.PortNumber(8081)), + }, + Percent: 42, + Fraction: gatewayv1.Fraction{ + Numerator: 567, + Denominator: 1000, + }, }, - Percent: 42, - Fraction: gatewayv1.Fraction{ - Numerator: 567, - Denominator: 1000, - }, - }, + }}, }}, }, } From 1ae9c389c05c7b5314be41b3f9b6be005043612c Mon Sep 17 00:00:00 2001 From: jakebennert Date: Thu, 22 Aug 2024 18:29:13 -0400 Subject: [PATCH 23/67] Update httproute_types.go --- apis/v1/httproute_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index 723b2c75be..3630ba6a28 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -1129,7 +1129,7 @@ type HTTPURLRewriteFilter struct { // HTTPRequestMirrorFilter defines configuration for the RequestMirror filter. // -// +kubebuilder:validation:XValidation:message="Only one of fraction or percent may be specified",rule="!(has(self.percent) && has(self.fraction))" +// type HTTPRequestMirrorFilter struct { // BackendRef references a resource where mirrored requests are sent. // From 2647feeb7e01b0177f0332cfd2fc1dbbf53bf13c Mon Sep 17 00:00:00 2001 From: Jake Bennert Date: Thu, 22 Aug 2024 22:49:48 +0000 Subject: [PATCH 24/67] Reran /hack/update-codegen.sh --- .../gateway.networking.k8s.io_grpcroutes.yaml | 14 -------------- .../gateway.networking.k8s.io_httproutes.yaml | 14 -------------- .../gateway.networking.k8s.io_grpcroutes.yaml | 14 -------------- .../gateway.networking.k8s.io_httproutes.yaml | 14 -------------- 4 files changed, 56 deletions(-) diff --git a/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml b/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml index 265fc0ab2b..a246fb960f 100644 --- a/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml +++ b/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml @@ -888,10 +888,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: Only one of fraction or percent may be - specified - rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response @@ -1604,9 +1600,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: Only one of fraction or percent may be specified - rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response @@ -3343,10 +3336,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: Only one of fraction or percent may be - specified - rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response @@ -4059,9 +4048,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: Only one of fraction or percent may be specified - rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response diff --git a/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml b/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml index 40851b6d8e..94aeebbdd1 100644 --- a/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml +++ b/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml @@ -880,10 +880,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: Only one of fraction or percent may be - specified - rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -1937,9 +1933,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: Only one of fraction or percent may be specified - rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -4234,10 +4227,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: Only one of fraction or percent may be - specified - rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -5291,9 +5280,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: Only one of fraction or percent may be specified - rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the diff --git a/config/crd/standard/gateway.networking.k8s.io_grpcroutes.yaml b/config/crd/standard/gateway.networking.k8s.io_grpcroutes.yaml index 8406d38533..01fc863825 100644 --- a/config/crd/standard/gateway.networking.k8s.io_grpcroutes.yaml +++ b/config/crd/standard/gateway.networking.k8s.io_grpcroutes.yaml @@ -817,10 +817,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: Only one of fraction or percent may be - specified - rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response @@ -1491,9 +1487,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: Only one of fraction or percent may be specified - rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response @@ -3031,10 +3024,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: Only one of fraction or percent may be - specified - rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response @@ -3705,9 +3694,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: Only one of fraction or percent may be specified - rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response diff --git a/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml b/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml index a1e3efd244..6a4a9b6fe1 100644 --- a/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml +++ b/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml @@ -809,10 +809,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: Only one of fraction or percent may be - specified - rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -1824,9 +1820,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: Only one of fraction or percent may be specified - rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -3922,10 +3915,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: Only one of fraction or percent may be - specified - rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -4937,9 +4926,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: Only one of fraction or percent may be specified - rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the From 4af86bcf4134a7e13021b292e797e8fd9e9a91df Mon Sep 17 00:00:00 2001 From: jakebennert Date: Thu, 22 Aug 2024 19:18:55 -0400 Subject: [PATCH 25/67] Update httproute_experimental_test.go --- pkg/test/cel/httproute_experimental_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/test/cel/httproute_experimental_test.go b/pkg/test/cel/httproute_experimental_test.go index e3c282f021..214c5af71f 100644 --- a/pkg/test/cel/httproute_experimental_test.go +++ b/pkg/test/cel/httproute_experimental_test.go @@ -433,7 +433,7 @@ func TestHTTPRouteRuleExperimental(t *testing.T) { } } -func TestHTTPRequestMirrorFilter(t *testing.T) { +func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { testService := gatewayv1.ObjectName("test-service") tests := []struct { name string From 639dd4202ffbd3740bfd5e3be21e0e50e66852dc Mon Sep 17 00:00:00 2001 From: jakebennert Date: Thu, 22 Aug 2024 19:59:10 -0400 Subject: [PATCH 26/67] Make Denominator field a pointer to distinguish between 0 and unset Co-authored-by: Rob Scott --- apis/v1/shared_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apis/v1/shared_types.go b/apis/v1/shared_types.go index 0649a0d66e..c3fc2f5db7 100644 --- a/apis/v1/shared_types.go +++ b/apis/v1/shared_types.go @@ -864,5 +864,5 @@ type Fraction struct { // +optional // +kubebuilder:default=100 // +kubebuilder:validation:Minimum=1 - Denominator int32 `json:"denominator"` + Denominator *int32 `json:"denominator,omitempty"` } From d1142d768c7ff4b12c29ec94a464574ce2ca48ac Mon Sep 17 00:00:00 2001 From: jakebennert Date: Thu, 22 Aug 2024 20:01:46 -0400 Subject: [PATCH 27/67] Change Percent to be a pointer to distinguish between 0 and unset Co-authored-by: Rob Scott --- apis/v1/httproute_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index 3630ba6a28..f30fdef4ca 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -1167,7 +1167,7 @@ type HTTPRequestMirrorFilter struct { // +kubebuilder:validation:Minimum=0 // +kubebuilder:validation:Maximum=100 // - Percent int32 `json:"percent,omitempty"` + Percent *int32 `json:"percent,omitempty"` // Fraction represents the fraction of requests that should be // mirrored to BackendRef. From 2fc563bd64b3538efaeb5b884f394a2dfc2691c4 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Thu, 22 Aug 2024 20:25:58 -0400 Subject: [PATCH 28/67] Update httproute_experimental_test.go --- pkg/test/cel/httproute_experimental_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/test/cel/httproute_experimental_test.go b/pkg/test/cel/httproute_experimental_test.go index 214c5af71f..c68576f60f 100644 --- a/pkg/test/cel/httproute_experimental_test.go +++ b/pkg/test/cel/httproute_experimental_test.go @@ -434,6 +434,8 @@ func TestHTTPRouteRuleExperimental(t *testing.T) { } func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { + var percent int = 42 + var denominator int = 1000 testService := gatewayv1.ObjectName("test-service") tests := []struct { name string @@ -451,10 +453,10 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { Name: testService, Port: ptrTo(gatewayv1.PortNumber(8081)), }, - Percent: 42, + Percent: &percent, Fraction: gatewayv1.Fraction{ Numerator: 567, - Denominator: 1000, + Denominator: &denominator, }, }, }}, From b7b9e5d7416523de24890b440b04fa57efb4ea46 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Thu, 22 Aug 2024 20:46:57 -0400 Subject: [PATCH 29/67] Update httproute_experimental_test.go --- pkg/test/cel/httproute_experimental_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/test/cel/httproute_experimental_test.go b/pkg/test/cel/httproute_experimental_test.go index c68576f60f..f2f57db94e 100644 --- a/pkg/test/cel/httproute_experimental_test.go +++ b/pkg/test/cel/httproute_experimental_test.go @@ -434,8 +434,8 @@ func TestHTTPRouteRuleExperimental(t *testing.T) { } func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { - var percent int = 42 - var denominator int = 1000 + var percent int32 = 42 + var denominator int32 = 1000 testService := gatewayv1.ObjectName("test-service") tests := []struct { name string From 5ef895e41b49117407647615494769227e9d9c29 Mon Sep 17 00:00:00 2001 From: Jake Bennert Date: Fri, 23 Aug 2024 07:01:16 +0000 Subject: [PATCH 30/67] Format httproute_types.go --- apis/v1/httproute_types.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index f30fdef4ca..d7e153e0d2 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -1157,27 +1157,27 @@ type HTTPRequestMirrorFilter struct { BackendRef BackendObjectReference `json:"backendRef"` // Percent represents the percentage of requests that should be - // mirrored to BackendRef. Its minimum value is 0 (indicating 0% of - // requests) and its maximum value is 100 (indicating 100% of requests). - // - // Only one of Fraction or Percent may be specified. If neither field + // mirrored to BackendRef. Its minimum value is 0 (indicating 0% of + // requests) and its maximum value is 100 (indicating 100% of requests). + // + // Only one of Fraction or Percent may be specified. If neither field // is specified, 100% of requests will be mirrored. - // - // +optional - // +kubebuilder:validation:Minimum=0 - // +kubebuilder:validation:Maximum=100 + // + // +optional + // +kubebuilder:validation:Minimum=0 + // +kubebuilder:validation:Maximum=100 // Percent *int32 `json:"percent,omitempty"` - // Fraction represents the fraction of requests that should be - // mirrored to BackendRef. - // - // Only one of Fraction or Percent may be specified. If neither field + // Fraction represents the fraction of requests that should be + // mirrored to BackendRef. + // + // Only one of Fraction or Percent may be specified. If neither field // is specified, 100% of requests will be mirrored. - // - // +optional + // + // +optional // - Fraction Fraction `json:"fraction,omitempty"` + Fraction Fraction `json:"fraction,omitempty"` } // HTTPBackendRef defines how a HTTPRoute forwards a HTTP request. From 55bdd99531f1f970fd2f85c54557cd3e334061cb Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 03:03:58 -0400 Subject: [PATCH 31/67] Make Fraction a pointer --- apis/v1/httproute_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index d7e153e0d2..0c17e3e8b3 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -1177,7 +1177,7 @@ type HTTPRequestMirrorFilter struct { // // +optional // - Fraction Fraction `json:"fraction,omitempty"` + Fraction *Fraction `json:"fraction,omitempty"` } // HTTPBackendRef defines how a HTTPRoute forwards a HTTP request. From a7ec37b4152ea408716a853ba38e260117d5c204 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 03:04:20 -0400 Subject: [PATCH 32/67] Update httproute_experimental_test.go --- pkg/test/cel/httproute_experimental_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/test/cel/httproute_experimental_test.go b/pkg/test/cel/httproute_experimental_test.go index f2f57db94e..741a341e74 100644 --- a/pkg/test/cel/httproute_experimental_test.go +++ b/pkg/test/cel/httproute_experimental_test.go @@ -454,7 +454,7 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { Port: ptrTo(gatewayv1.PortNumber(8081)), }, Percent: &percent, - Fraction: gatewayv1.Fraction{ + Fraction: &gatewayv1.Fraction{ Numerator: 567, Denominator: &denominator, }, From 785c868446fb10a05ab7b0d1e1c1663ced86b09d Mon Sep 17 00:00:00 2001 From: Jake Bennert Date: Fri, 23 Aug 2024 07:05:42 +0000 Subject: [PATCH 33/67] Reran hack/update-codegen.sh --- apis/applyconfiguration/internal/internal.go | 2 -- apis/v1/zz_generated.deepcopy.go | 16 +++++++++++++++- pkg/generated/openapi/zz_generated.openapi.go | 6 ++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/apis/applyconfiguration/internal/internal.go b/apis/applyconfiguration/internal/internal.go index 1e76d5b0a6..cf2182195b 100644 --- a/apis/applyconfiguration/internal/internal.go +++ b/apis/applyconfiguration/internal/internal.go @@ -288,7 +288,6 @@ var schemaYAML = typed.YAMLObject(`types: - name: denominator type: scalar: numeric - default: 0 - name: numerator type: scalar: numeric @@ -770,7 +769,6 @@ var schemaYAML = typed.YAMLObject(`types: - name: fraction type: namedType: io.k8s.sigs.gateway-api.apis.v1.Fraction - default: {} - name: percent type: scalar: numeric diff --git a/apis/v1/zz_generated.deepcopy.go b/apis/v1/zz_generated.deepcopy.go index 2411bd4830..6ce1393c4d 100644 --- a/apis/v1/zz_generated.deepcopy.go +++ b/apis/v1/zz_generated.deepcopy.go @@ -153,6 +153,11 @@ func (in *CookieConfig) DeepCopy() *CookieConfig { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Fraction) DeepCopyInto(out *Fraction) { *out = *in + if in.Denominator != nil { + in, out := &in.Denominator, &out.Denominator + *out = new(int32) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Fraction. @@ -986,7 +991,16 @@ func (in *HTTPQueryParamMatch) DeepCopy() *HTTPQueryParamMatch { func (in *HTTPRequestMirrorFilter) DeepCopyInto(out *HTTPRequestMirrorFilter) { *out = *in in.BackendRef.DeepCopyInto(&out.BackendRef) - out.Fraction = in.Fraction + if in.Percent != nil { + in, out := &in.Percent, &out.Percent + *out = new(int32) + **out = **in + } + if in.Fraction != nil { + in, out := &in.Fraction, &out.Fraction + *out = new(Fraction) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HTTPRequestMirrorFilter. diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 654e998967..6acfb984cc 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -2932,9 +2932,8 @@ func schema_sigsk8sio_gateway_api_apis_v1_Fraction(ref common.ReferenceCallback) }, "denominator": { SchemaProps: spec.SchemaProps{ - Default: 0, - Type: []string{"integer"}, - Format: "int32", + Type: []string{"integer"}, + Format: "int32", }, }, }, @@ -4409,7 +4408,6 @@ func schema_sigsk8sio_gateway_api_apis_v1_HTTPRequestMirrorFilter(ref common.Ref "fraction": { SchemaProps: spec.SchemaProps{ Description: "Fraction represents the fraction of requests that should be mirrored to BackendRef.\n\nOnly one of Fraction or Percent may be specified. If neither field is specified, 100% of requests will be mirrored.\n\n", - Default: map[string]interface{}{}, Ref: ref("sigs.k8s.io/gateway-api/apis/v1.Fraction"), }, }, From 9b9141a52a94c7bd948d6948b2c0c0242384dd10 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 04:37:24 -0400 Subject: [PATCH 34/67] Updating to test CEL validation --- apis/v1/httproute_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index 0c17e3e8b3..ee4b9824fb 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -1129,7 +1129,7 @@ type HTTPURLRewriteFilter struct { // HTTPRequestMirrorFilter defines configuration for the RequestMirror filter. // -// +// type HTTPRequestMirrorFilter struct { // BackendRef references a resource where mirrored requests are sent. // From 0d950da08de2a26608a85a7e734bf2c0a560a1d9 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 04:38:18 -0400 Subject: [PATCH 35/67] Updating to test CEL validation --- pkg/test/cel/httproute_experimental_test.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pkg/test/cel/httproute_experimental_test.go b/pkg/test/cel/httproute_experimental_test.go index 741a341e74..a99c60098e 100644 --- a/pkg/test/cel/httproute_experimental_test.go +++ b/pkg/test/cel/httproute_experimental_test.go @@ -435,7 +435,6 @@ func TestHTTPRouteRuleExperimental(t *testing.T) { func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { var percent int32 = 42 - var denominator int32 = 1000 testService := gatewayv1.ObjectName("test-service") tests := []struct { name string @@ -443,8 +442,8 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { rules []gatewayv1.HTTPRouteRule }{ { - name: "Only one of fraction or percent may be specified", - wantErrors: []string{"Only one of fraction or percent may be specified"}, + name: "Testing testing testing", + wantErrors: []string{"testing testing testing"}, rules: []gatewayv1.HTTPRouteRule{{ Filters: []gatewayv1.HTTPRouteFilter{{ Type: gatewayv1.HTTPRouteFilterRequestMirror, @@ -454,10 +453,6 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { Port: ptrTo(gatewayv1.PortNumber(8081)), }, Percent: &percent, - Fraction: &gatewayv1.Fraction{ - Numerator: 567, - Denominator: &denominator, - }, }, }}, }}, From 92c3a20f2f2a006c7acc958b8b999116e698f2ae Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 05:15:38 -0400 Subject: [PATCH 36/67] Update httproute_types.go --- apis/v1/httproute_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index ee4b9824fb..39527ccf96 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -1129,7 +1129,7 @@ type HTTPURLRewriteFilter struct { // HTTPRequestMirrorFilter defines configuration for the RequestMirror filter. // -// +// type HTTPRequestMirrorFilter struct { // BackendRef references a resource where mirrored requests are sent. // From 316965a80381d982a6a82f5764f8ebecfa43f083 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 05:16:56 -0400 Subject: [PATCH 37/67] Update httproute_experimental_test.go --- pkg/test/cel/httproute_experimental_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/test/cel/httproute_experimental_test.go b/pkg/test/cel/httproute_experimental_test.go index a99c60098e..9cecb661fd 100644 --- a/pkg/test/cel/httproute_experimental_test.go +++ b/pkg/test/cel/httproute_experimental_test.go @@ -434,7 +434,7 @@ func TestHTTPRouteRuleExperimental(t *testing.T) { } func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { - var percent int32 = 42 + var denominator int32 = 1000 testService := gatewayv1.ObjectName("test-service") tests := []struct { name string @@ -452,7 +452,10 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { Name: testService, Port: ptrTo(gatewayv1.PortNumber(8081)), }, - Percent: &percent, + Fraction: &gatewayv1.Fraction{ + Numerator: 568 + Denominator: &denominator + } }, }}, }}, From ef85ee03a39e8c62875ad32ac7d8f9cf11f953bf Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 05:25:11 -0400 Subject: [PATCH 38/67] Update httproute_experimental_test.go --- pkg/test/cel/httproute_experimental_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/test/cel/httproute_experimental_test.go b/pkg/test/cel/httproute_experimental_test.go index 9cecb661fd..e3f2868171 100644 --- a/pkg/test/cel/httproute_experimental_test.go +++ b/pkg/test/cel/httproute_experimental_test.go @@ -453,9 +453,9 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { Port: ptrTo(gatewayv1.PortNumber(8081)), }, Fraction: &gatewayv1.Fraction{ - Numerator: 568 - Denominator: &denominator - } + Numerator: 568, + Denominator: &denominator, + }, }, }}, }}, From f9d668783567a779a1b113d7583af0ee94e25011 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 05:39:31 -0400 Subject: [PATCH 39/67] Update httproute_experimental_test.go --- pkg/test/cel/httproute_experimental_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/test/cel/httproute_experimental_test.go b/pkg/test/cel/httproute_experimental_test.go index e3f2868171..348339e768 100644 --- a/pkg/test/cel/httproute_experimental_test.go +++ b/pkg/test/cel/httproute_experimental_test.go @@ -434,7 +434,7 @@ func TestHTTPRouteRuleExperimental(t *testing.T) { } func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { - var denominator int32 = 1000 + var denominator int32 = 1 testService := gatewayv1.ObjectName("test-service") tests := []struct { name string @@ -442,8 +442,8 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { rules []gatewayv1.HTTPRouteRule }{ { - name: "Testing testing testing", - wantErrors: []string{"testing testing testing"}, + name: "Testing", + wantErrors: []string{"numerator must be less than or equal to denominator"}, rules: []gatewayv1.HTTPRouteRule{{ Filters: []gatewayv1.HTTPRouteFilter{{ Type: gatewayv1.HTTPRouteFilterRequestMirror, @@ -453,7 +453,7 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { Port: ptrTo(gatewayv1.PortNumber(8081)), }, Fraction: &gatewayv1.Fraction{ - Numerator: 568, + Numerator: 83, Denominator: &denominator, }, }, From f64e4b722d31227dcf55a3579325a682d85bb960 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 05:52:24 -0400 Subject: [PATCH 40/67] Update httproute_types.go --- apis/v1/httproute_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index 39527ccf96..50bf5ff865 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -1129,7 +1129,7 @@ type HTTPURLRewriteFilter struct { // HTTPRequestMirrorFilter defines configuration for the RequestMirror filter. // -// +// +kubebuilder:validation:XValidation:message="testing testing testing",rule="false" type HTTPRequestMirrorFilter struct { // BackendRef references a resource where mirrored requests are sent. // From e92b89d37e8642661cad0be0ca9dee506b8bf7f5 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 05:53:26 -0400 Subject: [PATCH 41/67] Update httproute_experimental_test.go --- pkg/test/cel/httproute_experimental_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/test/cel/httproute_experimental_test.go b/pkg/test/cel/httproute_experimental_test.go index 348339e768..3695918a29 100644 --- a/pkg/test/cel/httproute_experimental_test.go +++ b/pkg/test/cel/httproute_experimental_test.go @@ -434,7 +434,8 @@ func TestHTTPRouteRuleExperimental(t *testing.T) { } func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { - var denominator int32 = 1 + var percent int32 = 42 + var denominator int32 = 1000 testService := gatewayv1.ObjectName("test-service") tests := []struct { name string @@ -443,7 +444,7 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { }{ { name: "Testing", - wantErrors: []string{"numerator must be less than or equal to denominator"}, + wantErrors: []string{"testing testing testing"}, rules: []gatewayv1.HTTPRouteRule{{ Filters: []gatewayv1.HTTPRouteFilter{{ Type: gatewayv1.HTTPRouteFilterRequestMirror, @@ -452,6 +453,7 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { Name: testService, Port: ptrTo(gatewayv1.PortNumber(8081)), }, + Percent: &percent, Fraction: &gatewayv1.Fraction{ Numerator: 83, Denominator: &denominator, From 7beabbba079797e5ed7bb5b4073c76614a01e23c Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 12:24:54 -0400 Subject: [PATCH 42/67] Update httproute_types.go --- apis/v1/httproute_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index 50bf5ff865..42c60e2d5a 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -1129,7 +1129,7 @@ type HTTPURLRewriteFilter struct { // HTTPRequestMirrorFilter defines configuration for the RequestMirror filter. // -// +kubebuilder:validation:XValidation:message="testing testing testing",rule="false" +// type HTTPRequestMirrorFilter struct { // BackendRef references a resource where mirrored requests are sent. // From c66e899247d3e5fe1165dd101891ea9565bb48a5 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 13:16:11 -0400 Subject: [PATCH 43/67] Update httproute_types.go --- apis/v1/httproute_types.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index 42c60e2d5a..6e71885e97 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -757,6 +757,8 @@ type HTTPRouteFilter struct { // Support: Extended // // +optional + // + // RequestMirror *HTTPRequestMirrorFilter `json:"requestMirror,omitempty"` // RequestRedirect defines a schema for a filter that responds to the @@ -1128,8 +1130,6 @@ type HTTPURLRewriteFilter struct { } // HTTPRequestMirrorFilter defines configuration for the RequestMirror filter. -// -// type HTTPRequestMirrorFilter struct { // BackendRef references a resource where mirrored requests are sent. // From faaac1849665f6810c22d126d3fa5b29fd237762 Mon Sep 17 00:00:00 2001 From: Jake Bennert Date: Fri, 23 Aug 2024 17:19:02 +0000 Subject: [PATCH 44/67] testing --- .../gateway.networking.k8s.io_httproutes.yaml | 28 ++++++++++++++++--- .../gateway.networking.k8s.io_httproutes.yaml | 16 ++++++++--- pkg/generated/openapi/zz_generated.openapi.go | 2 +- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml b/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml index 94aeebbdd1..54c4d63680 100644 --- a/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml +++ b/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml @@ -717,7 +717,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -729,6 +729,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -880,6 +882,9 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: testing testing testing + rule: "false" requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -1770,7 +1775,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -1782,6 +1787,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -1933,6 +1940,9 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: testing testing testing + rule: "false" requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -4064,7 +4074,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -4076,6 +4086,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -4227,6 +4239,9 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: testing testing testing + rule: "false" requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -5117,7 +5132,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -5129,6 +5144,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -5280,6 +5297,9 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: testing testing testing + rule: "false" requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the diff --git a/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml b/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml index 6a4a9b6fe1..88aacdec03 100644 --- a/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml +++ b/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml @@ -688,7 +688,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -700,6 +700,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -1699,7 +1701,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -1711,6 +1713,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -3794,7 +3798,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -3806,6 +3810,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -4805,7 +4811,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -4817,6 +4823,8 @@ spec: Support: Extended + + properties: backendRef: description: |- diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 6acfb984cc..9b95480fbc 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -4548,7 +4548,7 @@ func schema_sigsk8sio_gateway_api_apis_v1_HTTPRouteFilter(ref common.ReferenceCa }, "requestMirror": { SchemaProps: spec.SchemaProps{ - Description: "RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored.\n\nThis filter can be used multiple times within the same rule. Note that not all implementations will be able to support mirroring to multiple backends.\n\nSupport: Extended", + Description: "RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored.\n\nThis filter can be used multiple times within the same rule. Note that not all implementations will be able to support mirroring to multiple backends.\n\nSupport: Extended\n\n\n", Ref: ref("sigs.k8s.io/gateway-api/apis/v1.HTTPRequestMirrorFilter"), }, }, From 8758c998f798467a492e228903760d5752ae1dc9 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 17:17:46 -0400 Subject: [PATCH 45/67] Update httproute_types.go --- apis/v1/httproute_types.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index 6e71885e97..42c60e2d5a 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -757,8 +757,6 @@ type HTTPRouteFilter struct { // Support: Extended // // +optional - // - // RequestMirror *HTTPRequestMirrorFilter `json:"requestMirror,omitempty"` // RequestRedirect defines a schema for a filter that responds to the @@ -1130,6 +1128,8 @@ type HTTPURLRewriteFilter struct { } // HTTPRequestMirrorFilter defines configuration for the RequestMirror filter. +// +// type HTTPRequestMirrorFilter struct { // BackendRef references a resource where mirrored requests are sent. // From 502f23b22018b03bd35d5ed3d1cec46b6cec14f8 Mon Sep 17 00:00:00 2001 From: Jake Bennert Date: Fri, 23 Aug 2024 21:33:30 +0000 Subject: [PATCH 46/67] Ran hack/update-codegen.sh --- .../gateway.networking.k8s.io_httproutes.yaml | 28 +++---------------- .../gateway.networking.k8s.io_httproutes.yaml | 16 +++-------- pkg/generated/openapi/zz_generated.openapi.go | 2 +- 3 files changed, 9 insertions(+), 37 deletions(-) diff --git a/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml b/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml index 54c4d63680..94aeebbdd1 100644 --- a/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml +++ b/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml @@ -717,7 +717,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |+ + description: |- RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -729,8 +729,6 @@ spec: Support: Extended - - properties: backendRef: description: |- @@ -882,9 +880,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: testing testing testing - rule: "false" requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -1775,7 +1770,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |+ + description: |- RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -1787,8 +1782,6 @@ spec: Support: Extended - - properties: backendRef: description: |- @@ -1940,9 +1933,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: testing testing testing - rule: "false" requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -4074,7 +4064,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |+ + description: |- RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -4086,8 +4076,6 @@ spec: Support: Extended - - properties: backendRef: description: |- @@ -4239,9 +4227,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: testing testing testing - rule: "false" requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -5132,7 +5117,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |+ + description: |- RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -5144,8 +5129,6 @@ spec: Support: Extended - - properties: backendRef: description: |- @@ -5297,9 +5280,6 @@ spec: required: - backendRef type: object - x-kubernetes-validations: - - message: testing testing testing - rule: "false" requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the diff --git a/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml b/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml index 88aacdec03..6a4a9b6fe1 100644 --- a/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml +++ b/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml @@ -688,7 +688,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |+ + description: |- RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -700,8 +700,6 @@ spec: Support: Extended - - properties: backendRef: description: |- @@ -1701,7 +1699,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |+ + description: |- RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -1713,8 +1711,6 @@ spec: Support: Extended - - properties: backendRef: description: |- @@ -3798,7 +3794,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |+ + description: |- RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -3810,8 +3806,6 @@ spec: Support: Extended - - properties: backendRef: description: |- @@ -4811,7 +4805,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |+ + description: |- RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -4823,8 +4817,6 @@ spec: Support: Extended - - properties: backendRef: description: |- diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 9b95480fbc..6acfb984cc 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -4548,7 +4548,7 @@ func schema_sigsk8sio_gateway_api_apis_v1_HTTPRouteFilter(ref common.ReferenceCa }, "requestMirror": { SchemaProps: spec.SchemaProps{ - Description: "RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored.\n\nThis filter can be used multiple times within the same rule. Note that not all implementations will be able to support mirroring to multiple backends.\n\nSupport: Extended\n\n\n", + Description: "RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored.\n\nThis filter can be used multiple times within the same rule. Note that not all implementations will be able to support mirroring to multiple backends.\n\nSupport: Extended", Ref: ref("sigs.k8s.io/gateway-api/apis/v1.HTTPRequestMirrorFilter"), }, }, From 68128129e8b02dda4dc49f7835df7332e0998ce4 Mon Sep 17 00:00:00 2001 From: Jake Bennert Date: Fri, 23 Aug 2024 22:11:48 +0000 Subject: [PATCH 47/67] format shared_types.go --- apis/v1/shared_types.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apis/v1/shared_types.go b/apis/v1/shared_types.go index c3fc2f5db7..7eeec85f84 100644 --- a/apis/v1/shared_types.go +++ b/apis/v1/shared_types.go @@ -858,11 +858,11 @@ const ( // +kubebuilder:validation:XValidation:message="numerator must be less than or equal to denominator",rule="self.numerator <= self.denominator" type Fraction struct { - // +kubebuilder:validation:Minimum=0 - Numerator int32 `json:"numerator"` + // +kubebuilder:validation:Minimum=0 + Numerator int32 `json:"numerator"` - // +optional - // +kubebuilder:default=100 - // +kubebuilder:validation:Minimum=1 - Denominator *int32 `json:"denominator,omitempty"` + // +optional + // +kubebuilder:default=100 + // +kubebuilder:validation:Minimum=1 + Denominator *int32 `json:"denominator,omitempty"` } From 885055d30c436f84d89d5df0c43818e4a9315897 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 18:48:28 -0400 Subject: [PATCH 48/67] Update httproute_types.go --- apis/v1/httproute_types.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index 42c60e2d5a..26c51f2f69 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -757,6 +757,8 @@ type HTTPRouteFilter struct { // Support: Extended // // +optional + // + // RequestMirror *HTTPRequestMirrorFilter `json:"requestMirror,omitempty"` // RequestRedirect defines a schema for a filter that responds to the @@ -1128,8 +1130,6 @@ type HTTPURLRewriteFilter struct { } // HTTPRequestMirrorFilter defines configuration for the RequestMirror filter. -// -// type HTTPRequestMirrorFilter struct { // BackendRef references a resource where mirrored requests are sent. // From 311832178250e45bfe28c463284152e503fa1261 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 18:49:44 -0400 Subject: [PATCH 49/67] Update httproute_experimental_test.go --- pkg/test/cel/httproute_experimental_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/test/cel/httproute_experimental_test.go b/pkg/test/cel/httproute_experimental_test.go index 3695918a29..bd4c8d243b 100644 --- a/pkg/test/cel/httproute_experimental_test.go +++ b/pkg/test/cel/httproute_experimental_test.go @@ -444,7 +444,7 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { }{ { name: "Testing", - wantErrors: []string{"testing testing testing"}, + wantErrors: []string{"Only one of percent or fraction may be specified in HTTPRequestMirrorFilter"}, rules: []gatewayv1.HTTPRouteRule{{ Filters: []gatewayv1.HTTPRouteFilter{{ Type: gatewayv1.HTTPRouteFilterRequestMirror, From 03ad867d4bbb86999c62a36171284a08d1fb99c7 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 19:08:06 -0400 Subject: [PATCH 50/67] Update httproute_types.go --- apis/v1/httproute_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index 26c51f2f69..311866dc1a 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -758,7 +758,7 @@ type HTTPRouteFilter struct { // // +optional // - // + // RequestMirror *HTTPRequestMirrorFilter `json:"requestMirror,omitempty"` // RequestRedirect defines a schema for a filter that responds to the From cb721ba869557b2de1ec95210ce85eb99b1c7de0 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 19:20:34 -0400 Subject: [PATCH 51/67] Update httproute_types.go --- apis/v1/httproute_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index 311866dc1a..dbae1fd864 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -758,7 +758,7 @@ type HTTPRouteFilter struct { // // +optional // - // + // RequestMirror *HTTPRequestMirrorFilter `json:"requestMirror,omitempty"` // RequestRedirect defines a schema for a filter that responds to the From 45190cf66cff77a55d677ad0652aa0732628e8ad Mon Sep 17 00:00:00 2001 From: Jake Bennert Date: Fri, 23 Aug 2024 23:22:44 +0000 Subject: [PATCH 52/67] reran hack/update-codegen.sh --- .../gateway.networking.k8s.io_httproutes.yaml | 32 ++++++++++++++++--- .../gateway.networking.k8s.io_httproutes.yaml | 16 +++++++--- pkg/generated/openapi/zz_generated.openapi.go | 2 +- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml b/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml index 94aeebbdd1..797bcf2b4a 100644 --- a/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml +++ b/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml @@ -717,7 +717,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -729,6 +729,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -880,6 +882,10 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of percent or fraction may be + specified in HTTPRequestMirrorFilter + rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -1770,7 +1776,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -1782,6 +1788,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -1933,6 +1941,10 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of percent or fraction may be specified + in HTTPRequestMirrorFilter + rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -4064,7 +4076,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -4076,6 +4088,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -4227,6 +4241,10 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of percent or fraction may be + specified in HTTPRequestMirrorFilter + rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the @@ -5117,7 +5135,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -5129,6 +5147,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -5280,6 +5300,10 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of percent or fraction may be specified + in HTTPRequestMirrorFilter + rule: '!(has(self.percent) && has(self.fraction))' requestRedirect: description: |- RequestRedirect defines a schema for a filter that responds to the diff --git a/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml b/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml index 6a4a9b6fe1..88aacdec03 100644 --- a/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml +++ b/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml @@ -688,7 +688,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -700,6 +700,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -1699,7 +1701,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -1711,6 +1713,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -3794,7 +3798,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -3806,6 +3810,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -4805,7 +4811,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -4817,6 +4823,8 @@ spec: Support: Extended + + properties: backendRef: description: |- diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 6acfb984cc..52aac5643d 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -4548,7 +4548,7 @@ func schema_sigsk8sio_gateway_api_apis_v1_HTTPRouteFilter(ref common.ReferenceCa }, "requestMirror": { SchemaProps: spec.SchemaProps{ - Description: "RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored.\n\nThis filter can be used multiple times within the same rule. Note that not all implementations will be able to support mirroring to multiple backends.\n\nSupport: Extended", + Description: "RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored.\n\nThis filter can be used multiple times within the same rule. Note that not all implementations will be able to support mirroring to multiple backends.\n\nSupport: Extended\n\n\n", Ref: ref("sigs.k8s.io/gateway-api/apis/v1.HTTPRequestMirrorFilter"), }, }, From 48fa58ab824353bf2eca7478fbb671dd74974f5e Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 19:47:22 -0400 Subject: [PATCH 53/67] Update httproute_types.go --- apis/v1/httproute_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index dbae1fd864..4c4f5457f8 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -1177,7 +1177,7 @@ type HTTPRequestMirrorFilter struct { // // +optional // - Fraction *Fraction `json:"fraction,omitempty"` + Fraction Fraction `json:"fraction,omitempty"` } // HTTPBackendRef defines how a HTTPRoute forwards a HTTP request. From 0e10e93cf510a5555fbb33a6317c72a937fef525 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Fri, 23 Aug 2024 19:47:40 -0400 Subject: [PATCH 54/67] Update httproute_experimental_test.go --- pkg/test/cel/httproute_experimental_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/test/cel/httproute_experimental_test.go b/pkg/test/cel/httproute_experimental_test.go index bd4c8d243b..d188963162 100644 --- a/pkg/test/cel/httproute_experimental_test.go +++ b/pkg/test/cel/httproute_experimental_test.go @@ -454,7 +454,7 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { Port: ptrTo(gatewayv1.PortNumber(8081)), }, Percent: &percent, - Fraction: &gatewayv1.Fraction{ + Fraction: gatewayv1.Fraction{ Numerator: 83, Denominator: &denominator, }, From 61ec05c7f5cb152501b7a69871b5379b186bfbce Mon Sep 17 00:00:00 2001 From: Jake Bennert Date: Fri, 23 Aug 2024 23:48:50 +0000 Subject: [PATCH 55/67] Reran hack/update-codegen.sh --- apis/applyconfiguration/internal/internal.go | 1 + apis/v1/zz_generated.deepcopy.go | 6 +----- pkg/generated/openapi/zz_generated.openapi.go | 1 + 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/apis/applyconfiguration/internal/internal.go b/apis/applyconfiguration/internal/internal.go index cf2182195b..56a2995ce2 100644 --- a/apis/applyconfiguration/internal/internal.go +++ b/apis/applyconfiguration/internal/internal.go @@ -769,6 +769,7 @@ var schemaYAML = typed.YAMLObject(`types: - name: fraction type: namedType: io.k8s.sigs.gateway-api.apis.v1.Fraction + default: {} - name: percent type: scalar: numeric diff --git a/apis/v1/zz_generated.deepcopy.go b/apis/v1/zz_generated.deepcopy.go index 6ce1393c4d..6f54fec488 100644 --- a/apis/v1/zz_generated.deepcopy.go +++ b/apis/v1/zz_generated.deepcopy.go @@ -996,11 +996,7 @@ func (in *HTTPRequestMirrorFilter) DeepCopyInto(out *HTTPRequestMirrorFilter) { *out = new(int32) **out = **in } - if in.Fraction != nil { - in, out := &in.Fraction, &out.Fraction - *out = new(Fraction) - (*in).DeepCopyInto(*out) - } + in.Fraction.DeepCopyInto(&out.Fraction) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HTTPRequestMirrorFilter. diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 52aac5643d..34d67dcb92 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -4408,6 +4408,7 @@ func schema_sigsk8sio_gateway_api_apis_v1_HTTPRequestMirrorFilter(ref common.Ref "fraction": { SchemaProps: spec.SchemaProps{ Description: "Fraction represents the fraction of requests that should be mirrored to BackendRef.\n\nOnly one of Fraction or Percent may be specified. If neither field is specified, 100% of requests will be mirrored.\n\n", + Default: map[string]interface{}{}, Ref: ref("sigs.k8s.io/gateway-api/apis/v1.Fraction"), }, }, From bd2f90eba50f9be13ef92b66a33cb39efda6cd6d Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 26 Aug 2024 14:15:12 -0400 Subject: [PATCH 56/67] Added RequestMirror validation to GRPCRoute --- apis/v1/grpcroute_types.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apis/v1/grpcroute_types.go b/apis/v1/grpcroute_types.go index 543b34644f..4e0a064297 100644 --- a/apis/v1/grpcroute_types.go +++ b/apis/v1/grpcroute_types.go @@ -466,6 +466,8 @@ const ( // Support in GRPCRouteRule: Extended // // Support in GRPCBackendRef: Extended + // + // GRPCRouteFilterRequestMirror GRPCRouteFilterType = "RequestMirror" // GRPCRouteFilterExtensionRef should be used for configuring custom From 11cec9bb06377a67d3d0ca85f8c7f443f169b114 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 26 Aug 2024 14:21:05 -0400 Subject: [PATCH 57/67] Create grcproute_experimental_test.go --- pkg/test/cel/grcproute_experimental_test.go | 90 +++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 pkg/test/cel/grcproute_experimental_test.go diff --git a/pkg/test/cel/grcproute_experimental_test.go b/pkg/test/cel/grcproute_experimental_test.go new file mode 100644 index 0000000000..5423d57b09 --- /dev/null +++ b/pkg/test/cel/grcproute_experimental_test.go @@ -0,0 +1,90 @@ +// go:build experimental +// +build experimental + +/* +Copyright 2023 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "fmt" + "testing" + "time" + + gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// +// How are tests named? Where to add new tests? +// +// Ensure that tests for newly added CEL validations are added in the correctly +// named test function. For example, if you added a test at the +// `HTTPRouteFilter` hierarchy (i.e. either at the struct level, or on one of +// the immediate descendent fields), then the test will go in the +// TestHTTPRouteFilter function. If the appropriate test function does not +// exist, please create one. +// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { + var percent int32 = 42 + var denominator int32 = 1000 + testService := gatewayv1.ObjectName("test-service") + tests := []struct { + name string + wantErrors []string + rules []gatewayv1.HTTPRouteRule + }{ + { + name: "Testing", + wantErrors: []string{"Only one of percent or fraction may be specified in HTTPRequestMirrorFilter"}, + rules: []gatewayv1.HTTPRouteRule{{ + Filters: []gatewayv1.HTTPRouteFilter{{ + Type: gatewayv1.HTTPRouteFilterRequestMirror, + RequestMirror: &gatewayv1.HTTPRequestMirrorFilter{ + BackendRef: gatewayv1.BackendObjectReference{ + Name: testService, + Port: ptrTo(gatewayv1.PortNumber(8081)), + }, + Percent: &percent, + Fraction: gatewayv1.Fraction{ + Numerator: 83, + Denominator: &denominator, + }, + }, + }}, + }}, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + route := &gatewayv1.HTTPRoute{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("foo-%v", time.Now().UnixNano()), + Namespace: metav1.NamespaceDefault, + }, + Spec: gatewayv1.HTTPRouteSpec{Rules: tc.rules}, + } + validateHTTPRoute(t, route, tc.wantErrors) + }) + } +} From 9fe610b1b709d5b0cb83bbd3d3ee8454412b049b Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 26 Aug 2024 14:22:37 -0400 Subject: [PATCH 58/67] Update grcproute_experimental_test.go --- pkg/test/cel/grcproute_experimental_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/test/cel/grcproute_experimental_test.go b/pkg/test/cel/grcproute_experimental_test.go index 5423d57b09..ca9b1565ec 100644 --- a/pkg/test/cel/grcproute_experimental_test.go +++ b/pkg/test/cel/grcproute_experimental_test.go @@ -2,7 +2,7 @@ // +build experimental /* -Copyright 2023 The Kubernetes Authors. +Copyright 2024 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From a50077c8cf111632279efa852d44218caca93b83 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 26 Aug 2024 14:49:50 -0400 Subject: [PATCH 59/67] Update grpcroute_types.go --- apis/v1/grpcroute_types.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apis/v1/grpcroute_types.go b/apis/v1/grpcroute_types.go index 4e0a064297..953ba0243b 100644 --- a/apis/v1/grpcroute_types.go +++ b/apis/v1/grpcroute_types.go @@ -466,8 +466,6 @@ const ( // Support in GRPCRouteRule: Extended // // Support in GRPCBackendRef: Extended - // - // GRPCRouteFilterRequestMirror GRPCRouteFilterType = "RequestMirror" // GRPCRouteFilterExtensionRef should be used for configuring custom @@ -552,6 +550,8 @@ type GRPCRouteFilter struct { // Support: Extended // // +optional + // + // RequestMirror *HTTPRequestMirrorFilter `json:"requestMirror,omitempty"` // ExtensionRef is an optional, implementation-specific extension to the From ed12d84ffbdbc4f39a730b8ae23f81bb94cb9b14 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 26 Aug 2024 14:54:07 -0400 Subject: [PATCH 60/67] Update grcproute_experimental_test.go --- pkg/test/cel/grcproute_experimental_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/test/cel/grcproute_experimental_test.go b/pkg/test/cel/grcproute_experimental_test.go index ca9b1565ec..ce741815c2 100644 --- a/pkg/test/cel/grcproute_experimental_test.go +++ b/pkg/test/cel/grcproute_experimental_test.go @@ -51,14 +51,14 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { tests := []struct { name string wantErrors []string - rules []gatewayv1.HTTPRouteRule + rules []gatewayv1.GRPCRouteRule }{ { name: "Testing", wantErrors: []string{"Only one of percent or fraction may be specified in HTTPRequestMirrorFilter"}, - rules: []gatewayv1.HTTPRouteRule{{ - Filters: []gatewayv1.HTTPRouteFilter{{ - Type: gatewayv1.HTTPRouteFilterRequestMirror, + rules: []gatewayv1.GRPCRouteRule{{ + Filters: []gatewayv1.GRPCRouteFilter{{ + Type: gatewayv1.GRPCRouteFilterRequestMirror, RequestMirror: &gatewayv1.HTTPRequestMirrorFilter{ BackendRef: gatewayv1.BackendObjectReference{ Name: testService, @@ -77,14 +77,14 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - route := &gatewayv1.HTTPRoute{ + route := &gatewayv1.GRPCRoute{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("foo-%v", time.Now().UnixNano()), Namespace: metav1.NamespaceDefault, }, - Spec: gatewayv1.HTTPRouteSpec{Rules: tc.rules}, + Spec: gatewayv1.GRPCRouteSpec{Rules: tc.rules}, } - validateHTTPRoute(t, route, tc.wantErrors) + validateGRPCRoute(t, route, tc.wantErrors) }) } } From 4bc5e27665ffce764d5d0c092dded0d7c8abcdbd Mon Sep 17 00:00:00 2001 From: Jake Bennert Date: Mon, 26 Aug 2024 18:59:23 +0000 Subject: [PATCH 61/67] Ran hack/update-codegen.sh --- .../gateway.networking.k8s.io_grpcroutes.yaml | 32 ++++++++++++++++--- .../gateway.networking.k8s.io_grpcroutes.yaml | 16 +++++++--- pkg/generated/openapi/zz_generated.openapi.go | 2 +- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml b/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml index a246fb960f..f0c6cbc77d 100644 --- a/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml +++ b/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml @@ -725,7 +725,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -737,6 +737,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -888,6 +890,10 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of percent or fraction may be + specified in HTTPRequestMirrorFilter + rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response @@ -1437,7 +1443,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -1449,6 +1455,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -1600,6 +1608,10 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of percent or fraction may be specified + in HTTPRequestMirrorFilter + rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response @@ -3173,7 +3185,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -3185,6 +3197,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -3336,6 +3350,10 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of percent or fraction may be + specified in HTTPRequestMirrorFilter + rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response @@ -3885,7 +3903,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -3897,6 +3915,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -4048,6 +4068,10 @@ spec: required: - backendRef type: object + x-kubernetes-validations: + - message: Only one of percent or fraction may be specified + in HTTPRequestMirrorFilter + rule: '!(has(self.percent) && has(self.fraction))' responseHeaderModifier: description: |- ResponseHeaderModifier defines a schema for a filter that modifies response diff --git a/config/crd/standard/gateway.networking.k8s.io_grpcroutes.yaml b/config/crd/standard/gateway.networking.k8s.io_grpcroutes.yaml index 01fc863825..d11f0b279b 100644 --- a/config/crd/standard/gateway.networking.k8s.io_grpcroutes.yaml +++ b/config/crd/standard/gateway.networking.k8s.io_grpcroutes.yaml @@ -696,7 +696,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -708,6 +708,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -1366,7 +1368,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -1378,6 +1380,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -2903,7 +2907,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -2915,6 +2919,8 @@ spec: Support: Extended + + properties: backendRef: description: |- @@ -3573,7 +3579,7 @@ spec: x-kubernetes-list-type: map type: object requestMirror: - description: |- + description: |+ RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored. @@ -3585,6 +3591,8 @@ spec: Support: Extended + + properties: backendRef: description: |- diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 34d67dcb92..fc61854014 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -3194,7 +3194,7 @@ func schema_sigsk8sio_gateway_api_apis_v1_GRPCRouteFilter(ref common.ReferenceCa }, "requestMirror": { SchemaProps: spec.SchemaProps{ - Description: "RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored.\n\nThis filter can be used multiple times within the same rule. Note that not all implementations will be able to support mirroring to multiple backends.\n\nSupport: Extended", + Description: "RequestMirror defines a schema for a filter that mirrors requests. Requests are sent to the specified destination, but responses from that destination are ignored.\n\nThis filter can be used multiple times within the same rule. Note that not all implementations will be able to support mirroring to multiple backends.\n\nSupport: Extended\n\n\n", Ref: ref("sigs.k8s.io/gateway-api/apis/v1.HTTPRequestMirrorFilter"), }, }, From f12e175213dd841dc1587c328357c7e44a9c05b2 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 26 Aug 2024 15:29:11 -0400 Subject: [PATCH 62/67] Update grcproute_experimental_test.go --- pkg/test/cel/grcproute_experimental_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/test/cel/grcproute_experimental_test.go b/pkg/test/cel/grcproute_experimental_test.go index ce741815c2..a6eecd63e0 100644 --- a/pkg/test/cel/grcproute_experimental_test.go +++ b/pkg/test/cel/grcproute_experimental_test.go @@ -44,7 +44,7 @@ import ( //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// -func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { +func TestHTTPRequestMirrorFilterForGRPCRouteExperimental(t *testing.T) { var percent int32 = 42 var denominator int32 = 1000 testService := gatewayv1.ObjectName("test-service") From ee4f5f537d2f080091d0e918c32dc8fea9c19cc6 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 26 Aug 2024 15:42:58 -0400 Subject: [PATCH 63/67] Update grcproute_experimental_test.go --- pkg/test/cel/grcproute_experimental_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/test/cel/grcproute_experimental_test.go b/pkg/test/cel/grcproute_experimental_test.go index a6eecd63e0..afa3b02453 100644 --- a/pkg/test/cel/grcproute_experimental_test.go +++ b/pkg/test/cel/grcproute_experimental_test.go @@ -1,8 +1,8 @@ -// go:build experimental +//go:build experimental // +build experimental /* -Copyright 2024 The Kubernetes Authors. +Copyright 2023 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From ba8993dc59c0a3c3ea485877b2a62181c10ccc9e Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 26 Aug 2024 16:03:40 -0400 Subject: [PATCH 64/67] Update Copyright Year --- pkg/test/cel/grcproute_experimental_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/test/cel/grcproute_experimental_test.go b/pkg/test/cel/grcproute_experimental_test.go index afa3b02453..af438d74a8 100644 --- a/pkg/test/cel/grcproute_experimental_test.go +++ b/pkg/test/cel/grcproute_experimental_test.go @@ -2,7 +2,7 @@ // +build experimental /* -Copyright 2023 The Kubernetes Authors. +Copyright 2024 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From ad9ecbb19bd6613ffb0fff7bc2245ddab3d5d620 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 26 Aug 2024 16:09:18 -0400 Subject: [PATCH 65/67] Update pkg/test/cel/grcproute_experimental_test.go Co-authored-by: Rob Scott --- pkg/test/cel/grcproute_experimental_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/test/cel/grcproute_experimental_test.go b/pkg/test/cel/grcproute_experimental_test.go index af438d74a8..6656fb7804 100644 --- a/pkg/test/cel/grcproute_experimental_test.go +++ b/pkg/test/cel/grcproute_experimental_test.go @@ -45,7 +45,7 @@ import ( //////////////////////////////////////////////////////////////////////////////// func TestHTTPRequestMirrorFilterForGRPCRouteExperimental(t *testing.T) { - var percent int32 = 42 + var percent int32 = 42 var denominator int32 = 1000 testService := gatewayv1.ObjectName("test-service") tests := []struct { From bb5a85826330c99b2c30f2b2f1506d19c0624f98 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 26 Aug 2024 16:11:22 -0400 Subject: [PATCH 66/67] Update httproute_experimental_test.go --- pkg/test/cel/httproute_experimental_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/test/cel/httproute_experimental_test.go b/pkg/test/cel/httproute_experimental_test.go index d188963162..7c09c9a0d2 100644 --- a/pkg/test/cel/httproute_experimental_test.go +++ b/pkg/test/cel/httproute_experimental_test.go @@ -443,7 +443,7 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) { rules []gatewayv1.HTTPRouteRule }{ { - name: "Testing", + name: "HTTPRoute - Invalid because both percent and fraction are specified", wantErrors: []string{"Only one of percent or fraction may be specified in HTTPRequestMirrorFilter"}, rules: []gatewayv1.HTTPRouteRule{{ Filters: []gatewayv1.HTTPRouteFilter{{ From ddeab1a7ae401a329d15687ac2a6a26393d5edc7 Mon Sep 17 00:00:00 2001 From: jakebennert Date: Mon, 26 Aug 2024 16:49:24 -0400 Subject: [PATCH 67/67] Update grcproute_experimental_test.go --- pkg/test/cel/grcproute_experimental_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/test/cel/grcproute_experimental_test.go b/pkg/test/cel/grcproute_experimental_test.go index 6656fb7804..d7aca2abf5 100644 --- a/pkg/test/cel/grcproute_experimental_test.go +++ b/pkg/test/cel/grcproute_experimental_test.go @@ -54,7 +54,7 @@ func TestHTTPRequestMirrorFilterForGRPCRouteExperimental(t *testing.T) { rules []gatewayv1.GRPCRouteRule }{ { - name: "Testing", + name: "GRPCRoute - Invalid because both percent and fraction are specified", wantErrors: []string{"Only one of percent or fraction may be specified in HTTPRequestMirrorFilter"}, rules: []gatewayv1.GRPCRouteRule{{ Filters: []gatewayv1.GRPCRouteFilter{{