Skip to content

Commit 6e6914a

Browse files
authored
completely delete WatchListener and WatchRouteConfig APIs (#6849)
1 parent 836e5de commit 6e6914a

16 files changed

+421
-636
lines changed

xds/internal/testutils/fakeclient/client.go

Lines changed: 0 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"google.golang.org/grpc/xds/internal/xdsclient"
2727
"google.golang.org/grpc/xds/internal/xdsclient/bootstrap"
2828
"google.golang.org/grpc/xds/internal/xdsclient/load"
29-
"google.golang.org/grpc/xds/internal/xdsclient/xdsresource"
3029
)
3130

3231
// Client is a fake implementation of an xds client. It exposes a bunch of
@@ -38,151 +37,10 @@ type Client struct {
3837
xdsclient.XDSClient
3938

4039
name string
41-
ldsWatchCh *testutils.Channel
42-
rdsWatchCh *testutils.Channel
43-
cdsWatchCh *testutils.Channel
44-
edsWatchCh *testutils.Channel
45-
ldsCancelCh *testutils.Channel
46-
rdsCancelCh *testutils.Channel
47-
cdsCancelCh *testutils.Channel
48-
edsCancelCh *testutils.Channel
4940
loadReportCh *testutils.Channel
5041
lrsCancelCh *testutils.Channel
5142
loadStore *load.Store
5243
bootstrapCfg *bootstrap.Config
53-
54-
ldsCb func(xdsresource.ListenerUpdate, error)
55-
rdsCbs map[string]func(xdsresource.RouteConfigUpdate, error)
56-
cdsCbs map[string]func(xdsresource.ClusterUpdate, error)
57-
edsCbs map[string]func(xdsresource.EndpointsUpdate, error)
58-
}
59-
60-
// WatchListener registers a LDS watch.
61-
func (xdsC *Client) WatchListener(serviceName string, callback func(xdsresource.ListenerUpdate, error)) func() {
62-
xdsC.ldsCb = callback
63-
xdsC.ldsWatchCh.Send(serviceName)
64-
return func() {
65-
xdsC.ldsCancelCh.Send(nil)
66-
}
67-
}
68-
69-
// WaitForWatchListener waits for WatchCluster to be invoked on this client and
70-
// returns the serviceName being watched.
71-
func (xdsC *Client) WaitForWatchListener(ctx context.Context) (string, error) {
72-
val, err := xdsC.ldsWatchCh.Receive(ctx)
73-
if err != nil {
74-
return "", err
75-
}
76-
return val.(string), err
77-
}
78-
79-
// InvokeWatchListenerCallback invokes the registered ldsWatch callback.
80-
//
81-
// Not thread safe with WatchListener. Only call this after
82-
// WaitForWatchListener.
83-
func (xdsC *Client) InvokeWatchListenerCallback(update xdsresource.ListenerUpdate, err error) {
84-
xdsC.ldsCb(update, err)
85-
}
86-
87-
// WaitForCancelListenerWatch waits for a LDS watch to be cancelled and returns
88-
// context.DeadlineExceeded otherwise.
89-
func (xdsC *Client) WaitForCancelListenerWatch(ctx context.Context) error {
90-
_, err := xdsC.ldsCancelCh.Receive(ctx)
91-
return err
92-
}
93-
94-
// WatchRouteConfig registers a RDS watch.
95-
func (xdsC *Client) WatchRouteConfig(routeName string, callback func(xdsresource.RouteConfigUpdate, error)) func() {
96-
xdsC.rdsCbs[routeName] = callback
97-
xdsC.rdsWatchCh.Send(routeName)
98-
return func() {
99-
xdsC.rdsCancelCh.Send(routeName)
100-
}
101-
}
102-
103-
// WaitForWatchRouteConfig waits for WatchCluster to be invoked on this client and
104-
// returns the routeName being watched.
105-
func (xdsC *Client) WaitForWatchRouteConfig(ctx context.Context) (string, error) {
106-
val, err := xdsC.rdsWatchCh.Receive(ctx)
107-
if err != nil {
108-
return "", err
109-
}
110-
return val.(string), err
111-
}
112-
113-
// InvokeWatchRouteConfigCallback invokes the registered rdsWatch callback.
114-
//
115-
// Not thread safe with WatchRouteConfig. Only call this after
116-
// WaitForWatchRouteConfig.
117-
func (xdsC *Client) InvokeWatchRouteConfigCallback(name string, update xdsresource.RouteConfigUpdate, err error) {
118-
if len(xdsC.rdsCbs) != 1 {
119-
xdsC.rdsCbs[name](update, err)
120-
return
121-
}
122-
// Keeps functionality with previous usage of this on client side, if single
123-
// callback call that callback.
124-
var routeName string
125-
for route := range xdsC.rdsCbs {
126-
routeName = route
127-
}
128-
xdsC.rdsCbs[routeName](update, err)
129-
}
130-
131-
// WaitForCancelRouteConfigWatch waits for a RDS watch to be cancelled and returns
132-
// context.DeadlineExceeded otherwise.
133-
func (xdsC *Client) WaitForCancelRouteConfigWatch(ctx context.Context) (string, error) {
134-
val, err := xdsC.rdsCancelCh.Receive(ctx)
135-
if err != nil {
136-
return "", err
137-
}
138-
return val.(string), err
139-
}
140-
141-
// WatchEndpoints registers an EDS watch for provided clusterName.
142-
func (xdsC *Client) WatchEndpoints(clusterName string, callback func(xdsresource.EndpointsUpdate, error)) (cancel func()) {
143-
xdsC.edsCbs[clusterName] = callback
144-
xdsC.edsWatchCh.Send(clusterName)
145-
return func() {
146-
xdsC.edsCancelCh.Send(clusterName)
147-
}
148-
}
149-
150-
// WaitForWatchEDS waits for WatchEndpoints to be invoked on this client and
151-
// returns the clusterName being watched.
152-
func (xdsC *Client) WaitForWatchEDS(ctx context.Context) (string, error) {
153-
val, err := xdsC.edsWatchCh.Receive(ctx)
154-
if err != nil {
155-
return "", err
156-
}
157-
return val.(string), err
158-
}
159-
160-
// InvokeWatchEDSCallback invokes the registered edsWatch callback.
161-
//
162-
// Not thread safe with WatchEndpoints. Only call this after
163-
// WaitForWatchEDS.
164-
func (xdsC *Client) InvokeWatchEDSCallback(name string, update xdsresource.EndpointsUpdate, err error) {
165-
if len(xdsC.edsCbs) != 1 {
166-
// This may panic if name isn't found. But it's fine for tests.
167-
xdsC.edsCbs[name](update, err)
168-
return
169-
}
170-
// Keeps functionality with previous usage of this, if single callback call
171-
// that callback.
172-
for n := range xdsC.edsCbs {
173-
name = n
174-
}
175-
xdsC.edsCbs[name](update, err)
176-
}
177-
178-
// WaitForCancelEDSWatch waits for a EDS watch to be cancelled and returns
179-
// context.DeadlineExceeded otherwise.
180-
func (xdsC *Client) WaitForCancelEDSWatch(ctx context.Context) (string, error) {
181-
edsNameReceived, err := xdsC.edsCancelCh.Receive(ctx)
182-
if err != nil {
183-
return "", err
184-
}
185-
return edsNameReceived.(string), err
18644
}
18745

