Skip to content

Commit b0635fa

Browse files
authored
googleapis: Allow user set c2p bootstrap config (#9856)
Instead of always overriding the bootstrap with a custom c2p config, now we allow user defined ones to also be used. This only applies when running in GCP with federation.
1 parent b289519 commit b0635fa

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

googleapis/src/main/java/io/grpc/googleapis/GoogleCloudToProdNameResolver.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,28 @@ private void resolve() {
156156
class Resolve implements Runnable {
157157
@Override
158158
public void run() {
159-
String zone;
160-
boolean supportIpv6;
161159
ImmutableMap<String, ?> rawBootstrap = null;
162160
try {
163-
zone = queryZoneMetadata(METADATA_URL_ZONE);
164-
supportIpv6 = queryIpv6SupportMetadata(METADATA_URL_SUPPORT_IPV6);
165-
rawBootstrap = generateBootstrap(zone, supportIpv6);
161+
// User provided bootstrap configs are only supported with federation. If federation is
162+
// not enabled or there is no user provided config, we set a custom bootstrap override.
163+
// Otherwise, we don't set the override, which will allow a user provided bootstrap config
164+
// to take effect.
165+
if (!enableFederation || !xdsBootstrapProvided) {
166+
rawBootstrap = generateBootstrap(queryZoneMetadata(METADATA_URL_ZONE),
167+
queryIpv6SupportMetadata(METADATA_URL_SUPPORT_IPV6));
168+
}
166169
} catch (IOException e) {
167-
listener.onError(Status.INTERNAL.withDescription("Unable to get metadata").withCause(e));
170+
listener.onError(
171+
Status.INTERNAL.withDescription("Unable to get metadata").withCause(e));
168172
} finally {
169173
final ImmutableMap<String, ?> finalRawBootstrap = rawBootstrap;
170174
syncContext.execute(new Runnable() {
171175
@Override
172176
public void run() {
173-
if (!shutdown && finalRawBootstrap != null) {
174-
bootstrapSetter.setBootstrap(finalRawBootstrap);
177+
if (!shutdown) {
178+
if (finalRawBootstrap != null) {
179+
bootstrapSetter.setBootstrap(finalRawBootstrap);
180+
}
175181
delegate.start(listener);
176182
succeeded = true;
177183
}

googleapis/src/test/java/io/grpc/googleapis/GoogleCloudToProdNameResolverTest.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ public void onGcpAndNoProvidedBootstrapDelegateToXds() {
195195

196196
@SuppressWarnings("unchecked")
197197
@Test
198-
public void onGcpAndProvidedBootstrapAndFederationEnabledDelegateToXds() {
198+
public void onGcpAndNoProvidedBootstrapAndFederationEnabledDelegateToXds() {
199199
GoogleCloudToProdNameResolver.isOnGcp = true;
200-
GoogleCloudToProdNameResolver.xdsBootstrapProvided = true;
200+
GoogleCloudToProdNameResolver.xdsBootstrapProvided = false;
201201
GoogleCloudToProdNameResolver.enableFederation = true;
202202
createResolver();
203203
resolver.start(mockListener);
@@ -223,6 +223,21 @@ public void onGcpAndProvidedBootstrapAndFederationEnabledDelegateToXds() {
223223
ImmutableMap.of("xds_servers", ImmutableList.of(server)));
224224
}
225225

226+
@SuppressWarnings("unchecked")
227+
@Test
228+
public void onGcpAndProvidedBootstrapAndFederationEnabledDontDelegateToXds() {
229+
GoogleCloudToProdNameResolver.isOnGcp = true;
230+
GoogleCloudToProdNameResolver.xdsBootstrapProvided = true;
231+
GoogleCloudToProdNameResolver.enableFederation = true;
232+
createResolver();
233+
resolver.start(mockListener);
234+
fakeExecutor.runDueTasks();
235+
assertThat(delegatedResolver.keySet()).containsExactly("xds");
236+
verify(Iterables.getOnlyElement(delegatedResolver.values())).start(mockListener);
237+
// Bootstrapper should not have been set, since there was no user provided config.
238+
assertThat(fakeBootstrapSetter.bootstrapRef.get()).isNull();
239+
}
240+
226241
@Test
227242
public void failToQueryMetadata() {
228243
GoogleCloudToProdNameResolver.isOnGcp = true;

0 commit comments

Comments
 (0)