Skip to content

Commit

Permalink
Change route sorting order to Exact > RegularExpression > PathPrefix (e…
Browse files Browse the repository at this point in the history
…nvoyproxy#2579)

* Change route sorting order to Exact > RegularExpression > PathPrefix

kubernetes-sigs/gateway-api#1770
kubernetes-sigs/gateway-api#1855

Signed-off-by: Stéphane Cottin <[email protected]>
  • Loading branch information
vixns authored Apr 5, 2024
1 parent dd034a0 commit 11f56fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions internal/gatewayapi/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,33 @@ func (x XdsIRRoutes) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
func (x XdsIRRoutes) Less(i, j int) bool {

// 1. Sort based on path match type
// Exact > PathPrefix > RegularExpression
// Exact > RegularExpression > PathPrefix
if x[i].PathMatch != nil && x[i].PathMatch.Exact != nil {
if x[j].PathMatch != nil {
if x[j].PathMatch.Prefix != nil {
if x[j].PathMatch.SafeRegex != nil {
return false
}
if x[j].PathMatch.SafeRegex != nil {
if x[j].PathMatch.Prefix != nil {
return false
}
}
}
if x[i].PathMatch != nil && x[i].PathMatch.Prefix != nil {
if x[i].PathMatch != nil && x[i].PathMatch.SafeRegex != nil {
if x[j].PathMatch != nil {
if x[j].PathMatch.Exact != nil {
return true
}
if x[j].PathMatch.SafeRegex != nil {
if x[j].PathMatch.Prefix != nil {
return false
}
}
}
if x[i].PathMatch != nil && x[i].PathMatch.SafeRegex != nil {
if x[i].PathMatch != nil && x[i].PathMatch.Prefix != nil {
if x[j].PathMatch != nil {
if x[j].PathMatch.Exact != nil {
return true
}
if x[j].PathMatch.Prefix != nil {
if x[j].PathMatch.SafeRegex != nil {
return true
}
}
Expand Down Expand Up @@ -96,12 +96,12 @@ func pathMatchCount(pathMatch *ir.StringMatch) int {
if pathMatch.Exact != nil {
return len(*pathMatch.Exact)
}
if pathMatch.Prefix != nil {
return len(*pathMatch.Prefix)
}
if pathMatch.SafeRegex != nil {
return len(*pathMatch.SafeRegex)
}
if pathMatch.Prefix != nil {
return len(*pathMatch.Prefix)
}
}
return 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ xdsIR:
weight: 1
hostname: '*'
isHTTP2: true
name: grpcroute/default/grpcroute-1/rule/0/match/0/*
name: grpcroute/default/grpcroute-1/rule/0/match/1/*
pathMatch:
distinct: false
name: ""
prefix: /com.ExampleExact
safeRegex: /com.[A-Z]+/[A-Za-z_][A-Za-z_0-9]*
- backendWeights:
invalid: 0
valid: 0
Expand All @@ -145,8 +145,8 @@ xdsIR:
weight: 1
hostname: '*'
isHTTP2: true
name: grpcroute/default/grpcroute-1/rule/0/match/1/*
name: grpcroute/default/grpcroute-1/rule/0/match/0/*
pathMatch:
distinct: false
name: ""
safeRegex: /com.[A-Z]+/[A-Za-z_][A-Za-z_0-9]*
prefix: /com.ExampleExact

0 comments on commit 11f56fd

Please sign in to comment.