Skip to content

Commit 69587c5

Browse files
authored
xds: use the correct resource id template as per xDS server gRFC (#7978)
1 parent c26ee03 commit 69587c5

File tree

6 files changed

+28
-14
lines changed

6 files changed

+28
-14
lines changed

xds/src/main/java/io/grpc/xds/Bootstrapper.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,18 @@ public static class BootstrapInfo {
106106
private List<ServerInfo> servers;
107107
private final Node node;
108108
@Nullable private final Map<String, CertificateProviderInfo> certProviders;
109-
@Nullable private final String grpcServerResourceId;
109+
@Nullable private final String serverListenerResourceNameTemplate;
110110

111111
@VisibleForTesting
112112
BootstrapInfo(
113113
List<ServerInfo> servers,
114114
Node node,
115115
Map<String, CertificateProviderInfo> certProviders,
116-
String grpcServerResourceId) {
116+
String serverListenerResourceNameTemplate) {
117117
this.servers = servers;
118118
this.node = node;
119119
this.certProviders = certProviders;
120-
this.grpcServerResourceId = grpcServerResourceId;
120+
this.serverListenerResourceNameTemplate = serverListenerResourceNameTemplate;
121121
}
122122

123123
/**
@@ -140,8 +140,8 @@ public Map<String, CertificateProviderInfo> getCertProviders() {
140140
}
141141

142142
@Nullable
143-
public String getGrpcServerResourceId() {
144-
return grpcServerResourceId;
143+
public String getServerListenerResourceNameTemplate() {
144+
return serverListenerResourceNameTemplate;
145145
}
146146
}
147147
}

xds/src/main/java/io/grpc/xds/BootstrapperImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ BootstrapInfo bootstrap(Map<String, ?> rawData) throws XdsInitializationExceptio
215215
certProviders.put(name, certificateProviderInfo);
216216
}
217217
}
218-
String grpcServerResourceId = JsonUtil.getString(rawData, "grpc_server_resource_name_id");
218+
String grpcServerResourceId =
219+
JsonUtil.getString(rawData, "server_listener_resource_name_template");
219220
return new BootstrapInfo(servers, nodeBuilder.build(), certProviders, grpcServerResourceId);
220221
}
221222

xds/src/main/java/io/grpc/xds/XdsClientWrapperForServerSds.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ public void createXdsClientAndStart() throws IOException {
112112
.keepAliveTime(5, TimeUnit.MINUTES).build();
113113
timeService = SharedResourceHolder.get(timeServiceResource);
114114
newServerApi = serverInfo.isUseProtocolV3();
115-
String grpcServerResourceId = bootstrapInfo.getGrpcServerResourceId();
115+
String grpcServerResourceId = bootstrapInfo.getServerListenerResourceNameTemplate();
116116
if (newServerApi && grpcServerResourceId == null) {
117-
throw new IOException("missing grpc_server_resource_name_id value in xds bootstrap");
117+
throw new IOException(
118+
"missing server_listener_resource_name_template value in xds bootstrap");
118119
}
119120
XdsClient xdsClientImpl =
120121
new ClientXdsClient(
@@ -155,8 +156,7 @@ public void onError(Status error) {
155156
reportError(error.asException(), isResourceAbsent(error));
156157
}
157158
};
158-
grpcServerResourceId =
159-
grpcServerResourceId + "?udpa.resource.listening_address=" + ("0.0.0.0:" + port);
159+
grpcServerResourceId = grpcServerResourceId.replaceAll("%s", "0.0.0.0:" + port);
160160
xdsClient.watchLdsResource(grpcServerResourceId, listenerWatcher);
161161
}
162162

xds/src/test/java/io/grpc/xds/BootstrapperImplTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,12 @@ public void parseBootstrap_missingPluginName() {
547547
public void parseBootstrap_grpcServerResourceId() throws XdsInitializationException {
548548
String rawData = "{\n"
549549
+ " \"xds_servers\": [],\n"
550-
+ " \"grpc_server_resource_name_id\": \"grpc/serverx\"\n"
550+
+ " \"server_listener_resource_name_template\": \"grpc/serverx=%s\"\n"
551551
+ "}";
552552

553553
bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
554554
BootstrapInfo info = bootstrapper.bootstrap();
555-
assertThat(info.getGrpcServerResourceId()).isEqualTo("grpc/serverx");
555+
assertThat(info.getServerListenerResourceNameTemplate()).isEqualTo("grpc/serverx=%s");
556556
}
557557

558558
@Test

xds/src/test/java/io/grpc/xds/XdsClientWrapperForServerSdsTestMisc.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,17 @@ public void startXdsClient_expectException() {
202202
verify(mockServerWatcher, never()).onError(any(Throwable.class), eq(false));
203203
}
204204

205+
@Test
206+
public void xdsClientStart_multipleReplacements() {
207+
xdsClientWrapperForServerSds.start(xdsClient, "grpc/server?%s and %s and one more %s");
208+
ArgumentCaptor<XdsClient.LdsResourceWatcher> listenerWatcherCaptor =
209+
ArgumentCaptor.forClass(null);
210+
verify(xdsClient)
211+
.watchLdsResource(
212+
eq("grpc/server?0.0.0.0:7000 and 0.0.0.0:7000 and one more 0.0.0.0:7000"),
213+
listenerWatcherCaptor.capture());
214+
}
215+
205216
private DownstreamTlsContext sendListenerUpdate(
206217
SocketAddress localAddress, DownstreamTlsContext tlsContext) throws UnknownHostException {
207218
when(channel.localAddress()).thenReturn(localAddress);
@@ -218,7 +229,8 @@ public static XdsClientWrapperForServerSds createXdsClientWrapperForServerSds(
218229
XdsClient mockXdsClient = mock(XdsClient.class);
219230
XdsClientWrapperForServerSds xdsClientWrapperForServerSds =
220231
new XdsClientWrapperForServerSds(port);
221-
xdsClientWrapperForServerSds.start(mockXdsClient, "grpc/server");
232+
xdsClientWrapperForServerSds.start(
233+
mockXdsClient, "grpc/server?udpa.resource.listening_address=%s");
222234
XdsSdsClientServerTest.generateListenerUpdateToWatcher(
223235
downstreamTlsContext, xdsClientWrapperForServerSds.getListenerWatcher());
224236
return xdsClientWrapperForServerSds;

xds/src/test/java/io/grpc/xds/XdsServerTestHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ static XdsClient.LdsResourceWatcher startAndGetWatcher(
3333
XdsClientWrapperForServerSds xdsClientWrapperForServerSds,
3434
XdsClient mockXdsClient,
3535
int port) {
36-
xdsClientWrapperForServerSds.start(mockXdsClient, "grpc/server");
36+
xdsClientWrapperForServerSds.start(
37+
mockXdsClient, "grpc/server?udpa.resource.listening_address=%s");
3738
ArgumentCaptor<XdsClient.LdsResourceWatcher> listenerWatcherCaptor = ArgumentCaptor
3839
.forClass(null);
3940
verify(mockXdsClient)

0 commit comments

Comments
 (0)