Skip to content

Commit

Permalink
move "/" to route prefix (#2394)
Browse files Browse the repository at this point in the history
Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
  • Loading branch information
zhaohuabing authored Jan 3, 2024
1 parent 8c2112f commit 49e7aec
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/gatewayapi/backendtrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (t *Translator) translateBackendTrafficPolicyForRoute(policy *egv1a1.Backen
}

// Apply IR to all relevant routes
prefix := irRoutePrefix(route) + "/" // Prevent mismatching routes with the same prefix
prefix := irRoutePrefix(route)
for _, ir := range xdsIR {
for _, http := range ir.HTTP {
for _, r := range http.Routes {
Expand Down
8 changes: 5 additions & 3 deletions internal/gatewayapi/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,17 @@ func irUDPListenerName(listener *ListenerContext, udpRoute *UDPRouteContext) str
}

func irRoutePrefix(route RouteContext) string {
return fmt.Sprintf("%s/%s/%s", strings.ToLower(string(GetRouteType(route))), route.GetNamespace(), route.GetName())
// add a "/" at the end of the prefix to prevent mismatching routes with the
// same prefix. For example, route prefix "/foo/" should not match a route "/foobar".
return fmt.Sprintf("%s/%s/%s/", strings.ToLower(string(GetRouteType(route))), route.GetNamespace(), route.GetName())
}

func irRouteName(route RouteContext, ruleIdx, matchIdx int) string {
return fmt.Sprintf("%s/rule/%d/match/%d", irRoutePrefix(route), ruleIdx, matchIdx)
return fmt.Sprintf("%srule/%d/match/%d", irRoutePrefix(route), ruleIdx, matchIdx)
}

func irRouteDestinationName(route RouteContext, ruleIdx int) string {
return fmt.Sprintf("%s/rule/%d", irRoutePrefix(route), ruleIdx)
return fmt.Sprintf("%srule/%d", irRoutePrefix(route), ruleIdx)
}

func irTLSConfigs(tlsSecrets []*v1.Secret) []*ir.TLSListenerConfig {
Expand Down
2 changes: 1 addition & 1 deletion internal/gatewayapi/securitypolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (t *Translator) translateSecurityPolicyForRoute(
// Apply IR to all relevant routes
// Note: there are multiple features in a security policy, even if some of them
// are invalid, we still want to apply the valid ones.
prefix := irRoutePrefix(route) + "/" // Prevent mismatching routes with the same prefix
prefix := irRoutePrefix(route)
for _, ir := range xdsIR {
for _, http := range ir.HTTP {
for _, r := range http.Routes {
Expand Down

0 comments on commit 49e7aec

Please sign in to comment.