-
Notifications
You must be signed in to change notification settings - Fork 551
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
istio/1.12/patches/istio/20231104-gatewayapi-catchall.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |