Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPRoute: allow more match clauses #3205

Merged
merged 7 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apis/v1/httproute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type HTTPRouteSpec struct {
// +optional
// +kubebuilder:validation:MaxItems=16
// +kubebuilder:default={{matches: {{path: {type: "PathPrefix", value: "/"}}}}}
// +kubebuilder:validation:XValidation:message="While 16 rules and 64 matches are allowed, the total matches must be less than 128",rule="(self.size() > 0 ? self[0].matches.size() : 0) + (self.size() > 1 ? self[1].matches.size() : 0) + (self.size() > 2 ? self[2].matches.size() : 0) + (self.size() > 3 ? self[3].matches.size() : 0) + (self.size() > 4 ? self[4].matches.size() : 0) + (self.size() > 5 ? self[5].matches.size() : 0) + (self.size() > 6 ? self[6].matches.size() : 0) + (self.size() > 7 ? self[7].matches.size() : 0) + (self.size() > 8 ? self[8].matches.size() : 0) + (self.size() > 9 ? self[9].matches.size() : 0) + (self.size() > 10 ? self[10].matches.size() : 0) + (self.size() > 11 ? self[11].matches.size() : 0) + (self.size() > 12 ? self[12].matches.size() : 0) + (self.size() > 13 ? self[13].matches.size() : 0) + (self.size() > 14 ? self[14].matches.size() : 0) + (self.size() > 15 ? self[15].matches.size() : 0) <= 128"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely gross, but the least bad we can offer until CEL cost estimation allows us to use map here (Kubernetes 1.30+). Here's the CEL playground link for future readers.

howardjohn marked this conversation as resolved.
Show resolved Hide resolved
Rules []HTTPRouteRule `json:"rules,omitempty"`
}

Expand Down Expand Up @@ -190,7 +191,7 @@ type HTTPRouteRule struct {
// parent a request is coming from, a HTTP 404 status code MUST be returned.
//
// +optional
// +kubebuilder:validation:MaxItems=8
// +kubebuilder:validation:MaxItems=64
// +kubebuilder:default={{path:{ type: "PathPrefix", value: "/"}}}
Matches []HTTPRouteMatch `json:"matches,omitempty"`

Expand Down
32 changes: 30 additions & 2 deletions config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 30 additions & 2 deletions config/crd/standard/gateway.networking.k8s.io_httproutes.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions pkg/test/cel/httproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,48 @@ func TestHTTPRouteRule(t *testing.T) {
},
},
},
{
name: "too many matches and rules",
wantErrors: []string{"the total matches must be less than 128"},
rules: func() []gatewayv1.HTTPRouteRule {
match := gatewayv1.HTTPRouteMatch{
Path: &gatewayv1.HTTPPathMatch{
Type: ptrTo(gatewayv1.PathMatchType("PathPrefix")),
Value: ptrTo("/"),
},
}
var rules []gatewayv1.HTTPRouteRule
for range 7 { // rules
rule := gatewayv1.HTTPRouteRule{}
for range 20 { // matches
rule.Matches = append(rule.Matches, match)
}
rules = append(rules, rule)
}
return rules
}(),
},
{
name: "many matches and few rules",
wantErrors: nil,
rules: func() []gatewayv1.HTTPRouteRule {
match := gatewayv1.HTTPRouteMatch{
Path: &gatewayv1.HTTPPathMatch{
Type: ptrTo(gatewayv1.PathMatchType("PathPrefix")),
Value: ptrTo("/"),
},
}
var rules []gatewayv1.HTTPRouteRule
for range 2 { // rules
rule := gatewayv1.HTTPRouteRule{}
for range 48 { // matches
rule.Matches = append(rule.Matches, match)
}
rules = append(rules, rule)
}
return rules
}(),
},
}

for _, tc := range tests {
Expand Down