Skip to content

Commit b1e2025

Browse files
authored
fix: allow requests:0 for global rate limit block rules (#9333)
* fix: allow requests:0 for global rate limit block rules Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
1 parent efdda00 commit b1e2025

8 files changed

Lines changed: 74 additions & 21 deletions

File tree

api/v1alpha1/ratelimit_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ type RateLimitValue struct {
440440
// Requests is the number of requests (or cost units, when used with
441441
// cost-based rate limiting) allowed per Unit.
442442
//
443-
// +kubebuilder:validation:Minimum=1
443+
// +kubebuilder:validation:Minimum=0
444444
// +kubebuilder:validation:Maximum=4294967295
445445
// +kubebuilder:validation:Format=int64
446446
Requests uint32 `json:"requests"`

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ spec:
18291829
cost-based rate limiting) allowed per Unit.
18301830
format: int64
18311831
maximum: 4294967295
1832-
minimum: 1
1832+
minimum: 0
18331833
type: integer
18341834
unit:
18351835
description: |-
@@ -2240,7 +2240,7 @@ spec:
22402240
cost-based rate limiting) allowed per Unit.
22412241
format: int64
22422242
maximum: 4294967295
2243-
minimum: 1
2243+
minimum: 0
22442244
type: integer
22452245
unit:
22462246
description: |-

charts/gateway-helm/charts/crds/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,7 +1828,7 @@ spec:
18281828
cost-based rate limiting) allowed per Unit.
18291829
format: int64
18301830
maximum: 4294967295
1831-
minimum: 1
1831+
minimum: 0
18321832
type: integer
18331833
unit:
18341834
description: |-
@@ -2239,7 +2239,7 @@ spec:
22392239
cost-based rate limiting) allowed per Unit.
22402240
format: int64
22412241
maximum: 4294967295
2242-
minimum: 1
2242+
minimum: 0
22432243
type: integer
22442244
unit:
22452245
description: |-
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed BackendTrafficPolicy global rate limits rejecting `requests: 0`, allowing zero-request global rules to block matching traffic while local zero limits remain rejected.

