Skip to content

Commit

Permalink
make catch all route name unique across mulitple hosts
Browse files Browse the repository at this point in the history
Signed-off-by: huabing zhao <[email protected]>
  • Loading branch information
zhaohuabing committed Feb 14, 2024
1 parent d78c089 commit 8674c4a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ xdsIR:
directResponse:
statusCode: 404
hostname: gateway.envoyproxy.io
name: catch-all
name: gateway_envoyproxy_io/catch_all
pathMatch:
distinct: false
name: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ xdsIR:
directResponse:
statusCode: 404
hostname: www.foo.com
name: catch-all
name: www_foo_com/catch_all
pathMatch:
distinct: false
name: ""
Expand All @@ -289,7 +289,7 @@ xdsIR:
directResponse:
statusCode: 404
hostname: www.bar.com
name: catch-all
name: www_bar_com/catch_all
pathMatch:
distinct: false
name: ""
Expand Down
4 changes: 2 additions & 2 deletions internal/gatewayapi/testdata/securitypolicy-with-oidc.in.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ httpRoutes:
name: httproute-2
spec:
hostnames:
- www.example.com
- www.foo.com
parentRefs:
- namespace: envoy-gateway
name: gateway-1
sectionName: http
rules:
- matches:
- path:
value: "/bar"
value: "/"
backendRefs:
- name: service-1
port: 8080
Expand Down
12 changes: 6 additions & 6 deletions internal/gatewayapi/testdata/securitypolicy-with-oidc.out.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ httpRoutes:
namespace: default
spec:
hostnames:
- www.example.com
- www.foo.com
parentRefs:
- name: gateway-1
namespace: envoy-gateway
Expand All @@ -97,7 +97,7 @@ httpRoutes:
port: 8080
matches:
- path:
value: /bar
value: /
status:
parents:
- conditions:
Expand Down Expand Up @@ -256,8 +256,8 @@ xdsIR:
port: 8080
protocol: HTTP
weight: 1
hostname: www.example.com
name: httproute/default/httproute-2/rule/0/match/0/www_example_com
hostname: www.foo.com
name: httproute/default/httproute-2/rule/0/match/0/www_foo_com
oidc:
clientID: client1.apps.googleusercontent.com
clientSecret: Y2xpZW50MTpzZWNyZXQK
Expand All @@ -272,14 +272,14 @@ xdsIR:
pathMatch:
distinct: false
name: ""
prefix: /bar
prefix: /
- backendWeights:
invalid: 0
valid: 0
directResponse:
statusCode: 404
hostname: www.example.com
name: catch-all
name: www_example_com/catch_all
pathMatch:
distinct: false
name: ""
Expand Down
6 changes: 5 additions & 1 deletion internal/gatewayapi/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
package gatewayapi

import (
"fmt"
"strings"

"golang.org/x/exp/maps"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/utils/ptr"
Expand Down Expand Up @@ -240,8 +243,9 @@ func addCatchAllRoute(xdsIR map[string]*ir.Xds) {

for host, needCatchAllRoute := range needCatchAllRoutePerHost {
if needCatchAllRoute {
underscoredHost := strings.ReplaceAll(host, ".", "_")
http.Routes = append(http.Routes, &ir.HTTPRoute{
Name: "catch-all",
Name: fmt.Sprintf("%s/catch_all", underscoredHost),
PathMatch: &ir.StringMatch{
Prefix: ptr.To("/"),
},
Expand Down

0 comments on commit 8674c4a

Please sign in to comment.