From 683c18a0664ace577264b98d192f190921ad4317 Mon Sep 17 00:00:00 2001 From: Owen Haynes <1472893+owenhaynes@users.noreply.github.com> Date: Wed, 24 Apr 2024 07:46:26 +0100 Subject: [PATCH 1/4] Add SourceMatchType validation for acceptable values Signed-off-by: Owen Haynes <1472893+owenhaynes@users.noreply.github.com> --- api/v1alpha1/ratelimit_types.go | 1 + 1 file changed, 1 insertion(+) diff --git a/api/v1alpha1/ratelimit_types.go b/api/v1alpha1/ratelimit_types.go index bd547b935d2..2b30cb2b55a 100644 --- a/api/v1alpha1/ratelimit_types.go +++ b/api/v1alpha1/ratelimit_types.go @@ -129,6 +129,7 @@ const ( type SourceMatch struct { // +optional // +kubebuilder:default=Exact + // +kubebuilder:validation:Enum=Exact;Distinct Type *SourceMatchType `json:"type,omitempty"` // Value is the IP CIDR that represents the range of Source IP Addresses of the client. From 8b9a0cb6bb531b7c344f5e14d24666e8418d5b9a Mon Sep 17 00:00:00 2001 From: Owen Haynes <1472893+owenhaynes@users.noreply.github.com> Date: Wed, 24 Apr 2024 09:14:11 +0100 Subject: [PATCH 2/4] update generated Signed-off-by: Owen Haynes <1472893+owenhaynes@users.noreply.github.com> --- .../gateway.envoyproxy.io_backendtrafficpolicies.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml b/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml index 4f70242efef..10cae0f507d 100644 --- a/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml +++ b/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml @@ -571,6 +571,9 @@ spec: properties: type: default: Exact + enum: + - Exact + - Distinct type: string value: description: |- @@ -701,6 +704,9 @@ spec: properties: type: default: Exact + enum: + - Exact + - Distinct type: string value: description: |- From 4fda8950dcf46260dcbb25e4c1073dc9ae2ef5ba Mon Sep 17 00:00:00 2001 From: Owen Haynes <1472893+owenhaynes@users.noreply.github.com> Date: Wed, 24 Apr 2024 10:03:07 +0100 Subject: [PATCH 3/4] move validation line Signed-off-by: Owen Haynes <1472893+owenhaynes@users.noreply.github.com> --- api/v1alpha1/ratelimit_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v1alpha1/ratelimit_types.go b/api/v1alpha1/ratelimit_types.go index 2b30cb2b55a..9228e7d4b87 100644 --- a/api/v1alpha1/ratelimit_types.go +++ b/api/v1alpha1/ratelimit_types.go @@ -114,6 +114,7 @@ type RateLimitSelectCondition struct { SourceCIDR *SourceMatch `json:"sourceCIDR,omitempty"` } +// +kubebuilder:validation:Enum=Exact;Distinct type SourceMatchType string const ( @@ -129,7 +130,6 @@ const ( type SourceMatch struct { // +optional // +kubebuilder:default=Exact - // +kubebuilder:validation:Enum=Exact;Distinct Type *SourceMatchType `json:"type,omitempty"` // Value is the IP CIDR that represents the range of Source IP Addresses of the client. From 81ebce111c6a2806b31a49b6313782d0d1610e8d Mon Sep 17 00:00:00 2001 From: Owen Haynes <1472893+owenhaynes@users.noreply.github.com> Date: Wed, 24 Apr 2024 10:31:48 +0100 Subject: [PATCH 4/4] fix e2e test data Signed-off-by: Owen Haynes <1472893+owenhaynes@users.noreply.github.com> --- test/e2e/testdata/ratelimit-cidr-match.yaml | 2 +- test/e2e/testdata/ratelimit-multiple-listeners.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/testdata/ratelimit-cidr-match.yaml b/test/e2e/testdata/ratelimit-cidr-match.yaml index 4ee92d26fcd..fdc112e6663 100644 --- a/test/e2e/testdata/ratelimit-cidr-match.yaml +++ b/test/e2e/testdata/ratelimit-cidr-match.yaml @@ -16,7 +16,7 @@ spec: - clientSelectors: - sourceCIDR: value: 0.0.0.0/0 - type: distinct + type: Distinct limit: requests: 3 unit: Hour diff --git a/test/e2e/testdata/ratelimit-multiple-listeners.yaml b/test/e2e/testdata/ratelimit-multiple-listeners.yaml index 33d789515a9..47aa3e46450 100644 --- a/test/e2e/testdata/ratelimit-multiple-listeners.yaml +++ b/test/e2e/testdata/ratelimit-multiple-listeners.yaml @@ -48,7 +48,7 @@ spec: - clientSelectors: - sourceCIDR: value: 0.0.0.0/0 - type: distinct + type: Distinct limit: requests: 3 unit: Hour