Skip to content

Commit

Permalink
api: increase rate-limit global rules limit (#2906)
Browse files Browse the repository at this point in the history
* feat: increase rate-limit global rules limit (#2900)

Signed-off-by: ShyunnY <1147212064@qq.com>

* fix: supplemental cel testing

Signed-off-by: ShyunnY <1147212064@qq.com>

---------

Signed-off-by: ShyunnY <1147212064@qq.com>
  • Loading branch information
ShyunnY authored Mar 14, 2024
1 parent 642b1fb commit 975ef6e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/ratelimit_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type GlobalRateLimit struct {
// matches two rules, one rate limited and one not, the final decision will be
// to rate limit the request.
//
// +kubebuilder:validation:MaxItems=16
// +kubebuilder:validation:MaxItems=64
Rules []RateLimitRule `json:"rules"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ spec:
required:
- limit
type: object
maxItems: 16
maxItems: 64
type: array
required:
- rules
Expand Down
68 changes: 68 additions & 0 deletions test/cel-validation/backendtrafficpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,74 @@ func TestBackendTrafficPolicyTarget(t *testing.T) {
},
wantErrors: []string{},
},
{
desc: "valid count of Global rate limit rules items",
mutate: func(btp *egv1a1.BackendTrafficPolicy) {

rules := make([]egv1a1.RateLimitRule, 64)
rule := egv1a1.RateLimitRule{
Limit: egv1a1.RateLimitValue{
Requests: 10,
Unit: "Minute",
},
}
for i := range rules {
rules[i] = rule
}

btp.Spec = egv1a1.BackendTrafficPolicySpec{
TargetRef: gwapiv1a2.PolicyTargetReferenceWithSectionName{
PolicyTargetReference: gwapiv1a2.PolicyTargetReference{
Group: gwapiv1a2.Group("gateway.networking.k8s.io"),
Kind: gwapiv1a2.Kind("Gateway"),
Name: gwapiv1a2.ObjectName("eg"),
},
},
RateLimit: &egv1a1.RateLimitSpec{
Type: egv1a1.GlobalRateLimitType,
Global: &egv1a1.GlobalRateLimit{
Rules: rules,
},
},
}
},
wantErrors: []string{},
},
{
desc: "invalid count of Global rate limit rules items",
mutate: func(btp *egv1a1.BackendTrafficPolicy) {

rules := make([]egv1a1.RateLimitRule, 65)
rule := egv1a1.RateLimitRule{
Limit: egv1a1.RateLimitValue{
Requests: 10,
Unit: "Minute",
},
}
for i := range rules {
rules[i] = rule
}

btp.Spec = egv1a1.BackendTrafficPolicySpec{
TargetRef: gwapiv1a2.PolicyTargetReferenceWithSectionName{
PolicyTargetReference: gwapiv1a2.PolicyTargetReference{
Group: gwapiv1a2.Group("gateway.networking.k8s.io"),
Kind: gwapiv1a2.Kind("Gateway"),
Name: gwapiv1a2.ObjectName("eg"),
},
},
RateLimit: &egv1a1.RateLimitSpec{
Type: egv1a1.GlobalRateLimitType,
Global: &egv1a1.GlobalRateLimit{
Rules: rules,
},
},
}
},
wantErrors: []string{
`[spec.rateLimit.global.rules: Too many: 65: must have at most 64 items, <nil>: Invalid value: "null": some validation rules were not checked because the object was invalid; correct the existing errors to complete validation]`,
},
},
}

for _, tc := range cases {
Expand Down

0 comments on commit 975ef6e

Please sign in to comment.