Skip to content

Commit 77c5e76

Browse files
authored
Merge pull request #2846 from murgatroid99/grpc-js-xds_config_tears_fixes_2
grpc-js-xds: xds_cluster_manager: pass along updates to existing children
2 parents 361c42f + ec9b3cf commit 77c5e76

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

packages/grpc-js-xds/src/load-balancer-xds-cluster-manager.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,14 @@ class XdsClusterManager implements LoadBalancer {
227227
this.children.get(name)!.destroy();
228228
this.children.delete(name);
229229
}
230-
// Add new children that were not in the previous config
230+
// Update all children, and add any new ones
231231
for (const [name, childConfig] of configChildren.entries()) {
232-
if (!this.children.has(name)) {
233-
const newChild = new this.XdsClusterManagerChildImpl(this, name);
234-
newChild.updateAddressList(endpointList, childConfig, attributes);
235-
this.children.set(name, newChild);
232+
let child = this.children.get(name);
233+
if (!child) {
234+
child = new this.XdsClusterManagerChildImpl(this, name);
235+
this.children.set(name, child);
236236
}
237+
child.updateAddressList(endpointList, childConfig, attributes);
237238
}
238239
this.updatesPaused = false;
239240
this.updateState();

packages/grpc-js-xds/test/framework.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ export class FakeServerRoute {
386386
private listener: Listener;
387387
private routeConfiguration: RouteConfiguration;
388388
constructor(port: number, routeName: string, baseListener?: Listener | undefined, baseRouteConfiguration?: RouteConfiguration) {
389-
this.listener = baseListener ?? DEFAULT_BASE_SERVER_LISTENER;
389+
this.listener = baseListener ?? {...DEFAULT_BASE_SERVER_LISTENER};
390390
this.listener.name = `[::1]:${port}`;
391391
this.listener.address = {
392392
socket_address: {
@@ -414,7 +414,7 @@ export class FakeServerRoute {
414414
filterChain.filters = filterList;
415415
}
416416

417-
this.routeConfiguration = baseRouteConfiguration ?? DEFAULT_BASE_SERVER_ROUTE_CONFIG;
417+
this.routeConfiguration = baseRouteConfiguration ?? {...DEFAULT_BASE_SERVER_ROUTE_CONFIG};
418418
this.routeConfiguration.name = routeName;
419419
}
420420

packages/grpc-js-xds/test/test-core.ts

+31
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,36 @@ describe('core xDS functionality', () => {
134134
});
135135
}, reason => done(reason));
136136
}, reason => done(reason));
137+
});
138+
it('should handle cluster config changes', async () => {
139+
const [backend1, backend2] = await createBackends(2);
140+
const serverRoute1 = new FakeServerRoute(backend1.getPort(), 'serverRoute');
141+
const serverRoute2 = new FakeServerRoute(backend2.getPort(), 'serverRoute2');
142+
xdsServer.setRdsResource(serverRoute1.getRouteConfiguration());
143+
xdsServer.setLdsResource(serverRoute1.getListener());
144+
xdsServer.setRdsResource(serverRoute2.getRouteConfiguration());
145+
xdsServer.setLdsResource(serverRoute2.getListener());
146+
xdsServer.addResponseListener((typeUrl, responseState) => {
147+
if (responseState.state === 'NACKED') {
148+
client?.stopCalls();
149+
assert.fail(`Client NACKED ${typeUrl} resource with message ${responseState.errorMessage}`);
150+
}
151+
});
152+
const cluster1 = new FakeEdsCluster('cluster1', 'endpoint1', [{backends: [backend1], locality:{region: 'region1'}}]);
153+
const routeGroup1 = new FakeRouteGroup('listener1', 'route1', [{cluster: cluster1}]);
154+
await routeGroup1.startAllBackends(xdsServer);
155+
xdsServer.setEdsResource(cluster1.getEndpointConfig());
156+
xdsServer.setCdsResource(cluster1.getClusterConfig());
157+
xdsServer.setRdsResource(routeGroup1.getRouteConfiguration());
158+
xdsServer.setLdsResource(routeGroup1.getListener());
159+
client = XdsTestClient.createFromServer('listener1', xdsServer);
160+
client.startCalls(100);
161+
await cluster1.waitForAllBackendsToReceiveTraffic();
162+
const cluster2 = new FakeEdsCluster('cluster1', 'endpoint1', [{backends: [backend2], locality:{region: 'region2'}}]);
163+
await cluster2.startAllBackends(xdsServer);
164+
xdsServer.setEdsResource(cluster2.getEndpointConfig());
165+
await cluster2.waitForAllBackendsToReceiveTraffic();
166+
client.stopCalls();
167+
137168
})
138169
});

0 commit comments

Comments
 (0)