Skip to content

Commit

Permalink
xds: Add support for Dynamic RDS in listener wrapper (grpc#4655)
Browse files Browse the repository at this point in the history
* Add support for Dynamic RDS in listener wrapper
  • Loading branch information
zasweq authored Aug 11, 2021
1 parent 88dc96b commit ad87ad0
Show file tree
Hide file tree
Showing 10 changed files with 914 additions and 63 deletions.
26 changes: 13 additions & 13 deletions xds/internal/resolver/watch_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (s) TestServiceWatch(t *testing.T) {
waitForWatchRouteConfig(ctx, t, xdsC, routeStr)

wantUpdate := serviceUpdate{virtualHost: &xdsclient.VirtualHost{Domains: []string{"target"}, Routes: []*xdsclient.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{cluster: {Weight: 1}}}}}}
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand All @@ -187,7 +187,7 @@ func (s) TestServiceWatch(t *testing.T) {
WeightedClusters: map[string]xdsclient.WeightedCluster{cluster: {Weight: 1}},
}},
}}
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand Down Expand Up @@ -223,7 +223,7 @@ func (s) TestServiceWatchLDSUpdate(t *testing.T) {
waitForWatchRouteConfig(ctx, t, xdsC, routeStr)

wantUpdate := serviceUpdate{virtualHost: &xdsclient.VirtualHost{Domains: []string{"target"}, Routes: []*xdsclient.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{cluster: {Weight: 1}}}}}}
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand All @@ -237,14 +237,14 @@ func (s) TestServiceWatchLDSUpdate(t *testing.T) {

// Another LDS update with a different RDS_name.
xdsC.InvokeWatchListenerCallback(xdsclient.ListenerUpdate{RouteConfigName: routeStr + "2"}, nil)
if err := xdsC.WaitForCancelRouteConfigWatch(ctx); err != nil {
if _, err := xdsC.WaitForCancelRouteConfigWatch(ctx); err != nil {
t.Fatalf("wait for cancel route watch failed: %v, want nil", err)
}
waitForWatchRouteConfig(ctx, t, xdsC, routeStr+"2")

// RDS update for the new name.
wantUpdate2 := serviceUpdate{virtualHost: &xdsclient.VirtualHost{Domains: []string{"target"}, Routes: []*xdsclient.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{cluster + "2": {Weight: 1}}}}}}
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback(routeStr+"2", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand Down Expand Up @@ -279,7 +279,7 @@ func (s) TestServiceWatchLDSUpdateMaxStreamDuration(t *testing.T) {
WeightedClusters: map[string]xdsclient.WeightedCluster{cluster: {Weight: 1}}}}},
ldsConfig: ldsConfig{maxStreamDuration: time.Second},
}
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand All @@ -303,7 +303,7 @@ func (s) TestServiceWatchLDSUpdateMaxStreamDuration(t *testing.T) {
Prefix: newStringP(""),
WeightedClusters: map[string]xdsclient.WeightedCluster{cluster + "2": {Weight: 1}}}},
}}
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand Down Expand Up @@ -337,7 +337,7 @@ func (s) TestServiceNotCancelRDSOnSameLDSUpdate(t *testing.T) {
Prefix: newStringP(""),
WeightedClusters: map[string]xdsclient.WeightedCluster{cluster: {Weight: 1}}}},
}}
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand All @@ -354,7 +354,7 @@ func (s) TestServiceNotCancelRDSOnSameLDSUpdate(t *testing.T) {
xdsC.InvokeWatchListenerCallback(xdsclient.ListenerUpdate{RouteConfigName: routeStr}, nil)
sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout)
defer sCancel()
if err := xdsC.WaitForCancelRouteConfigWatch(sCtx); err != context.DeadlineExceeded {
if _, err := xdsC.WaitForCancelRouteConfigWatch(sCtx); err != context.DeadlineExceeded {
t.Fatalf("wait for cancel route watch failed: %v, want nil", err)
}
}
Expand All @@ -378,7 +378,7 @@ func (s) TestServiceWatchInlineRDS(t *testing.T) {
xdsC.InvokeWatchListenerCallback(xdsclient.ListenerUpdate{RouteConfigName: routeStr}, nil)
waitForWatchRouteConfig(ctx, t, xdsC, routeStr)
wantUpdate := serviceUpdate{virtualHost: &xdsclient.VirtualHost{Domains: []string{"target"}, Routes: []*xdsclient.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{cluster: {Weight: 1}}}}}}
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand All @@ -402,7 +402,7 @@ func (s) TestServiceWatchInlineRDS(t *testing.T) {
VirtualHosts: []*xdsclient.VirtualHost{wantVirtualHosts2},
}}, nil)
// This inline RDS resource should cause the RDS watch to be canceled.
if err := xdsC.WaitForCancelRouteConfigWatch(ctx); err != nil {
if _, err := xdsC.WaitForCancelRouteConfigWatch(ctx); err != nil {
t.Fatalf("wait for cancel route watch failed: %v, want nil", err)
}
if err := verifyServiceUpdate(ctx, serviceUpdateCh, wantUpdate2); err != nil {
Expand All @@ -412,7 +412,7 @@ func (s) TestServiceWatchInlineRDS(t *testing.T) {
// Switch LDS update back to LDS with RDS name to watch.
xdsC.InvokeWatchListenerCallback(xdsclient.ListenerUpdate{RouteConfigName: routeStr}, nil)
waitForWatchRouteConfig(ctx, t, xdsC, routeStr)
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand All @@ -429,7 +429,7 @@ func (s) TestServiceWatchInlineRDS(t *testing.T) {
VirtualHosts: []*xdsclient.VirtualHost{wantVirtualHosts2},
}}, nil)
// This inline RDS resource should cause the RDS watch to be canceled.
if err := xdsC.WaitForCancelRouteConfigWatch(ctx); err != nil {
if _, err := xdsC.WaitForCancelRouteConfigWatch(ctx); err != nil {
t.Fatalf("wait for cancel route watch failed: %v, want nil", err)
}
if err := verifyServiceUpdate(ctx, serviceUpdateCh, wantUpdate2); err != nil {
Expand Down
38 changes: 19 additions & 19 deletions xds/internal/resolver/xds_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (s) TestXDSResolverWatchCallbackAfterClose(t *testing.T) {
// Call the watchAPI callback after closing the resolver, and make sure no
// update is triggerred on the ClientConn.
xdsR.Close()
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand Down Expand Up @@ -317,7 +317,7 @@ func (s) TestXDSResolverBadServiceUpdate(t *testing.T) {
// Invoke the watchAPI callback with a bad service update and wait for the
// ReportError method to be called on the ClientConn.
suErr := errors.New("bad serviceupdate")
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{}, suErr)
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{}, suErr)

if gotErrVal, gotErr := tcc.errorCh.Receive(ctx); gotErr != nil || gotErrVal != suErr {
t.Fatalf("ClientConn.ReportError() received %v, want %v", gotErrVal, suErr)
Expand Down Expand Up @@ -406,7 +406,7 @@ func (s) TestXDSResolverGoodServiceUpdate(t *testing.T) {
} {
// Invoke the watchAPI callback with a good service update and wait for the
// UpdateState method to be called on the ClientConn.
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand Down Expand Up @@ -480,7 +480,7 @@ func (s) TestXDSResolverRequestHash(t *testing.T) {
waitForWatchRouteConfig(ctx, t, xdsC, routeStr)
// Invoke watchAPI callback with a good service update (with hash policies
// specified) and wait for UpdateState method to be called on ClientConn.
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand Down Expand Up @@ -541,7 +541,7 @@ func (s) TestXDSResolverRemovedWithRPCs(t *testing.T) {

// Invoke the watchAPI callback with a good service update and wait for the
// UpdateState method to be called on the ClientConn.
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand Down Expand Up @@ -572,7 +572,7 @@ func (s) TestXDSResolverRemovedWithRPCs(t *testing.T) {

// Delete the resource
suErr := xdsclient.NewErrorf(xdsclient.ErrorTypeResourceNotFound, "resource removed error")
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{}, suErr)
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{}, suErr)

if _, err = tcc.stateCh.Receive(ctx); err != nil {
t.Fatalf("Error waiting for UpdateState to be called: %v", err)
Expand Down Expand Up @@ -601,7 +601,7 @@ func (s) TestXDSResolverRemovedResource(t *testing.T) {

// Invoke the watchAPI callback with a good service update and wait for the
// UpdateState method to be called on the ClientConn.
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand Down Expand Up @@ -651,7 +651,7 @@ func (s) TestXDSResolverRemovedResource(t *testing.T) {
// Delete the resource. The channel should receive a service config with the
// original cluster but with an erroring config selector.
suErr := xdsclient.NewErrorf(xdsclient.ErrorTypeResourceNotFound, "resource removed error")
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{}, suErr)
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{}, suErr)

if gotState, err = tcc.stateCh.Receive(ctx); err != nil {
t.Fatalf("Error waiting for UpdateState to be called: %v", err)
Expand Down Expand Up @@ -712,7 +712,7 @@ func (s) TestXDSResolverWRR(t *testing.T) {

// Invoke the watchAPI callback with a good service update and wait for the
// UpdateState method to be called on the ClientConn.
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand Down Expand Up @@ -772,7 +772,7 @@ func (s) TestXDSResolverMaxStreamDuration(t *testing.T) {

// Invoke the watchAPI callback with a good service update and wait for the
// UpdateState method to be called on the ClientConn.
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand Down Expand Up @@ -862,7 +862,7 @@ func (s) TestXDSResolverDelayedOnCommitted(t *testing.T) {

// Invoke the watchAPI callback with a good service update and wait for the
// UpdateState method to be called on the ClientConn.
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand Down Expand Up @@ -912,7 +912,7 @@ func (s) TestXDSResolverDelayedOnCommitted(t *testing.T) {

// Perform TWO updates to ensure the old config selector does not hold a
// reference to test-cluster-1.
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand All @@ -922,7 +922,7 @@ func (s) TestXDSResolverDelayedOnCommitted(t *testing.T) {
}, nil)
tcc.stateCh.Receive(ctx) // Ignore the first update.

xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand Down Expand Up @@ -961,7 +961,7 @@ func (s) TestXDSResolverDelayedOnCommitted(t *testing.T) {
// test-cluster-1.
res.OnCommitted()

xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand Down Expand Up @@ -1012,15 +1012,15 @@ func (s) TestXDSResolverGoodUpdateAfterError(t *testing.T) {
// Invoke the watchAPI callback with a bad service update and wait for the
// ReportError method to be called on the ClientConn.
suErr := errors.New("bad serviceupdate")
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{}, suErr)
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{}, suErr)

if gotErrVal, gotErr := tcc.errorCh.Receive(ctx); gotErr != nil || gotErrVal != suErr {
t.Fatalf("ClientConn.ReportError() received %v, want %v", gotErrVal, suErr)
}

// Invoke the watchAPI callback with a good service update and wait for the
// UpdateState method to be called on the ClientConn.
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand All @@ -1040,7 +1040,7 @@ func (s) TestXDSResolverGoodUpdateAfterError(t *testing.T) {
// Invoke the watchAPI callback with a bad service update and wait for the
// ReportError method to be called on the ClientConn.
suErr2 := errors.New("bad serviceupdate 2")
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{}, suErr2)
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{}, suErr2)
if gotErrVal, gotErr := tcc.errorCh.Receive(ctx); gotErr != nil || gotErrVal != suErr2 {
t.Fatalf("ClientConn.ReportError() received %v, want %v", gotErrVal, suErr2)
}
Expand All @@ -1066,7 +1066,7 @@ func (s) TestXDSResolverResourceNotFoundError(t *testing.T) {
// Invoke the watchAPI callback with a bad service update and wait for the
// ReportError method to be called on the ClientConn.
suErr := xdsclient.NewErrorf(xdsclient.ErrorTypeResourceNotFound, "resource removed error")
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{}, suErr)
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{}, suErr)

if gotErrVal, gotErr := tcc.errorCh.Receive(ctx); gotErr != context.DeadlineExceeded {
t.Fatalf("ClientConn.ReportError() received %v, %v, want channel recv timeout", gotErrVal, gotErr)
Expand Down Expand Up @@ -1295,7 +1295,7 @@ func (s) TestXDSResolverHTTPFilters(t *testing.T) {

// Invoke the watchAPI callback with a good service update and wait for the
// UpdateState method to be called on the ClientConn.
xdsC.InvokeWatchRouteConfigCallback(xdsclient.RouteConfigUpdate{
xdsC.InvokeWatchRouteConfigCallback("", xdsclient.RouteConfigUpdate{
VirtualHosts: []*xdsclient.VirtualHost{
{
Domains: []string{targetStr},
Expand Down
Loading

0 comments on commit ad87ad0

Please sign in to comment.