Skip to content

Commit 11f56fd

Browse files
authored
Change route sorting order to Exact > RegularExpression > PathPrefix (envoyproxy#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]>
1 parent dd034a0 commit 11f56fd

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

internal/gatewayapi/sort.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,33 @@ func (x XdsIRRoutes) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
1818
func (x XdsIRRoutes) Less(i, j int) bool {
1919

2020
// 1. Sort based on path match type
21-
// Exact > PathPrefix > RegularExpression
21+
// Exact > RegularExpression > PathPrefix
2222
if x[i].PathMatch != nil && x[i].PathMatch.Exact != nil {
2323
if x[j].PathMatch != nil {
24-
if x[j].PathMatch.Prefix != nil {
24+
if x[j].PathMatch.SafeRegex != nil {
2525
return false
2626
}
27-
if x[j].PathMatch.SafeRegex != nil {
27+
if x[j].PathMatch.Prefix != nil {
2828
return false
2929
}
3030
}
3131
}
32-
if x[i].PathMatch != nil && x[i].PathMatch.Prefix != nil {
32+
if x[i].PathMatch != nil && x[i].PathMatch.SafeRegex != nil {
3333
if x[j].PathMatch != nil {
3434
if x[j].PathMatch.Exact != nil {
3535
return true
3636
}
37-
if x[j].PathMatch.SafeRegex != nil {
37+
if x[j].PathMatch.Prefix != nil {
3838
return false
3939
}
4040
}
4141
}
42-
if x[i].PathMatch != nil && x[i].PathMatch.SafeRegex != nil {
42+
if x[i].PathMatch != nil && x[i].PathMatch.Prefix != nil {
4343
if x[j].PathMatch != nil {
4444
if x[j].PathMatch.Exact != nil {
4545
return true
4646
}
47-
if x[j].PathMatch.Prefix != nil {
47+
if x[j].PathMatch.SafeRegex != nil {
4848
return true
4949
}
5050
}
@@ -96,12 +96,12 @@ func pathMatchCount(pathMatch *ir.StringMatch) int {
9696
if pathMatch.Exact != nil {
9797
return len(*pathMatch.Exact)
9898
}
99-
if pathMatch.Prefix != nil {
100-
return len(*pathMatch.Prefix)
101-
}
10299
if pathMatch.SafeRegex != nil {
103100
return len(*pathMatch.SafeRegex)
104101
}
102+
if pathMatch.Prefix != nil {
103+
return len(*pathMatch.Prefix)
104+
}
105105
}
106106
return 0
107107
}

internal/gatewayapi/testdata/grpcroute-with-service-match.out.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ xdsIR:
126126
weight: 1
127127
hostname: '*'
128128
isHTTP2: true
129-
name: grpcroute/default/grpcroute-1/rule/0/match/0/*
129+
name: grpcroute/default/grpcroute-1/rule/0/match/1/*
130130
pathMatch:
131131
distinct: false
132132
name: ""
133-
prefix: /com.ExampleExact
133+
safeRegex: /com.[A-Z]+/[A-Za-z_][A-Za-z_0-9]*
134134
- backendWeights:
135135
invalid: 0
136136
valid: 0
@@ -145,8 +145,8 @@ xdsIR:
145145
weight: 1
146146
hostname: '*'
147147
isHTTP2: true
148-
name: grpcroute/default/grpcroute-1/rule/0/match/1/*
148+
name: grpcroute/default/grpcroute-1/rule/0/match/0/*
149149
pathMatch:
150150
distinct: false
151151
name: ""
152-
safeRegex: /com.[A-Z]+/[A-Za-z_][A-Za-z_0-9]*
152+
prefix: /com.ExampleExact

0 commit comments

Comments
 (0)