Skip to content

Commit

Permalink
Change route sorting order to Exact > RegularExpression > PathPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
vixns committed Feb 27, 2024
1 parent f316c69 commit 12fdd61
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions internal/gatewayapi/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,19 @@ 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 {
return false
}
if x[j].PathMatch.SafeRegex != nil {
if x[j].PathMatch.Prefix != nil || x[j].PathMatch.SafeRegex != nil {
return false
}
}
}
if x[i].PathMatch != nil && x[i].PathMatch.Prefix != nil {
if x[j].PathMatch != nil {
if x[j].PathMatch.Exact != nil {
if x[j].PathMatch.Exact != nil || x[j].PathMatch.SafeRegex != nil {
return true
}
if x[j].PathMatch.SafeRegex != nil {
return false
}
}
}
if x[i].PathMatch != nil && x[i].PathMatch.SafeRegex != nil {
Expand All @@ -45,7 +39,7 @@ func (x XdsIRRoutes) Less(i, j int) bool {
return true
}
if x[j].PathMatch.Prefix != nil {
return true
return false
}
}
}
Expand Down Expand Up @@ -96,12 +90,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
}

0 comments on commit 12fdd61

Please sign in to comment.