Skip to content

Commit

Permalink
add the catch all case (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlanni committed Nov 3, 2023
1 parent 70176cd commit 26654ae
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions istio/1.12/patches/istio/20231104-gatewayapi-catchall.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
diff -Naur istio/pilot/pkg/config/kube/gateway/conversion.go istio-new/pilot/pkg/config/kube/gateway/conversion.go
--- istio/pilot/pkg/config/kube/gateway/conversion.go 2023-11-03 20:09:38.000000000 +0800
+++ istio-new/pilot/pkg/config/kube/gateway/conversion.go 2023-11-03 20:02:26.000000000 +0800
@@ -165,6 +165,34 @@
return result
}

+// isCatchAll returns true if HTTPMatchRequest is a catchall match otherwise
+// false. Note - this may not be exactly "catch all" as we don't know the full
+// class of possible inputs As such, this is used only for optimization.
+func isCatchAllMatch(m *istio.HTTPMatchRequest) bool {
+ catchall := false
+ if m.Uri != nil {
+ switch m := m.Uri.MatchType.(type) {
+ case *istio.StringMatch_Prefix:
+ catchall = m.Prefix == "/"
+ case *istio.StringMatch_Regex:
+ catchall = m.Regex == "*"
+ }
+ }
+ // A Match is catch all if and only if it has no match set
+ // and URI has a prefix / or regex *.
+ return catchall &&
+ len(m.Headers) == 0 &&
+ len(m.QueryParams) == 0 &&
+ len(m.SourceLabels) == 0 &&
+ len(m.WithoutHeaders) == 0 &&
+ len(m.Gateways) == 0 &&
+ m.Method == nil &&
+ m.Scheme == nil &&
+ m.Port == 0 &&
+ m.Authority == nil &&
+ m.SourceNamespace == ""
+}
+
// getURIRank ranks a URI match type. Exact > Prefix > Regex
func getURIRank(match *istio.HTTPMatchRequest) int {
if match.Uri == nil {
@@ -212,6 +240,11 @@
} else if len(routes[j].Match) == 0 {
return true
}
+ if isCatchAllMatch(routes[i].Match[0]) {
+ return false
+ } else if isCatchAllMatch(routes[j].Match[0]) {
+ return true
+ }
// Only look at match[0], we always generate only one match
m1, m2 := routes[i].Match[0], routes[j].Match[0]
r1, r2 := getURIRank(m1), getURIRank(m2)

0 comments on commit 26654ae

Please sign in to comment.