@@ -48,6 +48,7 @@ import { EXPERIMENTAL_FAULT_INJECTION, EXPERIMENTAL_RETRY } from './environment'
48
48
import Filter = experimental . Filter ;
49
49
import FilterFactory = experimental . FilterFactory ;
50
50
import RetryPolicy = experimental . RetryPolicy ;
51
+ import { validateBootstrapConfig } from './xds-bootstrap' ;
51
52
52
53
const TRACER_NAME = 'xds_resolver' ;
53
54
@@ -210,6 +211,8 @@ function getDefaultRetryMaxInterval(baseInterval: string): string {
210
211
return `${ Number . parseFloat ( baseInterval . substring ( 0 , baseInterval . length - 1 ) ) * 10 } s` ;
211
212
}
212
213
214
+ const BOOTSTRAP_CONFIG_KEY = 'grpc.TEST_ONLY_DO_NOT_USE_IN_PROD.xds_bootstrap_config' ;
215
+
213
216
const RETRY_CODES : { [ key : string ] : status } = {
214
217
'cancelled' : status . CANCELLED ,
215
218
'deadline-exceeded' : status . DEADLINE_EXCEEDED ,
@@ -238,11 +241,20 @@ class XdsResolver implements Resolver {
238
241
239
242
private ldsHttpFilterConfigs : { name : string , config : HttpFilterConfig } [ ] = [ ] ;
240
243
244
+ private xdsClient : XdsClient ;
245
+
241
246
constructor (
242
247
private target : GrpcUri ,
243
248
private listener : ResolverListener ,
244
249
private channelOptions : ChannelOptions
245
250
) {
251
+ if ( channelOptions [ BOOTSTRAP_CONFIG_KEY ] ) {
252
+ const parsedConfig = JSON . parse ( channelOptions [ BOOTSTRAP_CONFIG_KEY ] ) ;
253
+ const validatedConfig = validateBootstrapConfig ( parsedConfig ) ;
254
+ this . xdsClient = new XdsClient ( validatedConfig ) ;
255
+ } else {
256
+ this . xdsClient = getSingletonXdsClient ( ) ;
257
+ }
246
258
this . ldsWatcher = {
247
259
onValidUpdate : ( update : Listener__Output ) => {
248
260
const httpConnectionManager = decodeSingleResource ( HTTP_CONNECTION_MANGER_TYPE_URL , update . api_listener ! . api_listener ! . value ) ;
@@ -267,16 +279,16 @@ class XdsResolver implements Resolver {
267
279
const routeConfigName = httpConnectionManager . rds ! . route_config_name ;
268
280
if ( this . latestRouteConfigName !== routeConfigName ) {
269
281
if ( this . latestRouteConfigName !== null ) {
270
- getSingletonXdsClient ( ) . removeRouteWatcher ( this . latestRouteConfigName , this . rdsWatcher ) ;
282
+ this . xdsClient . removeRouteWatcher ( this . latestRouteConfigName , this . rdsWatcher ) ;
271
283
}
272
- getSingletonXdsClient ( ) . addRouteWatcher ( httpConnectionManager . rds ! . route_config_name , this . rdsWatcher ) ;
284
+ this . xdsClient . addRouteWatcher ( httpConnectionManager . rds ! . route_config_name , this . rdsWatcher ) ;
273
285
this . latestRouteConfigName = routeConfigName ;
274
286
}
275
287
break ;
276
288
}
277
289
case 'route_config' :
278
290
if ( this . latestRouteConfigName ) {
279
- getSingletonXdsClient ( ) . removeRouteWatcher ( this . latestRouteConfigName , this . rdsWatcher ) ;
291
+ this . xdsClient . removeRouteWatcher ( this . latestRouteConfigName , this . rdsWatcher ) ;
280
292
}
281
293
this . handleRouteConfig ( httpConnectionManager . route_config ! ) ;
282
294
break ;
@@ -546,7 +558,7 @@ class XdsResolver implements Resolver {
546
558
methodConfig : [ ] ,
547
559
loadBalancingConfig : [ lbPolicyConfig ]
548
560
}
549
- this . listener . onSuccessfulResolution ( [ ] , serviceConfig , null , configSelector , { } ) ;
561
+ this . listener . onSuccessfulResolution ( [ ] , serviceConfig , null , configSelector , { xdsClient : this . xdsClient } ) ;
550
562
}
551
563
552
564
private reportResolutionError ( reason : string ) {
@@ -563,15 +575,15 @@ class XdsResolver implements Resolver {
563
575
// Wait until updateResolution is called once to start the xDS requests
564
576
if ( ! this . isLdsWatcherActive ) {
565
577
trace ( 'Starting resolution for target ' + uriToString ( this . target ) ) ;
566
- getSingletonXdsClient ( ) . addListenerWatcher ( this . target . path , this . ldsWatcher ) ;
578
+ this . xdsClient . addListenerWatcher ( this . target . path , this . ldsWatcher ) ;
567
579
this . isLdsWatcherActive = true ;
568
580
}
569
581
}
570
582
571
583
destroy ( ) {
572
- getSingletonXdsClient ( ) . removeListenerWatcher ( this . target . path , this . ldsWatcher ) ;
584
+ this . xdsClient . removeListenerWatcher ( this . target . path , this . ldsWatcher ) ;
573
585
if ( this . latestRouteConfigName ) {
574
- getSingletonXdsClient ( ) . removeRouteWatcher ( this . latestRouteConfigName , this . rdsWatcher ) ;
586
+ this . xdsClient . removeRouteWatcher ( this . latestRouteConfigName , this . rdsWatcher ) ;
575
587
}
576
588
}
577
589
0 commit comments