18846
// ReportLoadArgs wraps the arguments passed to ReportLoad.
@@ -247,20 +105,9 @@ func NewClient() *Client {
247105
func NewClientWithName(name string) *Client {
248106
return &Client{
249107
name: name,
250-
ldsWatchCh: testutils.NewChannelWithSize(10),
251-
rdsWatchCh: testutils.NewChannelWithSize(10),
252-
cdsWatchCh: testutils.NewChannelWithSize(10),
253-
edsWatchCh: testutils.NewChannelWithSize(10),
254-
ldsCancelCh: testutils.NewChannelWithSize(10),
255-
rdsCancelCh: testutils.NewChannelWithSize(10),
256-
cdsCancelCh: testutils.NewChannelWithSize(10),
257-
edsCancelCh: testutils.NewChannelWithSize(10),
258108
loadReportCh: testutils.NewChannel(),
259109
lrsCancelCh: testutils.NewChannel(),
260110
loadStore: load.NewStore(),
261111
bootstrapCfg: &bootstrap.Config{ClientDefaultListenerResourceNameTemplate: "%s"},
262-
rdsCbs: make(map[string]func(xdsresource.RouteConfigUpdate, error)),
263-
cdsCbs: make(map[string]func(xdsresource.ClusterUpdate, error)),
264-
edsCbs: make(map[string]func(xdsresource.EndpointsUpdate, error)),
265112
}
266113
}

xds/internal/testutils/resource_watcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import "google.golang.org/grpc/xds/internal/xdsclient/xdsresource"
2424
// used to receive updates on watches registered with the xDS client, when using
2525
// the resource-type agnostic WatchResource API.
2626
//
27-
// Tests can the channels provided by this tyep to get access to updates and
27+
// Tests can use the channels provided by this type to get access to updates and
2828
// errors sent by the xDS client.
2929
type TestResourceWatcher struct {
3030
// UpdateCh is the channel on which xDS client updates are delivered.

xds/internal/xdsclient/client.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ import (
3030
// (collectively termed as xDS) on a remote management server, to discover
3131
// various dynamic resources.
3232
type XDSClient interface {
33-
WatchListener(string, func(xdsresource.ListenerUpdate, error)) func()
34-
WatchRouteConfig(string, func(xdsresource.RouteConfigUpdate, error)) func()
35-
3633
// WatchResource uses xDS to discover the resource associated with the
3734
// provided resource name. The resource type implementation determines how
3835
// xDS requests are sent out and how responses are deserialized and
@@ -47,9 +44,6 @@ type XDSClient interface {
4744
// During a race (e.g. an xDS response is received while the user is calling
4845
// cancel()), there's a small window where the callback can be called after
4946
// the watcher is canceled. Callers need to handle this case.
50-
//
51-
// TODO: Once this generic client API is fully implemented and integrated,
52-
// delete the resource type specific watch APIs on this interface.
5347
WatchResource(rType xdsresource.Type, resourceName string, watcher xdsresource.ResourceWatcher) (cancel func())
5448

5549
// DumpResources returns the status of the xDS resources. Returns a map of

xds/internal/xdsclient/clientimpl_watchers.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -25,62 +25,6 @@ import (
2525
"google.golang.org/grpc/xds/internal/xdsclient/xdsresource"
2626
)
2727

28-
// This is only required temporarily, while we modify the
29-
// clientImpl.WatchListener API to be implemented via the wrapper
30-
// WatchListener() API which calls the WatchResource() API.
31-
type listenerWatcher struct {
32-
resourceName string
33-
cb func(xdsresource.ListenerUpdate, error)
34-
}
35-
36-
func (l *listenerWatcher) OnUpdate(update *xdsresource.ListenerResourceData) {
37-
l.cb(update.Resource, nil)
38-
}
39-
40-
func (l *listenerWatcher) OnError(err error) {
41-
l.cb(xdsresource.ListenerUpdate{}, err)
42-
}
43-
44-
func (l *listenerWatcher) OnResourceDoesNotExist() {
45-
err := xdsresource.NewErrorf(xdsresource.ErrorTypeResourceNotFound, "resource name %q of type Listener not found in received response", l.resourceName)
46-
l.cb(xdsresource.ListenerUpdate{}, err)
47-
}
48-
49-
// WatchListener uses LDS to discover information about the Listener resource
50-
// identified by resourceName.
51-
func (c *clientImpl) WatchListener(resourceName string, cb func(xdsresource.ListenerUpdate, error)) (cancel func()) {
52-
watcher := &listenerWatcher{resourceName: resourceName, cb: cb}
53-
return xdsresource.WatchListener(c, resourceName, watcher)
54-
}
55-
56-
// This is only required temporarily, while we modify the
57-
// clientImpl.WatchRouteConfig API to be implemented via the wrapper
58-
// WatchRouteConfig() API which calls the WatchResource() API.
59-
type routeConfigWatcher struct {
60-
resourceName string
61-
cb func(xdsresource.RouteConfigUpdate, error)
62-
}
63-
64-
func (r *routeConfigWatcher) OnUpdate(update *xdsresource.RouteConfigResourceData) {
65-
r.cb(update.Resource, nil)
66-
}
67-
68-
func (r *routeConfigWatcher) OnError(err error) {
69-
r.cb(xdsresource.RouteConfigUpdate{}, err)
70-
}
71-
72-
func (r *routeConfigWatcher) OnResourceDoesNotExist() {
73-
err := xdsresource.NewErrorf(xdsresource.ErrorTypeResourceNotFound, "resource name %q of type RouteConfiguration not found in received response", r.resourceName)
74-
r.cb(xdsresource.RouteConfigUpdate{}, err)
75-
}
76-
77-
// WatchRouteConfig uses RDS to discover information about the
78-
// RouteConfiguration resource identified by resourceName.
79-
func (c *clientImpl) WatchRouteConfig(resourceName string, cb func(xdsresource.RouteConfigUpdate, error)) (cancel func()) {
80-
watcher := &routeConfigWatcher{resourceName: resourceName, cb: cb}
81-
return xdsresource.WatchRouteConfig(c, resourceName, watcher)
82-
}
83-
8428
// WatchResource uses xDS to discover the resource associated with the provided
8529
// resource name. The resource type implementation determines how xDS requests
8630
// are sent out and how responses are deserialized and validated. Upon receipt

xds/internal/xdsclient/tests/authority_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,6 @@ func setupForAuthorityTests(ctx context.Context, t *testing.T, idleTimeout time.
118118
return lisDefault, lisNonDefault, client, close
119119
}
120120

121-
type noopClusterWatcher struct{}
122-
123-
func (noopClusterWatcher) OnUpdate(update *xdsresource.ClusterResourceData) {}
124-
func (noopClusterWatcher) OnError(err error) {}
125-
func (noopClusterWatcher) OnResourceDoesNotExist() {}
126-
127121
// TestAuthorityShare tests the authority sharing logic. The test verifies the
128122
// following scenarios:
129123
// - A watch for a resource name with an authority matching an existing watch

0 commit comments

Comments
 (0)