From f9a1aeb4f25273448942c02780bd80c25bde2308 Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Wed, 15 Apr 2020 16:50:46 -0700 Subject: [PATCH] xds: accept either "" or "/" as the prefix for the default route (#3535) --- xds/internal/client/v2client_rds.go | 4 ++-- xds/internal/client/v2client_rds_test.go | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/xds/internal/client/v2client_rds.go b/xds/internal/client/v2client_rds.go index 4141d31d459..14ae6cdfc37 100644 --- a/xds/internal/client/v2client_rds.go +++ b/xds/internal/client/v2client_rds.go @@ -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 { diff --git a/xds/internal/client/v2client_rds_test.go b/xds/internal/client/v2client_rds_test.go index 6c10b22d2df..8bbabb9828f 100644 --- a/xds/internal/client/v2client_rds_test.go +++ b/xds/internal/client/v2client_rds_test.go @@ -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 {