Skip to content

Commit 92f5ba9

Browse files
authored
xdsclient: completely remove the old WatchCluster API (#6621)
1 parent 94d8074 commit 92f5ba9

File tree

9 files changed

+129
-221
lines changed

9 files changed

+129
-221
lines changed

xds/internal/testutils/fakeclient/client.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -138,57 +138,6 @@ func (xdsC *Client) WaitForCancelRouteConfigWatch(ctx context.Context) (string,
138138
return val.(string), err
139139
}
140140

141-
// WatchCluster registers a CDS watch.
142-
func (xdsC *Client) WatchCluster(clusterName string, callback func(xdsresource.ClusterUpdate, error)) func() {
143-
// Due to the tree like structure of aggregate clusters, there can be multiple callbacks persisted for each cluster
144-
// node. However, the client doesn't care about the parent child relationship between the nodes, only that it invokes
145-
// the right callback for a particular cluster.
146-
xdsC.cdsCbs[clusterName] = callback
147-
xdsC.cdsWatchCh.Send(clusterName)
148-
return func() {
149-
xdsC.cdsCancelCh.Send(clusterName)
150-
}
151-
}
152-
153-
// WaitForWatchCluster waits for WatchCluster to be invoked on this client and
154-
// returns the clusterName being watched.
155-
func (xdsC *Client) WaitForWatchCluster(ctx context.Context) (string, error) {
156-
val, err := xdsC.cdsWatchCh.Receive(ctx)
157-
if err != nil {
158-
return "", err
159-
}
160-
return val.(string), err
161-
}
162-
163-
// InvokeWatchClusterCallback invokes the registered cdsWatch callback.
164-
//
165-
// Not thread safe with WatchCluster. Only call this after
166-
// WaitForWatchCluster.
167-
func (xdsC *Client) InvokeWatchClusterCallback(update xdsresource.ClusterUpdate, err error) {
168-
// Keeps functionality with previous usage of this, if single callback call that callback.
169-
if len(xdsC.cdsCbs) == 1 {
170-
var clusterName string
171-
for cluster := range xdsC.cdsCbs {
172-
clusterName = cluster
173-
}
174-
xdsC.cdsCbs[clusterName](update, err)
175-
} else {
176-
// Have what callback you call with the update determined by the service name in the ClusterUpdate. Left up to the
177-
// caller to make sure the cluster update matches with a persisted callback.
178-
xdsC.cdsCbs[update.ClusterName](update, err)
179-
}
180-
}
181-
182-
// WaitForCancelClusterWatch waits for a CDS watch to be cancelled and returns
183-
// context.DeadlineExceeded otherwise.
184-
func (xdsC *Client) WaitForCancelClusterWatch(ctx context.Context) (string, error) {
185-
clusterNameReceived, err := xdsC.cdsCancelCh.Receive(ctx)
186-
if err != nil {
187-
return "", err
188-
}
189-
return clusterNameReceived.(string), err
190-
}
191-
192141
// WatchEndpoints registers an EDS watch for provided clusterName.
193142
func (xdsC *Client) WatchEndpoints(clusterName string, callback func(xdsresource.EndpointsUpdate, error)) (cancel func()) {
194143
xdsC.edsCbs[clusterName] = callback

xds/internal/xdsclient/client.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
type XDSClient interface {
3333
WatchListener(string, func(xdsresource.ListenerUpdate, error)) func()
3434
WatchRouteConfig(string, func(xdsresource.RouteConfigUpdate, error)) func()
35-
WatchCluster(string, func(xdsresource.ClusterUpdate, error)) func()
3635

3736
// WatchResource uses xDS to discover the resource associated with the
3837
// provided resource name. The resource type implementation determines how

xds/internal/xdsclient/clientimpl_watchers.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -81,37 +81,6 @@ func (c *clientImpl) WatchRouteConfig(resourceName string, cb func(xdsresource.R
8181
return xdsresource.WatchRouteConfig(c, resourceName, watcher)
8282
}
8383

84-
// This is only required temporarily, while we modify the
85-
// clientImpl.WatchCluster API to be implemented via the wrapper WatchCluster()
86-
// API which calls the WatchResource() API.
87-
type clusterWatcher struct {
88-
resourceName string
89-
cb func(xdsresource.ClusterUpdate, error)
90-
}
91-
92-
func (c *clusterWatcher) OnUpdate(update *xdsresource.ClusterResourceData) {
93-
c.cb(update.Resource, nil)
94-
}
95-
96-
func (c *clusterWatcher) OnError(err error) {
97-
c.cb(xdsresource.ClusterUpdate{}, err)
98-
}
99-
100-
func (c *clusterWatcher) OnResourceDoesNotExist() {
101-
err := xdsresource.NewErrorf(xdsresource.ErrorTypeResourceNotFound, "resource name %q of type Cluster not found in received response", c.resourceName)
102-
c.cb(xdsresource.ClusterUpdate{}, err)
103-
}
104-
105-
// WatchCluster uses CDS to discover information about the Cluster resource
106-
// identified by resourceName.
107-
//
108-
// WatchCluster can be called multiple times, with same or different
109-
// clusterNames. Each call will start an independent watcher for the resource.
110-
func (c *clientImpl) WatchCluster(resourceName string, cb func(xdsresource.ClusterUpdate, error)) (cancel func()) {
111-
watcher := &clusterWatcher{resourceName: resourceName, cb: cb}
112-
return xdsresource.WatchCluster(c, resourceName, watcher)
113-
}
114-
11584
// WatchResource uses xDS to discover the resource associated with the provided
11685
// resource name. The resource type implementation determines how xDS requests
11786
// are sent out and how responses are deserialized and validated. Upon receipt

xds/internal/xdsclient/tests/authority_test.go

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

123+
type noopClusterWatcher struct{}
124+
125+
func (noopClusterWatcher) OnUpdate(update *xdsresource.ClusterResourceData) {}
126+
func (noopClusterWatcher) OnError(err error) {}
127+
func (noopClusterWatcher) OnResourceDoesNotExist() {}
128+
123129
// TestAuthorityShare tests the authority sharing logic. The test verifies the
124130
// following scenarios:
125131
// - A watch for a resource name with an authority matching an existing watch
@@ -143,14 +149,15 @@ func (s) TestAuthorityShare(t *testing.T) {
143149
}
144150

145151
// Request the first resource. Verify that a new transport is created.
146-
cdsCancel1 := client.WatchCluster(authorityTestResourceName11, func(u xdsresource.ClusterUpdate, err error) {})
152+
watcher := noopClusterWatcher{}
153+
cdsCancel1 := xdsresource.WatchCluster(client, authorityTestResourceName11, watcher)
147154
defer cdsCancel1()
148155
if _, err := lis.NewConnCh.Receive(ctx); err != nil {
149156
t.Fatalf("Timed out when waiting for a new transport to be created to the management server: %v", err)
150157
}
151158

152159
// Request the second resource. Verify that no new transport is created.
153-
cdsCancel2 := client.WatchCluster(authorityTestResourceName12, func(u xdsresource.ClusterUpdate, err error) {})
160+
cdsCancel2 := xdsresource.WatchCluster(client, authorityTestResourceName12, watcher)
154161
defer cdsCancel2()
155162
sCtx, sCancel = context.WithTimeout(ctx, defaultTestShortTimeout)
156163
defer sCancel()
@@ -159,7 +166,7 @@ func (s) TestAuthorityShare(t *testing.T) {
159166
}
160167

161168
// Request the third resource. Verify that no new transport is created.
162-
cdsCancel3 := client.WatchCluster(authorityTestResourceName2, func(u xdsresource.ClusterUpdate, err error) {})
169+
cdsCancel3 := xdsresource.WatchCluster(client, authorityTestResourceName2, watcher)
163170
defer cdsCancel3()
164171
sCtx, sCancel = context.WithTimeout(ctx, defaultTestShortTimeout)
165172
defer sCancel()
@@ -179,15 +186,16 @@ func (s) TestAuthorityIdleTimeout(t *testing.T) {
179186
defer close()
180187

181188
// Request the first resource. Verify that a new transport is created.
182-
cdsCancel1 := client.WatchCluster(authorityTestResourceName11, func(u xdsresource.ClusterUpdate, err error) {})
189+
watcher := noopClusterWatcher{}
190+
cdsCancel1 := xdsresource.WatchCluster(client, authorityTestResourceName11, watcher)
183191
val, err := lis.NewConnCh.Receive(ctx)
184192
if err != nil {
185193
t.Fatalf("Timed out when waiting for a new transport to be created to the management server: %v", err)
186194
}
187195
conn := val.(*testutils.ConnWrapper)
188196

189197
// Request the second resource. Verify that no new transport is created.
190-
cdsCancel2 := client.WatchCluster(authorityTestResourceName12, func(u xdsresource.ClusterUpdate, err error) {})
198+
cdsCancel2 := xdsresource.WatchCluster(client, authorityTestResourceName12, watcher)
191199
sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout)
192200
defer sCancel()
193201
if _, err := lis.NewConnCh.Receive(sCtx); err != context.DeadlineExceeded {
@@ -225,7 +233,8 @@ func (s) TestAuthorityClientClose(t *testing.T) {
225233

226234
// Request the first resource. Verify that a new transport is created to the
227235
// default management server.
228-
cdsCancel1 := client.WatchCluster(authorityTestResourceName11, func(u xdsresource.ClusterUpdate, err error) {})
236+
watcher := noopClusterWatcher{}
237+
cdsCancel1 := xdsresource.WatchCluster(client, authorityTestResourceName11, watcher)
229238
val, err := lisDefault.NewConnCh.Receive(ctx)
230239
if err != nil {
231240
t.Fatalf("Timed out when waiting for a new transport to be created to the management server: %v", err)
@@ -235,7 +244,7 @@ func (s) TestAuthorityClientClose(t *testing.T) {
235244
// Request another resource which is served by the non-default authority.
236245
// Verify that a new transport is created to the non-default management
237246
// server.
238-
client.WatchCluster(authorityTestResourceName3, func(u xdsresource.ClusterUpdate, err error) {})
247+
xdsresource.WatchCluster(client, authorityTestResourceName3, watcher)
239248
val, err = lisNonDefault.NewConnCh.Receive(ctx)
240249
if err != nil {
241250
t.Fatalf("Timed out when waiting for a new transport to be created to the management server: %v", err)
@@ -272,7 +281,8 @@ func (s) TestAuthorityRevive(t *testing.T) {
272281
defer close()
273282

274283
// Request the first resource. Verify that a new transport is created.
275-
cdsCancel1 := client.WatchCluster(authorityTestResourceName11, func(u xdsresource.ClusterUpdate, err error) {})
284+
watcher := noopClusterWatcher{}
285+
cdsCancel1 := xdsresource.WatchCluster(client, authorityTestResourceName11, watcher)
276286
val, err := lis.NewConnCh.Receive(ctx)
277287
if err != nil {
278288
t.Fatalf("Timed out when waiting for a new transport to be created to the management server: %v", err)
@@ -284,7 +294,7 @@ func (s) TestAuthorityRevive(t *testing.T) {
284294

285295
// Request the second resource. Verify that no new transport is created.
286296
// This should move the authority out of the idle cache.
287-
cdsCancel2 := client.WatchCluster(authorityTestResourceName12, func(u xdsresource.ClusterUpdate, err error) {})
297+
cdsCancel2 := xdsresource.WatchCluster(client, authorityTestResourceName12, watcher)
288298
defer cdsCancel2()
289299
sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout)
290300
defer sCancel()

0 commit comments

Comments
 (0)