Merge pull request #1568 from murgatroid99/grpc-js_xds_credentials_bootstrap_change

grpc-js: xDS: handle insecure and google_default bootstrap creds
This commit is contained in:
Michael Lumish 2020-09-28 14:08:46 -07:00 committed by GitHub
commit a5cc154c8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 3 deletions

View File

@ -19,7 +19,7 @@ import * as protoLoader from '@grpc/proto-loader';
import { loadPackageDefinition } from './make-client'; import { loadPackageDefinition } from './make-client';
import * as adsTypes from './generated/ads'; import * as adsTypes from './generated/ads';
import * as lrsTypes from './generated/lrs'; import * as lrsTypes from './generated/lrs';
import { createGoogleDefaultCredentials } from './channel-credentials'; import { createGoogleDefaultCredentials, ChannelCredentials } from './channel-credentials';
import { loadBootstrapInfo } from './xds-bootstrap'; import { loadBootstrapInfo } from './xds-bootstrap';
import { ClientDuplexStream, ServiceError } from './call'; import { ClientDuplexStream, ServiceError } from './call';
import { StatusObject } from './call-stream'; import { StatusObject } from './call-stream';
@ -805,17 +805,38 @@ export class XdsClient {
...node, ...node,
client_features: ['envoy.lrs.supports_send_all_clusters'], client_features: ['envoy.lrs.supports_send_all_clusters'],
}; };
const credentialsConfigs = bootstrapInfo.xdsServers[0].channelCreds;
let channelCreds: ChannelCredentials | null = null;
for (const config of credentialsConfigs) {
if (config.type === 'google_default') {
channelCreds = createGoogleDefaultCredentials();
break;
} else if (config.type === 'insecure') {
channelCreds = ChannelCredentials.createInsecure();
break;
}
}
if (channelCreds === null) {
trace('Failed to initialize xDS Client. No valid credentials types found.');
// Bubble this error up to any listeners
this.reportStreamError({
code: Status.INTERNAL,
details: 'Failed to initialize xDS Client. No valid credentials types found.',
metadata: new Metadata(),
});
return;
}
trace('Starting xDS client connected to server URI ' + bootstrapInfo.xdsServers[0].serverUri); trace('Starting xDS client connected to server URI ' + bootstrapInfo.xdsServers[0].serverUri);
this.adsClient = new protoDefinitions.envoy.service.discovery.v2.AggregatedDiscoveryService( this.adsClient = new protoDefinitions.envoy.service.discovery.v2.AggregatedDiscoveryService(
bootstrapInfo.xdsServers[0].serverUri, bootstrapInfo.xdsServers[0].serverUri,
createGoogleDefaultCredentials(), channelCreds,
channelArgs channelArgs
); );
this.maybeStartAdsStream(); this.maybeStartAdsStream();
this.lrsClient = new protoDefinitions.envoy.service.load_stats.v2.LoadReportingService( this.lrsClient = new protoDefinitions.envoy.service.load_stats.v2.LoadReportingService(
bootstrapInfo.xdsServers[0].serverUri, bootstrapInfo.xdsServers[0].serverUri,
createGoogleDefaultCredentials(), channelCreds,
{channelOverride: this.adsClient.getChannel()} {channelOverride: this.adsClient.getChannel()}
); );
this.maybeStartLrsStream(); this.maybeStartLrsStream();