Skip to content

Commit f621dc6

Browse files
authored
Merge pull request #2848 from murgatroid99/grpc-js_revert_lb_policy_creds_arg
Revert "grpc-js: Enable LB policies to override subchannel credentials"
2 parents f003315 + 7a6107f commit f621dc6

17 files changed

+60
-86
lines changed

packages/grpc-js-xds/interop/xds-interop-client.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const RPC_BEHAVIOR_CHILD_CONFIG = parseLoadBalancingConfig({round_robin: {}});
8888
class RpcBehaviorLoadBalancer implements LoadBalancer {
8989
private child: ChildLoadBalancerHandler;
9090
private latestConfig: RpcBehaviorLoadBalancingConfig | null = null;
91-
constructor(channelControlHelper: ChannelControlHelper, credentials: grpc.ChannelCredentials, options: grpc.ChannelOptions) {
91+
constructor(channelControlHelper: ChannelControlHelper, options: grpc.ChannelOptions) {
9292
const childChannelControlHelper = createChildChannelControlHelper(channelControlHelper, {
9393
updateState: (connectivityState, picker) => {
9494
if (connectivityState === grpc.connectivityState.READY && this.latestConfig) {
@@ -97,7 +97,7 @@ class RpcBehaviorLoadBalancer implements LoadBalancer {
9797
channelControlHelper.updateState(connectivityState, picker);
9898
}
9999
});
100-
this.child = new ChildLoadBalancerHandler(childChannelControlHelper, credentials, options);
100+
this.child = new ChildLoadBalancerHandler(childChannelControlHelper, options);
101101
}
102102
updateAddressList(endpointList: Endpoint[], lbConfig: TypedLoadBalancingConfig, attributes: { [key: string]: unknown; }): void {
103103
if (!(lbConfig instanceof RpcBehaviorLoadBalancingConfig)) {

packages/grpc-js-xds/src/load-balancer-cds.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
*
1616
*/
1717

18-
import { connectivityState, status, Metadata, logVerbosity, experimental, LoadBalancingConfig, ChannelOptions, ChannelCredentials } from '@grpc/grpc-js';
18+
import { connectivityState, status, Metadata, logVerbosity, experimental, LoadBalancingConfig, ChannelOptions } from '@grpc/grpc-js';
19+
import { getSingletonXdsClient, Watcher, XdsClient } from './xds-client';
20+
import { Cluster__Output } from './generated/envoy/config/cluster/v3/Cluster';
1921
import Endpoint = experimental.Endpoint;
2022
import UnavailablePicker = experimental.UnavailablePicker;
2123
import ChildLoadBalancerHandler = experimental.ChildLoadBalancerHandler;
@@ -97,8 +99,8 @@ export class CdsLoadBalancer implements LoadBalancer {
9799
private priorityNames: string[] = [];
98100
private nextPriorityChildNumber = 0;
99101

100-
constructor(private readonly channelControlHelper: ChannelControlHelper, credentials: ChannelCredentials, options: ChannelOptions) {
101-
this.childBalancer = new ChildLoadBalancerHandler(channelControlHelper, credentials, options);
102+
constructor(private readonly channelControlHelper: ChannelControlHelper, options: ChannelOptions) {
103+
this.childBalancer = new ChildLoadBalancerHandler(channelControlHelper, options);
102104
}
103105

104106
private getNextPriorityName(cluster: string) {

packages/grpc-js-xds/src/load-balancer-priority.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717

18-
import { connectivityState as ConnectivityState, status as Status, Metadata, logVerbosity as LogVerbosity, experimental, LoadBalancingConfig, ChannelOptions, ChannelCredentials } from '@grpc/grpc-js';
18+
import { connectivityState as ConnectivityState, status as Status, Metadata, logVerbosity as LogVerbosity, experimental, LoadBalancingConfig, ChannelOptions } from '@grpc/grpc-js';
1919
import LoadBalancer = experimental.LoadBalancer;
2020
import ChannelControlHelper = experimental.ChannelControlHelper;
2121
import registerLoadBalancerType = experimental.registerLoadBalancerType;
@@ -197,7 +197,7 @@ export class PriorityLoadBalancer implements LoadBalancer {
197197
this.parent.channelControlHelper.requestReresolution();
198198
}
199199
}
200-
}), parent.credentials, parent.options);
200+
}), parent.options);
201201
this.picker = new QueuePicker(this.childBalancer);
202202
this.startFailoverTimer();
203203
}
@@ -323,7 +323,7 @@ export class PriorityLoadBalancer implements LoadBalancer {
323323

324324
private updatesPaused = false;
325325

326-
constructor(private channelControlHelper: ChannelControlHelper, private credentials: ChannelCredentials, private options: ChannelOptions) {}
326+
constructor(private channelControlHelper: ChannelControlHelper, private options: ChannelOptions) {}
327327

328328
private updateState(state: ConnectivityState, picker: Picker) {
329329
trace(

packages/grpc-js-xds/src/load-balancer-ring-hash.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717

18-
import { experimental, logVerbosity, connectivityState, status, Metadata, ChannelOptions, LoadBalancingConfig, ChannelCredentials } from '@grpc/grpc-js';
18+
import { experimental, logVerbosity, connectivityState, status, Metadata, ChannelOptions, LoadBalancingConfig } from '@grpc/grpc-js';
1919
import { isLocalityEndpoint } from './load-balancer-priority';
2020
import TypedLoadBalancingConfig = experimental.TypedLoadBalancingConfig;
2121
import LeafLoadBalancer = experimental.LeafLoadBalancer;
@@ -226,7 +226,7 @@ class RingHashLoadBalancer implements LoadBalancer {
226226
private currentState: connectivityState = connectivityState.IDLE;
227227
private ring: RingEntry[] = [];
228228
private ringHashSizeCap = DEFAULT_RING_SIZE_CAP;
229-
constructor(private channelControlHelper: ChannelControlHelper, private credentials: ChannelCredentials, private options: ChannelOptions) {
229+
constructor(private channelControlHelper: ChannelControlHelper, private options: ChannelOptions) {
230230
this.childChannelControlHelper = createChildChannelControlHelper(
231231
channelControlHelper,
232232
{
@@ -407,7 +407,7 @@ class RingHashLoadBalancer implements LoadBalancer {
407407
} else {
408408
this.leafMap.set(
409409
endpoint,
410-
new LeafLoadBalancer(endpoint, this.childChannelControlHelper, this.credentials, this.options)
410+
new LeafLoadBalancer(endpoint, this.childChannelControlHelper, this.options)
411411
);
412412
}
413413
const weight = this.leafWeightMap.get(endpoint);

packages/grpc-js-xds/src/load-balancer-weighted-target.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717

18-
import { connectivityState as ConnectivityState, status as Status, Metadata, logVerbosity, experimental, LoadBalancingConfig, ChannelOptions, ChannelCredentials } from "@grpc/grpc-js";
18+
import { connectivityState as ConnectivityState, status as Status, Metadata, logVerbosity, experimental, LoadBalancingConfig, ChannelOptions } from "@grpc/grpc-js";
1919
import { isLocalityEndpoint, LocalityEndpoint } from "./load-balancer-priority";
2020
import TypedLoadBalancingConfig = experimental.TypedLoadBalancingConfig;
2121
import LoadBalancer = experimental.LoadBalancer;
@@ -178,7 +178,7 @@ export class WeightedTargetLoadBalancer implements LoadBalancer {
178178
updateState: (connectivityState: ConnectivityState, picker: Picker) => {
179179
this.updateState(connectivityState, picker);
180180
},
181-
}), parent.credentials, parent.options);
181+
}), parent.options);
182182

183183
this.picker = new QueuePicker(this.childBalancer);
184184
}
@@ -243,7 +243,7 @@ export class WeightedTargetLoadBalancer implements LoadBalancer {
243243
private targetList: string[] = [];
244244
private updatesPaused = false;
245245

246-
constructor(private channelControlHelper: ChannelControlHelper, private credentials: ChannelCredentials, private options: ChannelOptions) {}
246+
constructor(private channelControlHelper: ChannelControlHelper, private options: ChannelOptions) {}
247247

248248
private maybeUpdateState() {
249249
if (!this.updatesPaused) {

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717

18-
import { experimental, logVerbosity, status as Status, Metadata, connectivityState, ChannelOptions, ChannelCredentials } from "@grpc/grpc-js";
18+
import { experimental, logVerbosity, status as Status, Metadata, connectivityState, ChannelOptions } from "@grpc/grpc-js";
1919
import { validateXdsServerConfig, XdsServerConfig } from "./xds-bootstrap";
2020
import { getSingletonXdsClient, XdsClient, XdsClusterDropStats, XdsClusterLocalityStats } from "./xds-client";
2121
import { LocalityEndpoint } from "./load-balancer-priority";
@@ -211,13 +211,13 @@ class XdsClusterImplBalancer implements LoadBalancer {
211211
private xdsClient: XdsClient | null = null;
212212
private latestClusterConfig: ClusterConfig | null = null;
213213

214-
constructor(private readonly channelControlHelper: ChannelControlHelper, credentials: ChannelCredentials, options: ChannelOptions) {
214+
constructor(private readonly channelControlHelper: ChannelControlHelper, options: ChannelOptions) {
215215
this.childBalancer = new ChildLoadBalancerHandler(createChildChannelControlHelper(channelControlHelper, {
216-
createSubchannel: (subchannelAddress, subchannelArgs, credentialsOverride) => {
216+
createSubchannel: (subchannelAddress, subchannelArgs) => {
217217
if (!this.xdsClient || !this.latestConfig || !this.lastestEndpointList || !this.latestClusterConfig) {
218218
throw new Error('xds_cluster_impl: invalid state: createSubchannel called with xdsClient or latestConfig not populated');
219219
}
220-
const wrapperChild = channelControlHelper.createSubchannel(subchannelAddress, subchannelArgs, credentialsOverride);
220+
const wrapperChild = channelControlHelper.createSubchannel(subchannelAddress, subchannelArgs);
221221
let locality: Locality__Output | null = null;
222222
for (const endpoint of this.lastestEndpointList) {
223223
if (endpointHasAddress(endpoint, subchannelAddress)) {
@@ -248,7 +248,7 @@ class XdsClusterImplBalancer implements LoadBalancer {
248248
channelControlHelper.updateState(connectivityState, picker);
249249
}
250250
}
251-
}), credentials, options);
251+
}), options);
252252
}
253253
updateAddressList(endpointList: Endpoint[], lbConfig: TypedLoadBalancingConfig, attributes: { [key: string]: unknown; }): void {
254254
if (!(lbConfig instanceof XdsClusterImplLoadBalancingConfig)) {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717

18-
import { connectivityState as ConnectivityState, status as Status, experimental, logVerbosity, Metadata, status, ChannelOptions, ChannelCredentials } from "@grpc/grpc-js/";
18+
import { connectivityState as ConnectivityState, status as Status, experimental, logVerbosity, Metadata, status, ChannelOptions } from "@grpc/grpc-js/";
1919

2020
import TypedLoadBalancingConfig = experimental.TypedLoadBalancingConfig;
2121
import LoadBalancer = experimental.LoadBalancer;
@@ -131,7 +131,7 @@ class XdsClusterManager implements LoadBalancer {
131131
updateState: (connectivityState: ConnectivityState, picker: Picker) => {
132132
this.updateState(connectivityState, picker);
133133
},
134-
}), parent.credentials, parent.options);
134+
}), parent.options);
135135

136136
this.picker = new QueuePicker(this.childBalancer);
137137
}
@@ -167,7 +167,7 @@ class XdsClusterManager implements LoadBalancer {
167167
// Shutdown is a placeholder value that will never appear in normal operation.
168168
private currentState: ConnectivityState = ConnectivityState.SHUTDOWN;
169169
private updatesPaused = false;
170-
constructor(private channelControlHelper: ChannelControlHelper, private credentials: ChannelCredentials, private options: ChannelOptions) {}
170+
constructor(private channelControlHelper: ChannelControlHelper, private options: ChannelOptions) {}
171171

172172
private maybeUpdateState() {
173173
if (!this.updatesPaused) {

packages/grpc-js-xds/src/load-balancer-xds-wrr-locality.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
// https://github.com/grpc/proposal/blob/master/A52-xds-custom-lb-policies.md
1919

20-
import { ChannelCredentials, ChannelOptions, LoadBalancingConfig, experimental, logVerbosity } from "@grpc/grpc-js";
20+
import { ChannelOptions, LoadBalancingConfig, experimental, logVerbosity } from "@grpc/grpc-js";
2121
import { loadProtosWithOptionsSync } from "@grpc/proto-loader/build/src/util";
2222
import { WeightedTargetRaw } from "./load-balancer-weighted-target";
2323
import { isLocalityEndpoint } from "./load-balancer-priority";
@@ -73,8 +73,8 @@ class XdsWrrLocalityLoadBalancingConfig implements TypedLoadBalancingConfig {
7373

7474
class XdsWrrLocalityLoadBalancer implements LoadBalancer {
7575
private childBalancer: ChildLoadBalancerHandler;
76-
constructor(private readonly channelControlHelper: ChannelControlHelper, credentials: ChannelCredentials, options: ChannelOptions) {
77-
this.childBalancer = new ChildLoadBalancerHandler(channelControlHelper, credentials, options);
76+
constructor(private readonly channelControlHelper: ChannelControlHelper, options: ChannelOptions) {
77+
this.childBalancer = new ChildLoadBalancerHandler(channelControlHelper, options);
7878
}
7979
updateAddressList(endpointList: Endpoint[], lbConfig: TypedLoadBalancingConfig, attributes: { [key: string]: unknown; }): void {
8080
if (!(lbConfig instanceof XdsWrrLocalityLoadBalancingConfig)) {

packages/grpc-js-xds/test/test-custom-lb-policies.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { ControlPlaneServer } from "./xds-server";
2424
import * as assert from 'assert';
2525
import { WrrLocality } from "../src/generated/envoy/extensions/load_balancing_policies/wrr_locality/v3/WrrLocality";
2626
import { TypedStruct } from "../src/generated/xds/type/v3/TypedStruct";
27-
import { ChannelCredentials, ChannelOptions, connectivityState, experimental, logVerbosity } from "@grpc/grpc-js";
27+
import { ChannelOptions, connectivityState, experimental, logVerbosity } from "@grpc/grpc-js";
2828

2929
import TypedLoadBalancingConfig = experimental.TypedLoadBalancingConfig;
3030
import LoadBalancer = experimental.LoadBalancer;
@@ -84,7 +84,7 @@ const RPC_BEHAVIOR_CHILD_CONFIG = parseLoadBalancingConfig({round_robin: {}});
8484
class RpcBehaviorLoadBalancer implements LoadBalancer {
8585
private child: ChildLoadBalancerHandler;
8686
private latestConfig: RpcBehaviorLoadBalancingConfig | null = null;
87-
constructor(channelControlHelper: ChannelControlHelper, credentials: ChannelCredentials, options: ChannelOptions) {
87+
constructor(channelControlHelper: ChannelControlHelper, options: ChannelOptions) {
8888
const childChannelControlHelper = createChildChannelControlHelper(channelControlHelper, {
8989
updateState: (state, picker) => {
9090
if (state === connectivityState.READY && this.latestConfig) {
@@ -93,7 +93,7 @@ class RpcBehaviorLoadBalancer implements LoadBalancer {
9393
channelControlHelper.updateState(state, picker);
9494
}
9595
});
96-
this.child = new ChildLoadBalancerHandler(childChannelControlHelper, credentials, options);
96+
this.child = new ChildLoadBalancerHandler(childChannelControlHelper, options);
9797
}
9898
updateAddressList(endpointList: Endpoint[], lbConfig: TypedLoadBalancingConfig, attributes: { [key: string]: unknown; }): void {
9999
if (!(lbConfig instanceof RpcBehaviorLoadBalancingConfig)) {

packages/grpc-js/src/internal-channel.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,13 @@ export class InternalChannel {
294294
const channelControlHelper: ChannelControlHelper = {
295295
createSubchannel: (
296296
subchannelAddress: SubchannelAddress,
297-
subchannelArgs: ChannelOptions,
298-
credentialsOverride: ChannelCredentials | null
297+
subchannelArgs: ChannelOptions
299298
) => {
300299
const subchannel = this.subchannelPool.getOrCreateSubchannel(
301300
this.target,
302301
subchannelAddress,
303302
Object.assign({}, this.options, subchannelArgs),
304-
credentialsOverride ?? this.credentials
303+
this.credentials
305304
);
306305
subchannel.throttleKeepalive(this.keepaliveTime);
307306
if (this.channelzEnabled) {
@@ -350,7 +349,6 @@ export class InternalChannel {
350349
this.resolvingLoadBalancer = new ResolvingLoadBalancer(
351350
this.target,
352351
channelControlHelper,
353-
credentials,
354352
options,
355353
(serviceConfig, configSelector) => {
356354
if (serviceConfig.retryThrottling) {

packages/grpc-js/src/load-balancer-child-handler.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { ConnectivityState } from './connectivity-state';
2727
import { Picker } from './picker';
2828
import type { ChannelRef, SubchannelRef } from './channelz';
2929
import { SubchannelInterface } from './subchannel-interface';
30-
import { ChannelCredentials } from './channel-credentials';
3130

3231
const TYPE_NAME = 'child_load_balancer_helper';
3332

@@ -41,13 +40,11 @@ export class ChildLoadBalancerHandler implements LoadBalancer {
4140
constructor(private parent: ChildLoadBalancerHandler) {}
4241
createSubchannel(
4342
subchannelAddress: SubchannelAddress,
44-
subchannelArgs: ChannelOptions,
45-
credentialsOverride: ChannelCredentials | null
43+
subchannelArgs: ChannelOptions
4644
): SubchannelInterface {
4745
return this.parent.channelControlHelper.createSubchannel(
4846
subchannelAddress,
49-
subchannelArgs,
50-
credentialsOverride
47+
subchannelArgs
5148
);
5249
}
5350
updateState(connectivityState: ConnectivityState, picker: Picker): void {
@@ -89,7 +86,6 @@ export class ChildLoadBalancerHandler implements LoadBalancer {
8986

9087
constructor(
9188
private readonly channelControlHelper: ChannelControlHelper,
92-
private readonly credentials: ChannelCredentials,
9389
private readonly options: ChannelOptions
9490
) {}
9591

@@ -118,7 +114,7 @@ export class ChildLoadBalancerHandler implements LoadBalancer {
118114
this.configUpdateRequiresNewPolicyInstance(this.latestConfig, lbConfig)
119115
) {
120116
const newHelper = new this.ChildPolicyHelper(this);
121-
const newChild = createLoadBalancer(lbConfig, newHelper, this.credentials, this.options)!;
117+
const newChild = createLoadBalancer(lbConfig, newHelper, this.options)!;
122118
newHelper.setChild(newChild);
123119
if (this.currentChild === null) {
124120
this.currentChild = newChild;

packages/grpc-js/src/load-balancer-outlier-detection.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import {
4343
} from './subchannel-interface';
4444
import * as logging from './logging';
4545
import { LoadBalancingConfig } from './service-config';
46-
import { ChannelCredentials } from './channel-credentials';
4746

4847
const TRACER_NAME = 'outlier_detection';
4948

@@ -470,20 +469,17 @@ export class OutlierDetectionLoadBalancer implements LoadBalancer {
470469

471470
constructor(
472471
channelControlHelper: ChannelControlHelper,
473-
credentials: ChannelCredentials,
474472
options: ChannelOptions
475473
) {
476474
this.childBalancer = new ChildLoadBalancerHandler(
477475
createChildChannelControlHelper(channelControlHelper, {
478476
createSubchannel: (
479477
subchannelAddress: SubchannelAddress,
480-
subchannelArgs: ChannelOptions,
481-
credentialsOverride: ChannelCredentials | null
478+
subchannelArgs: ChannelOptions
482479
) => {
483480
const originalSubchannel = channelControlHelper.createSubchannel(
484481
subchannelAddress,
485-
subchannelArgs,
486-
credentialsOverride
482+
subchannelArgs
487483
);
488484
const mapEntry =
489485
this.entryMap.getForSubchannelAddress(subchannelAddress);
@@ -509,7 +505,6 @@ export class OutlierDetectionLoadBalancer implements LoadBalancer {
509505
}
510506
},
511507
}),
512-
credentials,
513508
options
514509
);
515510
this.ejectionTimer = setInterval(() => {}, 0);

packages/grpc-js/src/load-balancer-pick-first.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import {
4343
import { isTcpSubchannelAddress } from './subchannel-address';
4444
import { isIPv6 } from 'net';
4545
import { ChannelOptions } from './channel-options';
46-
import { ChannelCredentials } from './channel-credentials';
4746

4847
const TRACER_NAME = 'pick_first';
4948

@@ -244,7 +243,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
244243
*/
245244
constructor(
246245
private readonly channelControlHelper: ChannelControlHelper,
247-
credentials: ChannelCredentials,
248246
options: ChannelOptions
249247
) {
250248
this.connectionDelayTimeout = setTimeout(() => {}, 0);
@@ -466,7 +464,7 @@ export class PickFirstLoadBalancer implements LoadBalancer {
466464
private connectToAddressList(addressList: SubchannelAddress[]) {
467465
trace('connectToAddressList([' + addressList.map(address => subchannelAddressToString(address)) + '])');
468466
const newChildrenList = addressList.map(address => ({
469-
subchannel: this.channelControlHelper.createSubchannel(address, {}, null),
467+
subchannel: this.channelControlHelper.createSubchannel(address, {}),
470468
hasReportedTransientFailure: false,
471469
}));
472470
for (const { subchannel } of newChildrenList) {
@@ -562,7 +560,6 @@ export class LeafLoadBalancer {
562560
constructor(
563561
private endpoint: Endpoint,
564562
channelControlHelper: ChannelControlHelper,
565-
credentials: ChannelCredentials,
566563
options: ChannelOptions
567564
) {
568565
const childChannelControlHelper = createChildChannelControlHelper(
@@ -577,7 +574,6 @@ export class LeafLoadBalancer {
577574
);
578575
this.pickFirstBalancer = new PickFirstLoadBalancer(
579576
childChannelControlHelper,
580-
credentials,
581577
{ ...options, [REPORT_HEALTH_STATUS_OPTION_NAME]: true }
582578
);
583579
this.latestPicker = new QueuePicker(this.pickFirstBalancer);

0 commit comments

Comments
 (0)