diff --git a/internal/gatewayapi/sort.go b/internal/gatewayapi/sort.go index 00a5fc6389d..75d9ebc503a 100644 --- a/internal/gatewayapi/sort.go +++ b/internal/gatewayapi/sort.go @@ -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 } } @@ -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 } diff --git a/internal/gatewayapi/testdata/grpcroute-with-service-match.out.yaml b/internal/gatewayapi/testdata/grpcroute-with-service-match.out.yaml index 9624ffcaab1..ca598b9d046 100644 --- a/internal/gatewayapi/testdata/grpcroute-with-service-match.out.yaml +++ b/internal/gatewayapi/testdata/grpcroute-with-service-match.out.yaml @@ -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 @@ -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