Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xds: add support for setting bootstrap file with java system property #7620

Merged
merged 1 commit into from Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/example-xds/README.md
Expand Up @@ -6,7 +6,7 @@ being configured with the XDS management protocol. Out-of-the-box they behave th
as their hello-world version.

__XDS support is incomplete and experimental, with limited compatibility. It
will be very hard to produce a working enviornment just by this example. Please
will be very hard to produce a working environment just by this example. Please
refer to documentation specific for your XDS management server and
environment.__

Expand All @@ -24,8 +24,8 @@ This creates the scripts `build/install/example-xds/bin/hello-world-client-xds`
### Run the example without using XDS Credentials

To use XDS, you should first deploy the XDS management server in your deployment environment
and know its name. You need to set the `GRPC_XDS_BOOTSTRAP` environment variable to point to the
gRPC XDS bootstrap file (see
and know its name. You need to set the `GRPC_XDS_BOOTSTRAP` environment variable (preferred) or if that is not set then
the `io.grpc.xds.bootstrap` java system property to point to the gRPC XDS bootstrap file (see
[gRFC A27](https://github.com/grpc/proposal/blob/master/A27-xds-global-load-balancing.md#xdsclient-and-bootstrap-file) for the
bootstrap format). This is needed by both `build/install/example-xds/bin/hello-world-client-xds`
and `build/install/example-xds/bin/hello-world-server-xds`.
Expand Down Expand Up @@ -61,7 +61,7 @@ $ export GRPC_XDS_BOOTSTRAP=/path/to/bootstrap.json
$ ./build/install/example-xds/bin/hello-world-server-xds 8000 my-test-xds-server --secure
```

2. Similarly, add `--secure` on the comamnd line when you run the xDS client:
2. Similarly, add `--secure` on the command line when you run the xDS client:
```
$ export GRPC_XDS_BOOTSTRAP=/path/to/bootstrap.json
$ ./build/install/example-xds/bin/hello-world-client-xds xds:///yourServersName:8000 my-test-xds-client --secure
Expand Down
13 changes: 10 additions & 3 deletions xds/src/main/java/io/grpc/xds/Bootstrapper.java
Expand Up @@ -47,21 +47,28 @@ public abstract class Bootstrapper {

private static final String LOG_PREFIX = "xds-bootstrap";
private static final String BOOTSTRAP_PATH_SYS_ENV_VAR = "GRPC_XDS_BOOTSTRAP";
private static final String BOOTSTRAP_PATH_SYS_PROPERTY_VAR = "io.grpc.xds.bootstrap";
@VisibleForTesting
static final String CLIENT_FEATURE_DISABLE_OVERPROVISIONING =
"envoy.lb.does_not_support_overprovisioning";

private static final Bootstrapper DEFAULT_INSTANCE = new Bootstrapper() {
@Override
public BootstrapInfo readBootstrap() throws XdsInitializationException {
String filePath = System.getenv(BOOTSTRAP_PATH_SYS_ENV_VAR);
String filePathSource = BOOTSTRAP_PATH_SYS_ENV_VAR;
String filePath = System.getenv(filePathSource);
if (filePath == null) {
filePathSource = BOOTSTRAP_PATH_SYS_PROPERTY_VAR;
filePath = System.getProperty(filePathSource);
}
if (filePath == null) {
throw new XdsInitializationException(
"Environment variable " + BOOTSTRAP_PATH_SYS_ENV_VAR + " not defined.");
"Environment variable " + BOOTSTRAP_PATH_SYS_ENV_VAR
+ " or Java System Property " + BOOTSTRAP_PATH_SYS_PROPERTY_VAR + " not defined.");
}
XdsLogger
sanjaypujare marked this conversation as resolved.
Show resolved Hide resolved
.withPrefix(LOG_PREFIX)
.log(XdsLogLevel.INFO, BOOTSTRAP_PATH_SYS_ENV_VAR + "={0}", filePath);
.log(XdsLogLevel.INFO, filePathSource + "={0}", filePath);
String fileContent;
try {
fileContent = new String(Files.readAllBytes(Paths.get(filePath)), StandardCharsets.UTF_8);
Expand Down
Expand Up @@ -201,7 +201,9 @@ public void startXdsClient_expectException() {
} catch (IOException expected) {
assertThat(expected)
.hasMessageThat()
.contains("Environment variable GRPC_XDS_BOOTSTRAP not defined");
.contains(
"Environment variable GRPC_XDS_BOOTSTRAP"
+ " or Java System Property io.grpc.xds.bootstrap not defined.");
}
ArgumentCaptor<Status> argCaptor = ArgumentCaptor.forClass(null);
verify(mockServerWatcher).onError(argCaptor.capture());
Expand All @@ -210,7 +212,9 @@ public void startXdsClient_expectException() {
assertThat(captured.getCause()).isInstanceOf(XdsInitializationException.class);
assertThat(captured.getCause())
.hasMessageThat()
.contains("Environment variable GRPC_XDS_BOOTSTRAP not defined");
.contains(
"Environment variable GRPC_XDS_BOOTSTRAP"
+ " or Java System Property io.grpc.xds.bootstrap not defined.");
}

private DownstreamTlsContext sendListenerUpdate(
Expand Down
8 changes: 6 additions & 2 deletions xds/src/test/java/io/grpc/xds/XdsServerBuilderTest.java
Expand Up @@ -236,7 +236,9 @@ public void xdsServerWithoutMockXdsClient_startError()
} catch (IOException expected) {
assertThat(expected)
.hasMessageThat()
.contains("Environment variable GRPC_XDS_BOOTSTRAP not defined");
.contains(
"Environment variable GRPC_XDS_BOOTSTRAP"
+ " or Java System Property io.grpc.xds.bootstrap not defined.");
}
ArgumentCaptor<Status> argCaptor = ArgumentCaptor.forClass(null);
verify(mockErrorNotifier).onError(argCaptor.capture());
Expand All @@ -245,7 +247,9 @@ public void xdsServerWithoutMockXdsClient_startError()
assertThat(captured.getCause()).isInstanceOf(XdsInitializationException.class);
assertThat(captured.getCause())
.hasMessageThat()
.contains("Environment variable GRPC_XDS_BOOTSTRAP not defined");
.contains(
"Environment variable GRPC_XDS_BOOTSTRAP"
+ " or Java System Property io.grpc.xds.bootstrap not defined.");
}

@Test
Expand Down