Skip to content

Commit

Permalink
xds: accept either "" or "/" as the prefix for the default route (#3535)
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed Apr 15, 2020
1 parent ff40ef4 commit f9a1aeb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions xds/internal/client/v2client_rds.go
Expand Up @@ -95,8 +95,8 @@ func getClusterFromRouteConfiguration(rc *xdspb.RouteConfiguration, host string)
return ""
}
dr := vh.Routes[len(vh.Routes)-1]
if match := dr.GetMatch(); match == nil || match.GetPrefix() != "" {
// The matched virtual host is invalid.
if match := dr.GetMatch(); match == nil || (match.GetPrefix() != "" && match.GetPrefix() != "/") {
// The matched virtual host is invalid. Match is not "" or "/".
return ""
}
if route := dr.GetRoute(); route != nil {
Expand Down
17 changes: 16 additions & 1 deletion xds/internal/client/v2client_rds_test.go
Expand Up @@ -133,10 +133,25 @@ func (s) TestRDSGetClusterFromRouteConfiguration(t *testing.T) {
wantCluster: "",
},
{
name: "good-route-config",
name: "good-route-config-with-empty-string-route",
rc: goodRouteConfig1,
wantCluster: goodClusterName1,
},
{
// default route's match is not empty string, but "/".
name: "good-route-config-with-slash-string-route",
rc: &xdspb.RouteConfiguration{
Name: goodRouteName1,
VirtualHosts: []*routepb.VirtualHost{{
Domains: []string{goodLDSTarget1},
Routes: []*routepb.Route{{
Match: &routepb.RouteMatch{PathSpecifier: &routepb.RouteMatch_Prefix{Prefix: "/"}},
Action: &routepb.Route_Route{
Route: &routepb.RouteAction{
ClusterSpecifier: &routepb.RouteAction_Cluster{Cluster: goodClusterName1},
}}}}}}},
wantCluster: goodClusterName1,
},
}

for _, test := range tests {
Expand Down

0 comments on commit f9a1aeb

Please sign in to comment.