Skip to content

Commit

Permalink
Merge pull request #1568 from murgatroid99/grpc-js_xds_credentials_bo…
Browse files Browse the repository at this point in the history
…otstrap_change

grpc-js: xDS: handle insecure and google_default bootstrap creds
  • Loading branch information
murgatroid99 committed Sep 28, 2020
2 parents 6470e88 + b99872e commit a5cc154
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions packages/grpc-js/src/xds-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as protoLoader from '@grpc/proto-loader';
import { loadPackageDefinition } from './make-client';
import * as adsTypes from './generated/ads';
import * as lrsTypes from './generated/lrs';
import { createGoogleDefaultCredentials } from './channel-credentials';
import { createGoogleDefaultCredentials, ChannelCredentials } from './channel-credentials';
import { loadBootstrapInfo } from './xds-bootstrap';
import { ClientDuplexStream, ServiceError } from './call';
import { StatusObject } from './call-stream';
Expand Down Expand Up @@ -805,17 +805,38 @@ export class XdsClient {
...node,
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);
this.adsClient = new protoDefinitions.envoy.service.discovery.v2.AggregatedDiscoveryService(
bootstrapInfo.xdsServers[0].serverUri,
createGoogleDefaultCredentials(),
channelCreds,
channelArgs
);
this.maybeStartAdsStream();

this.lrsClient = new protoDefinitions.envoy.service.load_stats.v2.LoadReportingService(
bootstrapInfo.xdsServers[0].serverUri,
createGoogleDefaultCredentials(),
channelCreds,
{channelOverride: this.adsClient.getChannel()}
);
this.maybeStartLrsStream();
Expand Down

0 comments on commit a5cc154

Please sign in to comment.