mirror of https://github.com/grpc/grpc-java.git
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.
This commit is contained in:
parent
b2895198c3
commit
b0635fa1d4
|
|
@ -156,22 +156,28 @@ final class GoogleCloudToProdNameResolver extends NameResolver {
|
||||||
class Resolve implements Runnable {
|
class Resolve implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String zone;
|
|
||||||
boolean supportIpv6;
|
|
||||||
ImmutableMap<String, ?> rawBootstrap = null;
|
ImmutableMap<String, ?> rawBootstrap = null;
|
||||||
try {
|
try {
|
||||||
zone = queryZoneMetadata(METADATA_URL_ZONE);
|
// User provided bootstrap configs are only supported with federation. If federation is
|
||||||
supportIpv6 = queryIpv6SupportMetadata(METADATA_URL_SUPPORT_IPV6);
|
// not enabled or there is no user provided config, we set a custom bootstrap override.
|
||||||
rawBootstrap = generateBootstrap(zone, supportIpv6);
|
// Otherwise, we don't set the override, which will allow a user provided bootstrap config
|
||||||
|
// to take effect.
|
||||||
|
if (!enableFederation || !xdsBootstrapProvided) {
|
||||||
|
rawBootstrap = generateBootstrap(queryZoneMetadata(METADATA_URL_ZONE),
|
||||||
|
queryIpv6SupportMetadata(METADATA_URL_SUPPORT_IPV6));
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
listener.onError(Status.INTERNAL.withDescription("Unable to get metadata").withCause(e));
|
listener.onError(
|
||||||
|
Status.INTERNAL.withDescription("Unable to get metadata").withCause(e));
|
||||||
} finally {
|
} finally {
|
||||||
final ImmutableMap<String, ?> finalRawBootstrap = rawBootstrap;
|
final ImmutableMap<String, ?> finalRawBootstrap = rawBootstrap;
|
||||||
syncContext.execute(new Runnable() {
|
syncContext.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!shutdown && finalRawBootstrap != null) {
|
if (!shutdown) {
|
||||||
|
if (finalRawBootstrap != null) {
|
||||||
bootstrapSetter.setBootstrap(finalRawBootstrap);
|
bootstrapSetter.setBootstrap(finalRawBootstrap);
|
||||||
|
}
|
||||||
delegate.start(listener);
|
delegate.start(listener);
|
||||||
succeeded = true;
|
succeeded = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -195,9 +195,9 @@ public class GoogleCloudToProdNameResolverTest {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void onGcpAndProvidedBootstrapAndFederationEnabledDelegateToXds() {
|
public void onGcpAndNoProvidedBootstrapAndFederationEnabledDelegateToXds() {
|
||||||
GoogleCloudToProdNameResolver.isOnGcp = true;
|
GoogleCloudToProdNameResolver.isOnGcp = true;
|
||||||
GoogleCloudToProdNameResolver.xdsBootstrapProvided = true;
|
GoogleCloudToProdNameResolver.xdsBootstrapProvided = false;
|
||||||
GoogleCloudToProdNameResolver.enableFederation = true;
|
GoogleCloudToProdNameResolver.enableFederation = true;
|
||||||
createResolver();
|
createResolver();
|
||||||
resolver.start(mockListener);
|
resolver.start(mockListener);
|
||||||
|
|
@ -223,6 +223,21 @@ public class GoogleCloudToProdNameResolverTest {
|
||||||
ImmutableMap.of("xds_servers", ImmutableList.of(server)));
|
ImmutableMap.of("xds_servers", ImmutableList.of(server)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
public void onGcpAndProvidedBootstrapAndFederationEnabledDontDelegateToXds() {
|
||||||
|
GoogleCloudToProdNameResolver.isOnGcp = true;
|
||||||
|
GoogleCloudToProdNameResolver.xdsBootstrapProvided = true;
|
||||||
|
GoogleCloudToProdNameResolver.enableFederation = true;
|
||||||
|
createResolver();
|
||||||
|
resolver.start(mockListener);
|
||||||
|
fakeExecutor.runDueTasks();
|
||||||
|
assertThat(delegatedResolver.keySet()).containsExactly("xds");
|
||||||
|
verify(Iterables.getOnlyElement(delegatedResolver.values())).start(mockListener);
|
||||||
|
// Bootstrapper should not have been set, since there was no user provided config.
|
||||||
|
assertThat(fakeBootstrapSetter.bootstrapRef.get()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void failToQueryMetadata() {
|
public void failToQueryMetadata() {
|
||||||
GoogleCloudToProdNameResolver.isOnGcp = true;
|
GoogleCloudToProdNameResolver.isOnGcp = true;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue