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

chore(MeshHTTPRoute): default catch all path in route match #6993

Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 18 additions & 7 deletions pkg/plugins/policies/meshhttproute/plugin/v1alpha1/listeners.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,8 @@ func prepareRoutes(
}
}

catchAllMatch := []api.Match{{
Path: &api.PathMatch{
Value: "/",
Type: api.PathPrefix,
},
}}
catchAllPathMatch := api.PathMatch{Value: "/", Type: api.PathPrefix}
catchAllMatch := []api.Match{{Path: pointer.To(catchAllPathMatch)}}

noCatchAll := slices.IndexFunc(rules, func(rule api.Rule) bool {
return reflect.DeepEqual(rule.Matches, catchAllMatch)
Expand All @@ -146,8 +142,23 @@ func prepareRoutes(

var routes []Route
for _, rule := range rules {
var matches []api.Match

for _, match := range rule.Matches {
if match.Path == nil {
// According to Envoy docs, match must have precisely one of
// prefix, path, safe_regex, connect_matcher,
// path_separated_prefix, path_match_policy set, so when policy
// doesn't specify explicit type of matching, we are assuming
// "catch all" path (any path starting with "/").
match.Path = pointer.To(catchAllPathMatch)
}

matches = append(matches, match)
}

route := Route{
Matches: rule.Matches,
Matches: matches,
}

if rule.Default.BackendRefs != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ resources:
cluster: backend-_0_
timeout: 0s
- match:
prefix: /
queryParameters:
- name: v1
stringMatch:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ resources:
- name: foo-prefix
stringMatch:
prefix: x
prefix: /
route:
cluster: backend
timeout: 0s
Expand Down