test/cel-validation/backendtrafficpolicy_test.go

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,7 @@ func TestBackendTrafficPolicyTarget(t *testing.T) {
19361936
wantErrors: []string{},
19371937
},
19381938
{
1939-
desc: "rate limit requests of zero is rejected",
1939+
desc: "rate limit requests of one is accepted",
19401940
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
19411941
btp.Spec = egv1a1.BackendTrafficPolicySpec{
19421942
PolicyTargetReferences: egv1a1.PolicyTargetReferences{
@@ -1953,7 +1953,7 @@ func TestBackendTrafficPolicyTarget(t *testing.T) {
19531953
Rules: []egv1a1.RateLimitRule{
19541954
{
19551955
Limit: egv1a1.RateLimitValue{
1956-
Requests: 0,
1956+
Requests: 1,
19571957
Unit: "Minute",
19581958
},
19591959
},
@@ -1962,10 +1962,36 @@ func TestBackendTrafficPolicyTarget(t *testing.T) {
19621962
},
19631963
}
19641964
},
1965-
wantErrors: []string{
1966-
"spec.ratelimit.global.rules[0].limit.requests",
1967-
"should be greater than or equal to 1",
1965+
wantErrors: []string{},
1966+
},
1967+
{
1968+
desc: "global rate limit requests of zero is accepted",
1969+
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
1970+
btp.Spec = egv1a1.BackendTrafficPolicySpec{
1971+
PolicyTargetReferences: egv1a1.PolicyTargetReferences{
1972+
TargetRef: &gwapiv1.LocalPolicyTargetReferenceWithSectionName{
1973+
LocalPolicyTargetReference: gwapiv1.LocalPolicyTargetReference{
1974+
Group: gwapiv1.Group("gateway.networking.k8s.io"),
1975+
Kind: gwapiv1.Kind("Gateway"),
1976+
Name: gwapiv1.ObjectName("eg"),
1977+
},
1978+
},
1979+
},
1980+
RateLimit: &egv1a1.RateLimitSpec{
1981+
Global: &egv1a1.GlobalRateLimit{
1982+
Rules: []egv1a1.RateLimitRule{
1983+
{
1984+
Limit: egv1a1.RateLimitValue{
1985+
Requests: 0,
1986+
Unit: "Minute",
1987+
},
1988+
},
1989+
},
1990+
},
1991+
},
1992+
}
19681993
},
1994+
wantErrors: []string{},
19691995
},
19701996
{
19711997
desc: "local rate limit requests at uint32 max boundary is accepted",
@@ -1997,7 +2023,7 @@ func TestBackendTrafficPolicyTarget(t *testing.T) {
19972023
wantErrors: []string{},
19982024
},
19992025
{
2000-
desc: "local rate limit requests of zero is rejected",
2026+
desc: "local rate limit requests of one is accepted",
20012027
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
20022028
btp.Spec = egv1a1.BackendTrafficPolicySpec{
20032029
PolicyTargetReferences: egv1a1.PolicyTargetReferences{
@@ -2014,7 +2040,7 @@ func TestBackendTrafficPolicyTarget(t *testing.T) {
20142040
Rules: []egv1a1.RateLimitRule{
20152041
{
20162042
Limit: egv1a1.RateLimitValue{
2017-
Requests: 0,
2043+
Requests: 1,
20182044
Unit: "Minute",
20192045
},
20202046
},
@@ -2023,10 +2049,36 @@ func TestBackendTrafficPolicyTarget(t *testing.T) {
20232049
},
20242050
}
20252051
},
2026-
wantErrors: []string{
2027-
"spec.ratelimit.local.rules[0].limit.requests",
2028-
"should be greater than or equal to 1",
2052+
wantErrors: []string{},
2053+
},
2054+
{
2055+
desc: "local rate limit requests of zero is accepted",
2056+
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
2057+
btp.Spec = egv1a1.BackendTrafficPolicySpec{
2058+
PolicyTargetReferences: egv1a1.PolicyTargetReferences{
2059+
TargetRef: &gwapiv1.LocalPolicyTargetReferenceWithSectionName{
2060+
LocalPolicyTargetReference: gwapiv1.LocalPolicyTargetReference{
2061+
Group: gwapiv1.Group("gateway.networking.k8s.io"),
2062+
Kind: gwapiv1.Kind("Gateway"),
2063+
Name: gwapiv1.ObjectName("eg"),
2064+
},
2065+
},
2066+
},
2067+
RateLimit: &egv1a1.RateLimitSpec{
2068+
Local: &egv1a1.LocalRateLimit{
2069+
Rules: []egv1a1.RateLimitRule{
2070+
{
2071+
Limit: egv1a1.RateLimitValue{
2072+
Requests: 0,
2073+
Unit: "Minute",
2074+
},
2075+
},
2076+
},
2077+
},
2078+
},
2079+
}
20292080
},
2081+
wantErrors: []string{},
20302082
},
20312083
{
20322084
desc: "valid connectionBufferLimitBytes format",

test/helm/gateway-crds-helm/all.out.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26446,7 +26446,7 @@ spec:
2644626446
cost-based rate limiting) allowed per Unit.
2644726447
format: int64
2644826448
maximum: 4294967295
26449-
minimum: 1
26449+
minimum: 0
2645026450
type: integer
2645126451
unit:
2645226452
description: |-
@@ -26857,7 +26857,7 @@ spec:
2685726857
cost-based rate limiting) allowed per Unit.
2685826858
format: int64
2685926859
maximum: 4294967295
26860-
minimum: 1
26860+
minimum: 0
2686126861
type: integer
2686226862
unit:
2686326863
description: |-

test/helm/gateway-crds-helm/e2e.out.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,7 +2384,7 @@ spec:
23842384
cost-based rate limiting) allowed per Unit.
23852385
format: int64
23862386
maximum: 4294967295
2387-
minimum: 1
2387+
minimum: 0
23882388
type: integer
23892389
unit:
23902390
description: |-
@@ -2795,7 +2795,7 @@ spec:
27952795
cost-based rate limiting) allowed per Unit.
27962796
format: int64
27972797
maximum: 4294967295
2798-
minimum: 1
2798+
minimum: 0
27992799
type: integer
28002800
unit:
28012801
description: |-

test/helm/gateway-crds-helm/envoy-gateway-crds.out.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,7 +2384,7 @@ spec:
23842384
cost-based rate limiting) allowed per Unit.
23852385
format: int64
23862386
maximum: 4294967295
2387-
minimum: 1
2387+
minimum: 0
23882388
type: integer
23892389
unit:
23902390
description: |-
@@ -2795,7 +2795,7 @@ spec:
27952795
cost-based rate limiting) allowed per Unit.
27962796
format: int64
27972797
maximum: 4294967295
2798-
minimum: 1
2798+
minimum: 0
27992799
type: integer
28002800
unit:
28012801
description: |-

0 commit comments

Comments
 (0)