Fix kubernetes findMatchingHostname improperly checking specificity

This commit is contained in:
Colorman 2026-01-26 12:13:17 +01:00
parent 75ac25bb31
commit 7db4dcf299
No known key found for this signature in database
2 changed files with 9 additions and 9 deletions

View file

@ -1103,15 +1103,8 @@ func findMatchingHostname(h1, h2 gatev1.Hostname) gatev1.Hostname {
return ""
}
return lessWildcards(h1, h2)
}
func lessWildcards(h1, h2 gatev1.Hostname) gatev1.Hostname {
if strings.Count(string(h1), "*") > strings.Count(string(h2), "*") {
return h2
}
return h1
// since h1 is a suffix of h2, we know h2 is the more specific host
return h2
}
func allowRoute(listener gatewayListener, routeNamespace, routeKind string) bool {

View file

@ -7630,6 +7630,13 @@ func Test_findMatchingHostnames(t *testing.T) {
want: []gatev1.Hostname{"toto.foo.com", "test.foo.com"},
wantOk: true,
},
{
desc: "Matching wildcard subsubdomain with listener wildcard subdomain",
listenerHostname: ptr.To(gatev1.Hostname("*.foo.com")),
routeHostnames: []gatev1.Hostname{"*.bar.foo.com"},
want: []gatev1.Hostname{"*.bar.foo.com"},
wantOk: true,
},
}
for _, test := range testCases {