@@ -30,6 +30,7 @@ import { XdsConfig } from './xds-dependency-manager';
30
30
import { LocalityEndpoint , PriorityChildRaw } from './load-balancer-priority' ;
31
31
import { Locality__Output } from './generated/envoy/config/core/v3/Locality' ;
32
32
import { AGGREGATE_CLUSTER_BACKWARDS_COMPAT , EXPERIMENTAL_OUTLIER_DETECTION } from './environment' ;
33
+ import { XDS_CONFIG_KEY } from './resolver-xds' ;
33
34
34
35
const TRACER_NAME = 'cds_balancer' ;
35
36
@@ -91,6 +92,8 @@ export function localityToName(locality: Locality__Output) {
91
92
return `{region=${ locality . region } ,zone=${ locality . zone } ,sub_zone=${ locality . sub_zone } }` ;
92
93
}
93
94
95
+ export const ROOT_CLUSTER_KEY = 'grpc.internal.root_cluster' ;
96
+
94
97
export class CdsLoadBalancer implements LoadBalancer {
95
98
private childBalancer : ChildLoadBalancerHandler ;
96
99
@@ -99,8 +102,8 @@ export class CdsLoadBalancer implements LoadBalancer {
99
102
private priorityNames : string [ ] = [ ] ;
100
103
private nextPriorityChildNumber = 0 ;
101
104
102
- constructor ( private readonly channelControlHelper : ChannelControlHelper , options : ChannelOptions ) {
103
- this . childBalancer = new ChildLoadBalancerHandler ( channelControlHelper , options ) ;
105
+ constructor ( private readonly channelControlHelper : ChannelControlHelper ) {
106
+ this . childBalancer = new ChildLoadBalancerHandler ( channelControlHelper ) ;
104
107
}
105
108
106
109
private getNextPriorityName ( cluster : string ) {
@@ -110,14 +113,14 @@ export class CdsLoadBalancer implements LoadBalancer {
110
113
updateAddressList (
111
114
endpointList : Endpoint [ ] ,
112
115
lbConfig : TypedLoadBalancingConfig ,
113
- attributes : { [ key : string ] : unknown }
116
+ options : ChannelOptions
114
117
) : void {
115
118
if ( ! ( lbConfig instanceof CdsLoadBalancingConfig ) ) {
116
119
trace ( 'Discarding address list update with unrecognized config ' + JSON . stringify ( lbConfig , undefined , 2 ) ) ;
117
120
return ;
118
121
}
119
122
trace ( 'Received update with config ' + JSON . stringify ( lbConfig , undefined , 2 ) ) ;
120
- const xdsConfig = attributes . xdsConfig as XdsConfig ;
123
+ const xdsConfig = options [ XDS_CONFIG_KEY ] as XdsConfig ;
121
124
const clusterName = lbConfig . getCluster ( ) ;
122
125
const maybeClusterConfig = xdsConfig . clusters . get ( clusterName ) ;
123
126
if ( ! maybeClusterConfig ) {
@@ -165,7 +168,7 @@ export class CdsLoadBalancer implements LoadBalancer {
165
168
this . channelControlHelper . updateState ( connectivityState . TRANSIENT_FAILURE , new UnavailablePicker ( { code : status . UNAVAILABLE , details : `LB policy config parsing failed with error ${ ( e as Error ) . message } ` , metadata : new Metadata ( ) } ) ) ;
166
169
return ;
167
170
}
168
- this . childBalancer . updateAddressList ( endpointList , typedChildConfig , { ...attributes , rootCluster : clusterName } ) ;
171
+ this . childBalancer . updateAddressList ( endpointList , typedChildConfig , { ...options , [ ROOT_CLUSTER_KEY ] : clusterName } ) ;
169
172
} else {
170
173
if ( ! clusterConfig . children . endpoints ) {
171
174
trace ( 'Received update with no resolved endpoints for cluster ' + clusterName ) ;
@@ -180,8 +183,8 @@ export class CdsLoadBalancer implements LoadBalancer {
180
183
if ( clusterConfig . cluster . type === 'EDS' ) {
181
184
endpointPickingPolicy = clusterConfig . cluster . lbPolicyConfig ;
182
185
if ( AGGREGATE_CLUSTER_BACKWARDS_COMPAT ) {
183
- if ( typeof attributes . rootCluster === 'string' ) {
184
- const maybeRootClusterConfig = xdsConfig . clusters . get ( attributes . rootCluster ) ;
186
+ if ( typeof options [ ROOT_CLUSTER_KEY ] === 'string' ) {
187
+ const maybeRootClusterConfig = xdsConfig . clusters . get ( options [ ROOT_CLUSTER_KEY ] ) ;
185
188
if ( maybeRootClusterConfig ?. success ) {
186
189
endpointPickingPolicy = maybeRootClusterConfig . value . cluster . lbPolicyConfig ;
187
190
}
@@ -279,7 +282,7 @@ export class CdsLoadBalancer implements LoadBalancer {
279
282
return ;
280
283
}
281
284
trace ( JSON . stringify ( typedChildConfig . toJsonObject ( ) , undefined , 2 ) ) ;
282
- this . childBalancer . updateAddressList ( childEndpointList , typedChildConfig , attributes ) ;
285
+ this . childBalancer . updateAddressList ( childEndpointList , typedChildConfig , options ) ;
283
286
}
284
287
}
285
288
exitIdle ( ) : void {
0 commit comments