mirror of https://github.com/grpc/grpc-java.git
xds: fix the new server API for ServerXdsClient (#7666)
This commit is contained in:
parent
192614bf51
commit
3811ef3d22
|
|
@ -58,7 +58,7 @@ final class ServerXdsClient extends AbstractXdsClient {
|
||||||
private int listenerPort = -1;
|
private int listenerPort = -1;
|
||||||
private final boolean newServerApi;
|
private final boolean newServerApi;
|
||||||
@Nullable private final String instanceIp;
|
@Nullable private final String instanceIp;
|
||||||
private final String grpcServerResourceId;
|
private String grpcServerResourceId;
|
||||||
@Nullable
|
@Nullable
|
||||||
private ScheduledHandle ldsRespTimer;
|
private ScheduledHandle ldsRespTimer;
|
||||||
|
|
||||||
|
|
@ -78,6 +78,13 @@ final class ServerXdsClient extends AbstractXdsClient {
|
||||||
listenerWatcher = checkNotNull(watcher, "watcher");
|
listenerWatcher = checkNotNull(watcher, "watcher");
|
||||||
checkArgument(port > 0, "port needs to be > 0");
|
checkArgument(port > 0, "port needs to be > 0");
|
||||||
listenerPort = port;
|
listenerPort = port;
|
||||||
|
if (newServerApi) {
|
||||||
|
String listeningAddress = instanceIp + ":" + listenerPort;
|
||||||
|
grpcServerResourceId =
|
||||||
|
grpcServerResourceId + "?udpa.resource.listening_address=" + listeningAddress;
|
||||||
|
} else {
|
||||||
|
grpcServerResourceId = ":" + listenerPort;
|
||||||
|
}
|
||||||
getSyncContext().execute(new Runnable() {
|
getSyncContext().execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
@ -90,7 +97,7 @@ final class ServerXdsClient extends AbstractXdsClient {
|
||||||
ldsRespTimer =
|
ldsRespTimer =
|
||||||
getSyncContext()
|
getSyncContext()
|
||||||
.schedule(
|
.schedule(
|
||||||
new ListenerResourceFetchTimeoutTask(":" + port),
|
new ListenerResourceFetchTimeoutTask(grpcServerResourceId),
|
||||||
INITIAL_RESOURCE_FETCH_TIMEOUT_SEC, TimeUnit.SECONDS, getTimeService());
|
INITIAL_RESOURCE_FETCH_TIMEOUT_SEC, TimeUnit.SECONDS, getTimeService());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -101,10 +108,7 @@ final class ServerXdsClient extends AbstractXdsClient {
|
||||||
@Override
|
@Override
|
||||||
Collection<String> getSubscribedResources(ResourceType type) {
|
Collection<String> getSubscribedResources(ResourceType type) {
|
||||||
if (newServerApi) {
|
if (newServerApi) {
|
||||||
String listeningAddress = instanceIp + ":" + listenerPort;
|
return ImmutableList.<String>of(grpcServerResourceId);
|
||||||
String resourceName =
|
|
||||||
grpcServerResourceId + "?udpa.resource.listening_address=" + listeningAddress;
|
|
||||||
return ImmutableList.<String>of(resourceName);
|
|
||||||
} else {
|
} else {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
@ -161,7 +165,7 @@ final class ServerXdsClient extends AbstractXdsClient {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (ldsRespTimer == null) {
|
if (ldsRespTimer == null) {
|
||||||
listenerWatcher.onResourceDoesNotExist(":" + listenerPort);
|
listenerWatcher.onResourceDoesNotExist(grpcServerResourceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ackResponse(ResourceType.LDS, versionInfo, nonce);
|
ackResponse(ResourceType.LDS, versionInfo, nonce);
|
||||||
|
|
@ -172,17 +176,16 @@ final class ServerXdsClient extends AbstractXdsClient {
|
||||||
|
|
||||||
private boolean isRequestedListener(Listener listener) {
|
private boolean isRequestedListener(Listener listener) {
|
||||||
if (newServerApi) {
|
if (newServerApi) {
|
||||||
return "TRAFFICDIRECTOR_INBOUND_LISTENER".equals(listener.getName())
|
return grpcServerResourceId.equals(listener.getName())
|
||||||
&& listener.getTrafficDirection().equals(TrafficDirection.INBOUND)
|
&& listener.getTrafficDirection().equals(TrafficDirection.INBOUND)
|
||||||
&& hasMatchingFilter(listener.getFilterChainsList());
|
&& isAddressMatching(listener.getAddress(), listenerPort);
|
||||||
}
|
}
|
||||||
return isAddressMatching(listener.getAddress())
|
return isAddressMatching(listener.getAddress(), 15001)
|
||||||
&& hasMatchingFilter(listener.getFilterChainsList());
|
&& hasMatchingFilter(listener.getFilterChainsList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAddressMatching(Address address) {
|
private boolean isAddressMatching(Address address, int portToMatch) {
|
||||||
return newServerApi || (address.hasSocketAddress()
|
return address.hasSocketAddress() && (address.getSocketAddress().getPortValue() == portToMatch);
|
||||||
&& (address.getSocketAddress().getPortValue() == 15001));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasMatchingFilter(List<FilterChain> filterChainsList) {
|
private boolean hasMatchingFilter(List<FilterChain> filterChainsList) {
|
||||||
|
|
@ -211,7 +214,7 @@ final class ServerXdsClient extends AbstractXdsClient {
|
||||||
ldsRespTimer =
|
ldsRespTimer =
|
||||||
getSyncContext()
|
getSyncContext()
|
||||||
.schedule(
|
.schedule(
|
||||||
new ListenerResourceFetchTimeoutTask(":" + listenerPort),
|
new ListenerResourceFetchTimeoutTask(grpcServerResourceId),
|
||||||
INITIAL_RESOURCE_FETCH_TIMEOUT_SEC, TimeUnit.SECONDS, getTimeService());
|
INITIAL_RESOURCE_FETCH_TIMEOUT_SEC, TimeUnit.SECONDS, getTimeService());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ public final class XdsClientWrapperForServerSds {
|
||||||
private final int port;
|
private final int port;
|
||||||
private ScheduledExecutorService timeService;
|
private ScheduledExecutorService timeService;
|
||||||
private XdsClient.ListenerWatcher listenerWatcher;
|
private XdsClient.ListenerWatcher listenerWatcher;
|
||||||
|
private boolean newServerApi;
|
||||||
@VisibleForTesting final Set<ServerWatcher> serverWatchers = new HashSet<>();
|
@VisibleForTesting final Set<ServerWatcher> serverWatchers = new HashSet<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -109,6 +110,7 @@ public final class XdsClientWrapperForServerSds {
|
||||||
}
|
}
|
||||||
Node node = bootstrapInfo.getNode();
|
Node node = bootstrapInfo.getNode();
|
||||||
timeService = SharedResourceHolder.get(timeServiceResource);
|
timeService = SharedResourceHolder.get(timeServiceResource);
|
||||||
|
newServerApi = channel.isUseProtocolV3() && experimentalNewServerApiEnvVar;
|
||||||
XdsClient xdsClientImpl =
|
XdsClient xdsClientImpl =
|
||||||
new ServerXdsClient(
|
new ServerXdsClient(
|
||||||
channel,
|
channel,
|
||||||
|
|
@ -180,7 +182,8 @@ public final class XdsClientWrapperForServerSds {
|
||||||
FilterChainComparator comparator = new FilterChainComparator(localInetAddr);
|
FilterChainComparator comparator = new FilterChainComparator(localInetAddr);
|
||||||
FilterChain bestMatch =
|
FilterChain bestMatch =
|
||||||
filterChains.isEmpty() ? null : Collections.max(filterChains, comparator);
|
filterChains.isEmpty() ? null : Collections.max(filterChains, comparator);
|
||||||
if (bestMatch != null && comparator.isMatching(bestMatch.getFilterChainMatch())) {
|
if (bestMatch != null
|
||||||
|
&& (newServerApi || comparator.isMatching(bestMatch.getFilterChainMatch()))) {
|
||||||
return bestMatch.getDownstreamTlsContext();
|
return bestMatch.getDownstreamTlsContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -222,7 +222,6 @@ public class ServerXdsClientNewServerApiTest {
|
||||||
StreamObserver<DiscoveryResponse> responseObserver = responseObservers.poll();
|
StreamObserver<DiscoveryResponse> responseObserver = responseObservers.poll();
|
||||||
StreamObserver<DiscoveryRequest> requestObserver = requestObservers.poll();
|
StreamObserver<DiscoveryRequest> requestObserver = requestObservers.poll();
|
||||||
|
|
||||||
// Client sends an LDS request with null in lds resource name
|
|
||||||
verify(requestObserver)
|
verify(requestObserver)
|
||||||
.onNext(eq(XdsClientTestHelper.buildDiscoveryRequest(NODE, "",
|
.onNext(eq(XdsClientTestHelper.buildDiscoveryRequest(NODE, "",
|
||||||
ImmutableList.of("test/value?udpa.resource.listening_address=192.168.3.7:7000"),
|
ImmutableList.of("test/value?udpa.resource.listening_address=192.168.3.7:7000"),
|
||||||
|
|
@ -262,7 +261,8 @@ public class ServerXdsClientNewServerApiTest {
|
||||||
verify(listenerWatcher, never()).onResourceDoesNotExist(":" + PORT);
|
verify(listenerWatcher, never()).onResourceDoesNotExist(":" + PORT);
|
||||||
verify(listenerWatcher, never()).onError(any(Status.class));
|
verify(listenerWatcher, never()).onError(any(Status.class));
|
||||||
fakeClock.forwardTime(ServerXdsClient.INITIAL_RESOURCE_FETCH_TIMEOUT_SEC, TimeUnit.SECONDS);
|
fakeClock.forwardTime(ServerXdsClient.INITIAL_RESOURCE_FETCH_TIMEOUT_SEC, TimeUnit.SECONDS);
|
||||||
verify(listenerWatcher).onResourceDoesNotExist(":" + PORT);
|
verify(listenerWatcher)
|
||||||
|
.onResourceDoesNotExist("test/value?udpa.resource.listening_address=192.168.3.7:" + PORT);
|
||||||
assertThat(fakeClock.getPendingTasks(LISTENER_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).isEmpty();
|
assertThat(fakeClock.getPendingTasks(LISTENER_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -273,7 +273,6 @@ public class ServerXdsClientNewServerApiTest {
|
||||||
StreamObserver<DiscoveryResponse> responseObserver = responseObservers.poll();
|
StreamObserver<DiscoveryResponse> responseObserver = responseObservers.poll();
|
||||||
StreamObserver<DiscoveryRequest> requestObserver = requestObservers.poll();
|
StreamObserver<DiscoveryRequest> requestObserver = requestObservers.poll();
|
||||||
|
|
||||||
// Client sends an LDS request with null in lds resource name
|
|
||||||
verify(requestObserver)
|
verify(requestObserver)
|
||||||
.onNext(
|
.onNext(
|
||||||
eq(
|
eq(
|
||||||
|
|
@ -286,27 +285,31 @@ public class ServerXdsClientNewServerApiTest {
|
||||||
"")));
|
"")));
|
||||||
assertThat(fakeClock.getPendingTasks(LISTENER_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).hasSize(1);
|
assertThat(fakeClock.getPendingTasks(LISTENER_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).hasSize(1);
|
||||||
|
|
||||||
final FilterChain filterChainOutbound = buildFilterChain(buildFilterChainMatch(8000), null);
|
final FilterChain filterChainInbound = buildFilterChain(buildFilterChainMatch("managed-mtls"),
|
||||||
final FilterChain filterChainInbound = buildFilterChain(buildFilterChainMatch(PORT,
|
|
||||||
CidrRange.newBuilder().setAddressPrefix(LOCAL_IP)
|
|
||||||
.setPrefixLen(UInt32Value.of(32)).build()),
|
|
||||||
CommonTlsContextTestsUtil.buildTestDownstreamTlsContext("google-sds-config-default",
|
CommonTlsContextTestsUtil.buildTestDownstreamTlsContext("google-sds-config-default",
|
||||||
"ROOTCA"),
|
"ROOTCA"),
|
||||||
buildTestFilter("envoy.http_connection_manager"));
|
buildTestFilter("envoy.http_connection_manager"));
|
||||||
List<Any> listeners = ImmutableList.of(
|
List<Any> listeners =
|
||||||
Any.pack(buildListener("bar.googleapis.com",
|
ImmutableList.of(
|
||||||
Any.pack(HttpConnectionManager.newBuilder()
|
Any.pack(
|
||||||
|
buildListener(
|
||||||
|
"bar.googleapis.com",
|
||||||
|
Any.pack(
|
||||||
|
HttpConnectionManager.newBuilder()
|
||||||
.setRouteConfig(
|
.setRouteConfig(
|
||||||
buildRouteConfiguration("route-bar.googleapis.com",
|
buildRouteConfiguration(
|
||||||
|
"route-bar.googleapis.com",
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
buildVirtualHost(
|
buildVirtualHost(
|
||||||
ImmutableList.of("bar.googleapis.com"),
|
ImmutableList.of("bar.googleapis.com"),
|
||||||
"cluster-bar.googleapis.com"))))
|
"cluster-bar.googleapis.com"))))
|
||||||
.build()))),
|
.build()))),
|
||||||
Any.pack(buildListenerWithFilterChain(LISTENER_NAME, 15001, "0.0.0.0",
|
Any.pack(
|
||||||
filterChainOutbound,
|
buildListenerWithFilterChain(
|
||||||
filterChainInbound
|
"test/value?udpa.resource.listening_address=192.168.3.7:7000",
|
||||||
)));
|
7000,
|
||||||
|
"0.0.0.0",
|
||||||
|
filterChainInbound)));
|
||||||
DiscoveryResponse response =
|
DiscoveryResponse response =
|
||||||
buildDiscoveryResponse("0", listeners, ResourceType.LDS.typeUrl(), "0000");
|
buildDiscoveryResponse("0", listeners, ResourceType.LDS.typeUrl(), "0000");
|
||||||
responseObserver.onNext(response);
|
responseObserver.onNext(response);
|
||||||
|
|
@ -327,20 +330,12 @@ public class ServerXdsClientNewServerApiTest {
|
||||||
verify(listenerWatcher, times(1)).onListenerChanged(listenerUpdateCaptor.capture());
|
verify(listenerWatcher, times(1)).onListenerChanged(listenerUpdateCaptor.capture());
|
||||||
ListenerUpdate configUpdate = listenerUpdateCaptor.getValue();
|
ListenerUpdate configUpdate = listenerUpdateCaptor.getValue();
|
||||||
EnvoyServerProtoData.Listener listener = configUpdate.getListener();
|
EnvoyServerProtoData.Listener listener = configUpdate.getListener();
|
||||||
assertThat(listener.getName()).isEqualTo(LISTENER_NAME);
|
assertThat(listener.getName())
|
||||||
assertThat(listener.getAddress()).isEqualTo("0.0.0.0:15001");
|
.isEqualTo("test/value?udpa.resource.listening_address=192.168.3.7:7000");
|
||||||
assertThat(listener.getFilterChains()).hasSize(2);
|
assertThat(listener.getAddress()).isEqualTo("0.0.0.0:7000");
|
||||||
EnvoyServerProtoData.FilterChain filterChainOutboundInListenerUpdate
|
assertThat(listener.getFilterChains()).hasSize(1);
|
||||||
= listener.getFilterChains().get(0);
|
|
||||||
assertThat(filterChainOutboundInListenerUpdate.getFilterChainMatch().getDestinationPort())
|
|
||||||
.isEqualTo(8000);
|
|
||||||
EnvoyServerProtoData.FilterChain filterChainInboundInListenerUpdate
|
EnvoyServerProtoData.FilterChain filterChainInboundInListenerUpdate
|
||||||
= listener.getFilterChains().get(1);
|
= listener.getFilterChains().get(0);
|
||||||
EnvoyServerProtoData.FilterChainMatch inBoundfilterChainMatch =
|
|
||||||
filterChainInboundInListenerUpdate.getFilterChainMatch();
|
|
||||||
assertThat(inBoundfilterChainMatch.getDestinationPort()).isEqualTo(PORT);
|
|
||||||
assertThat(inBoundfilterChainMatch.getPrefixRanges()).containsExactly(
|
|
||||||
new EnvoyServerProtoData.CidrRange(LOCAL_IP, 32));
|
|
||||||
CommonTlsContext downstreamCommonTlsContext =
|
CommonTlsContext downstreamCommonTlsContext =
|
||||||
filterChainInboundInListenerUpdate.getDownstreamTlsContext().getCommonTlsContext();
|
filterChainInboundInListenerUpdate.getDownstreamTlsContext().getCommonTlsContext();
|
||||||
assertThat(downstreamCommonTlsContext.getTlsCertificateSdsSecretConfigs(0).getName())
|
assertThat(downstreamCommonTlsContext.getTlsCertificateSdsSecretConfigs(0).getName())
|
||||||
|
|
@ -357,32 +352,23 @@ public class ServerXdsClientNewServerApiTest {
|
||||||
/** Client receives LDS responses for updating Listener previously received. */
|
/** Client receives LDS responses for updating Listener previously received. */
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void notifyUpdatedListener() throws InvalidProtocolBufferException {
|
public void notifyUpdatedListener() {
|
||||||
xdsClient.watchListenerData(PORT, listenerWatcher);
|
xdsClient.watchListenerData(PORT, listenerWatcher);
|
||||||
StreamObserver<DiscoveryResponse> responseObserver = responseObservers.poll();
|
StreamObserver<DiscoveryResponse> responseObserver = responseObservers.poll();
|
||||||
StreamObserver<DiscoveryRequest> requestObserver = requestObservers.poll();
|
StreamObserver<DiscoveryRequest> requestObserver = requestObservers.poll();
|
||||||
|
|
||||||
final FilterChain filterChainOutbound = buildFilterChain(buildFilterChainMatch(8000), null);
|
final FilterChain filterChainInbound = buildFilterChain(buildFilterChainMatch("managed-mtls"),
|
||||||
final FilterChain filterChainInbound = buildFilterChain(buildFilterChainMatch(PORT,
|
|
||||||
CidrRange.newBuilder().setAddressPrefix(LOCAL_IP)
|
|
||||||
.setPrefixLen(UInt32Value.of(32)).build()),
|
|
||||||
CommonTlsContextTestsUtil.buildTestDownstreamTlsContext("google-sds-config-default",
|
CommonTlsContextTestsUtil.buildTestDownstreamTlsContext("google-sds-config-default",
|
||||||
"ROOTCA"),
|
"ROOTCA"),
|
||||||
buildTestFilter("envoy.http_connection_manager"));
|
buildTestFilter("envoy.http_connection_manager"));
|
||||||
List<Any> listeners = ImmutableList.of(
|
List<Any> listeners =
|
||||||
Any.pack(buildListener("bar.googleapis.com",
|
|
||||||
Any.pack(HttpConnectionManager.newBuilder()
|
|
||||||
.setRouteConfig(
|
|
||||||
buildRouteConfiguration("route-bar.googleapis.com",
|
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
buildVirtualHost(
|
Any.pack(
|
||||||
ImmutableList.of("bar.googleapis.com"),
|
buildListenerWithFilterChain(
|
||||||
"cluster-bar.googleapis.com"))))
|
"test/value?udpa.resource.listening_address=192.168.3.7:7000",
|
||||||
.build()))),
|
7000,
|
||||||
Any.pack(buildListenerWithFilterChain(LISTENER_NAME, 15001, "0.0.0.0",
|
"0.0.0.0",
|
||||||
filterChainOutbound,
|
filterChainInbound)));
|
||||||
filterChainInbound
|
|
||||||
)));
|
|
||||||
DiscoveryResponse response =
|
DiscoveryResponse response =
|
||||||
buildDiscoveryResponse("0", listeners, ResourceType.LDS.typeUrl(), "0000");
|
buildDiscoveryResponse("0", listeners, ResourceType.LDS.typeUrl(), "0000");
|
||||||
responseObserver.onNext(response);
|
responseObserver.onNext(response);
|
||||||
|
|
@ -392,17 +378,20 @@ public class ServerXdsClientNewServerApiTest {
|
||||||
|
|
||||||
reset(requestObserver);
|
reset(requestObserver);
|
||||||
// Management server sends another LDS response with updates for Listener.
|
// Management server sends another LDS response with updates for Listener.
|
||||||
final FilterChain filterChainNewInbound = buildFilterChain(buildFilterChainMatch(PORT,
|
final FilterChain filterChainNewInbound =
|
||||||
CidrRange.newBuilder().setAddressPrefix(LOCAL_IP)
|
buildFilterChain(
|
||||||
.setPrefixLen(UInt32Value.of(32)).build()),
|
buildFilterChainMatch("managed-mtls"),
|
||||||
CommonTlsContextTestsUtil.buildTestDownstreamTlsContext("google-sds-config-default1",
|
CommonTlsContextTestsUtil.buildTestDownstreamTlsContext(
|
||||||
"ROOTCA2"),
|
"google-sds-config-default1", "ROOTCA2"),
|
||||||
buildTestFilter("envoy.http_connection_manager"));
|
buildTestFilter("envoy.http_connection_manager"));
|
||||||
List<Any> listeners1 =
|
List<Any> listeners1 =
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
Any.pack(
|
Any.pack(
|
||||||
buildListenerWithFilterChain(
|
buildListenerWithFilterChain(
|
||||||
LISTENER_NAME, 15001, "0.0.0.0", filterChainNewInbound)));
|
"test/value?udpa.resource.listening_address=192.168.3.7:7000",
|
||||||
|
7000,
|
||||||
|
"0.0.0.0",
|
||||||
|
filterChainNewInbound)));
|
||||||
DiscoveryResponse response1 =
|
DiscoveryResponse response1 =
|
||||||
buildDiscoveryResponse("1", listeners1, ResourceType.LDS.typeUrl(), "0001");
|
buildDiscoveryResponse("1", listeners1, ResourceType.LDS.typeUrl(), "0001");
|
||||||
responseObserver.onNext(response1);
|
responseObserver.onNext(response1);
|
||||||
|
|
@ -424,14 +413,11 @@ public class ServerXdsClientNewServerApiTest {
|
||||||
verify(listenerWatcher, times(2)).onListenerChanged(listenerUpdateCaptor.capture());
|
verify(listenerWatcher, times(2)).onListenerChanged(listenerUpdateCaptor.capture());
|
||||||
ListenerUpdate configUpdate = listenerUpdateCaptor.getValue();
|
ListenerUpdate configUpdate = listenerUpdateCaptor.getValue();
|
||||||
EnvoyServerProtoData.Listener listener = configUpdate.getListener();
|
EnvoyServerProtoData.Listener listener = configUpdate.getListener();
|
||||||
assertThat(listener.getName()).isEqualTo(LISTENER_NAME);
|
assertThat(listener.getName())
|
||||||
|
.isEqualTo("test/value?udpa.resource.listening_address=192.168.3.7:7000");
|
||||||
assertThat(listener.getFilterChains()).hasSize(1);
|
assertThat(listener.getFilterChains()).hasSize(1);
|
||||||
EnvoyServerProtoData.FilterChain filterChain =
|
EnvoyServerProtoData.FilterChain filterChain =
|
||||||
Iterables.getOnlyElement(listener.getFilterChains());
|
Iterables.getOnlyElement(listener.getFilterChains());
|
||||||
EnvoyServerProtoData.FilterChainMatch filterChainMatch = filterChain.getFilterChainMatch();
|
|
||||||
assertThat(filterChainMatch.getDestinationPort()).isEqualTo(PORT);
|
|
||||||
assertThat(filterChainMatch.getPrefixRanges()).containsExactly(
|
|
||||||
new EnvoyServerProtoData.CidrRange(LOCAL_IP, 32));
|
|
||||||
CommonTlsContext downstreamCommonTlsContext =
|
CommonTlsContext downstreamCommonTlsContext =
|
||||||
filterChain.getDownstreamTlsContext().getCommonTlsContext();
|
filterChain.getDownstreamTlsContext().getCommonTlsContext();
|
||||||
assertThat(downstreamCommonTlsContext.getTlsCertificateSdsSecretConfigs(0).getName())
|
assertThat(downstreamCommonTlsContext.getTlsCertificateSdsSecretConfigs(0).getName())
|
||||||
|
|
@ -444,45 +430,48 @@ public class ServerXdsClientNewServerApiTest {
|
||||||
.isEqualTo("ROOTCA2");
|
.isEqualTo("ROOTCA2");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Client receives LDS response containing non-matching port in the filterMatch. */
|
/** Client receives LDS response containing non-matching port. */
|
||||||
@Test
|
@Test
|
||||||
public void ldsResponse_nonMatchingPort() {
|
public void ldsResponse_nonMatchingPort() {
|
||||||
xdsClient.watchListenerData(PORT, listenerWatcher);
|
xdsClient.watchListenerData(PORT, listenerWatcher);
|
||||||
StreamObserver<DiscoveryResponse> responseObserver = responseObservers.poll();
|
StreamObserver<DiscoveryResponse> responseObserver = responseObservers.poll();
|
||||||
requestObservers.poll();
|
requestObservers.poll();
|
||||||
|
|
||||||
final FilterChain filterChainInbound = buildFilterChain(buildFilterChainMatch(8000), null);
|
final FilterChain filterChainInbound =
|
||||||
final FilterChain filterChainOutbound = buildFilterChain(buildFilterChainMatch(
|
buildFilterChain(buildFilterChainMatch("managed-mtls"), null);
|
||||||
PORT + 1, // add 1 to mismatch
|
|
||||||
CidrRange.newBuilder().setAddressPrefix(LOCAL_IP)
|
|
||||||
.setPrefixLen(UInt32Value.of(32)).build()),
|
|
||||||
|
|
||||||
CommonTlsContextTestsUtil.buildTestDownstreamTlsContext("google-sds-config-default",
|
List<Any> listeners =
|
||||||
"ROOTCA"),
|
ImmutableList.of(
|
||||||
buildTestFilter("envoy.http_connection_manager"));
|
Any.pack(
|
||||||
List<Any> listeners = ImmutableList.of(
|
buildListener(
|
||||||
Any.pack(buildListener("bar.googleapis.com",
|
"bar.googleapis.com",
|
||||||
Any.pack(HttpConnectionManager.newBuilder()
|
Any.pack(
|
||||||
|
HttpConnectionManager.newBuilder()
|
||||||
.setRouteConfig(
|
.setRouteConfig(
|
||||||
buildRouteConfiguration("route-bar.googleapis.com",
|
buildRouteConfiguration(
|
||||||
|
"route-bar.googleapis.com",
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
buildVirtualHost(
|
buildVirtualHost(
|
||||||
ImmutableList.of("bar.googleapis.com"),
|
ImmutableList.of("bar.googleapis.com"),
|
||||||
"cluster-bar.googleapis.com"))))
|
"cluster-bar.googleapis.com"))))
|
||||||
.build()))),
|
.build()))),
|
||||||
Any.pack(buildListenerWithFilterChain(LISTENER_NAME, PORT, "0.0.0.0",
|
Any.pack(
|
||||||
filterChainInbound,
|
buildListenerWithFilterChain(
|
||||||
filterChainOutbound
|
"test/value?udpa.resource.listening_address=192.168.3.7:7000",
|
||||||
)));
|
PORT + 1,
|
||||||
|
"0.0.0.0",
|
||||||
|
filterChainInbound)));
|
||||||
DiscoveryResponse response =
|
DiscoveryResponse response =
|
||||||
buildDiscoveryResponse("0", listeners, ResourceType.LDS.typeUrl(), "0000");
|
buildDiscoveryResponse("0", listeners, ResourceType.LDS.typeUrl(), "0000");
|
||||||
responseObserver.onNext(response);
|
responseObserver.onNext(response);
|
||||||
|
|
||||||
verify(listenerWatcher, never()).onListenerChanged(any(ListenerUpdate.class));
|
verify(listenerWatcher, never()).onListenerChanged(any(ListenerUpdate.class));
|
||||||
verify(listenerWatcher, never()).onResourceDoesNotExist(":" + PORT);
|
verify(listenerWatcher, never())
|
||||||
|
.onResourceDoesNotExist("test/value?udpa.resource.listening_address=192.168.3.7:" + PORT);
|
||||||
verify(listenerWatcher, never()).onError(any(Status.class));
|
verify(listenerWatcher, never()).onError(any(Status.class));
|
||||||
fakeClock.forwardTime(ServerXdsClient.INITIAL_RESOURCE_FETCH_TIMEOUT_SEC, TimeUnit.SECONDS);
|
fakeClock.forwardTime(ServerXdsClient.INITIAL_RESOURCE_FETCH_TIMEOUT_SEC, TimeUnit.SECONDS);
|
||||||
verify(listenerWatcher).onResourceDoesNotExist(":" + PORT);
|
verify(listenerWatcher)
|
||||||
|
.onResourceDoesNotExist("test/value?udpa.resource.listening_address=192.168.3.7:" + PORT);
|
||||||
assertThat(fakeClock.getPendingTasks(LISTENER_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).isEmpty();
|
assertThat(fakeClock.getPendingTasks(LISTENER_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -670,6 +659,10 @@ public class ServerXdsClientNewServerApiTest {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FilterChainMatch buildFilterChainMatch(String...values) {
|
||||||
|
return FilterChainMatch.newBuilder().addAllApplicationProtocols(Arrays.asList(values)).build();
|
||||||
|
}
|
||||||
|
|
||||||
static Filter buildTestFilter(String name) {
|
static Filter buildTestFilter(String name) {
|
||||||
return
|
return
|
||||||
Filter.newBuilder()
|
Filter.newBuilder()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue