From 9d810c7430e8513e20da41ad4399a0ac16fa4489 Mon Sep 17 00:00:00 2001 From: Gavrilov_A Date: Fri, 25 Nov 2022 01:32:45 +0300 Subject: [PATCH 1/3] added VHDS support. Now you can create a lot of Virtual hosts and attach routes to them --- .../test/java/io/envoyproxy/controlplane/server/TestMain.java | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/test/java/io/envoyproxy/controlplane/server/TestMain.java b/server/src/test/java/io/envoyproxy/controlplane/server/TestMain.java index 713ff1294..ecba91438 100644 --- a/server/src/test/java/io/envoyproxy/controlplane/server/TestMain.java +++ b/server/src/test/java/io/envoyproxy/controlplane/server/TestMain.java @@ -36,6 +36,7 @@ public static void main(String[] arg) throws IOException, InterruptedException { ImmutableList.of(), "1")); + V3DiscoveryServer v3DiscoveryServer = new V3DiscoveryServer(cache); ServerBuilder builder = From 89dd182ec772c2fdca6dd244a68f93339fa256ce Mon Sep 17 00:00:00 2001 From: Gavrilov_A Date: Fri, 25 Nov 2022 02:03:50 +0300 Subject: [PATCH 2/3] added vhds support Signed-off-by: Gavrilov_A --- .../proto/envoy/config/route/v3/route.proto | 12 ++--- .../controlplane/cache/Resources.java | 19 ++++--- .../controlplane/cache/SnapshotResources.java | 2 + .../controlplane/cache/TestResources.java | 52 +++++++++++++++++-- .../controlplane/cache/v3/Snapshot.java | 21 +++++++- .../cache/v3/SimpleCacheTest.java | 16 +++--- .../controlplane/cache/v3/SnapshotTest.java | 19 +++++-- .../server/V3DiscoveryServer.java | 32 ++++++++---- ...dsDeltaDiscoveryRequestStreamObserver.java | 2 +- .../V3DeltaDiscoveryServerCallbacks.java | 4 +- .../V3DiscoveryServerAdsWarmingClusterIT.java | 2 + .../controlplane/server/V3TestSnapshots.java | 2 + 12 files changed, 138 insertions(+), 45 deletions(-) diff --git a/api/src/main/proto/envoy/config/route/v3/route.proto b/api/src/main/proto/envoy/config/route/v3/route.proto index c953e7803..e222088da 100644 --- a/api/src/main/proto/envoy/config/route/v3/route.proto +++ b/api/src/main/proto/envoy/config/route/v3/route.proto @@ -36,12 +36,12 @@ message RouteConfiguration { // An array of virtual hosts that make up the route table. repeated VirtualHost virtual_hosts = 2; - // An array of virtual hosts will be dynamically loaded via the VHDS API. - // Both *virtual_hosts* and *vhds* fields will be used when present. *virtual_hosts* can be used - // for a base routing table or for infrequently changing virtual hosts. *vhds* is used for - // on-demand discovery of virtual hosts. The contents of these two fields will be merged to - // generate a routing table for a given RouteConfiguration, with *vhds* derived configuration - // taking precedence. +// An array of virtual hosts will be dynamically loaded via the VHDS API. +// Both *virtual_hosts* and *vhds* fields will be used when present. *virtual_hosts* can be used +// for a base routing table or for infrequently changing virtual hosts. *vhds* is used for +// on-demand discovery of virtual hosts. The contents of these two fields will be merged to +// generate a routing table for a given RouteConfiguration, with *vhds* derived configuration +// taking precedence. Vhds vhds = 9; // Optionally specifies a list of HTTP headers that the connection manager diff --git a/cache/src/main/java/io/envoyproxy/controlplane/cache/Resources.java b/cache/src/main/java/io/envoyproxy/controlplane/cache/Resources.java index b405005aa..55d2b0630 100644 --- a/cache/src/main/java/io/envoyproxy/controlplane/cache/Resources.java +++ b/cache/src/main/java/io/envoyproxy/controlplane/cache/Resources.java @@ -2,11 +2,7 @@ import static com.google.common.base.Strings.isNullOrEmpty; import static io.envoyproxy.controlplane.cache.Resources.ApiVersion.V3; -import static io.envoyproxy.controlplane.cache.Resources.ResourceType.CLUSTER; -import static io.envoyproxy.controlplane.cache.Resources.ResourceType.ENDPOINT; -import static io.envoyproxy.controlplane.cache.Resources.ResourceType.LISTENER; -import static io.envoyproxy.controlplane.cache.Resources.ResourceType.ROUTE; -import static io.envoyproxy.controlplane.cache.Resources.ResourceType.SECRET; +import static io.envoyproxy.controlplane.cache.Resources.ResourceType.*; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -21,6 +17,7 @@ import io.envoyproxy.envoy.config.listener.v3.FilterChain; import io.envoyproxy.envoy.config.listener.v3.Listener; import io.envoyproxy.envoy.config.route.v3.RouteConfiguration; +import io.envoyproxy.envoy.config.route.v3.VirtualHost; import io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager; import io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager.RouteSpecifierCase; import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.Secret; @@ -42,6 +39,7 @@ public enum ResourceType { ENDPOINT, LISTENER, ROUTE, + VIRTUAL_HOST, SECRET } @@ -64,6 +62,8 @@ public static class V3 { "type.googleapis.com/envoy.config.listener.v3" + ".Listener"; public static final String ROUTE_TYPE_URL = "type.googleapis.com/envoy.config.route.v3" + ".RouteConfiguration"; + public static final String VIRTUAL_HOST_TYPE_URL = + "type.googleapis.com/envoy.config.route.v3" + ".VirtualHost"; public static final String SECRET_TYPE_URL = "type.googleapis.com/envoy.extensions" + ".transport_sockets.tls.v3.Secret"; @@ -73,11 +73,12 @@ public static class V3 { ENDPOINT_TYPE_URL, LISTENER_TYPE_URL, ROUTE_TYPE_URL, + VIRTUAL_HOST_TYPE_URL, SECRET_TYPE_URL); } public static final List RESOURCE_TYPES_IN_ORDER = - ImmutableList.of(CLUSTER, ENDPOINT, LISTENER, ROUTE, SECRET); + ImmutableList.of(CLUSTER, ENDPOINT, LISTENER, ROUTE, VIRTUAL_HOST, SECRET); public static final Map TYPE_URLS_TO_RESOURCE_TYPE = new ImmutableMap.Builder() @@ -85,6 +86,7 @@ public static class V3 { .put(Resources.V3.ENDPOINT_TYPE_URL, ENDPOINT) .put(Resources.V3.LISTENER_TYPE_URL, LISTENER) .put(Resources.V3.ROUTE_TYPE_URL, ROUTE) + .put(Resources.V3.VIRTUAL_HOST_TYPE_URL, VIRTUAL_HOST) .put(Resources.V3.SECRET_TYPE_URL, SECRET) .build(); @@ -94,6 +96,7 @@ public static class V3 { .put(Resources.V3.ENDPOINT_TYPE_URL, ClusterLoadAssignment.class) .put(Resources.V3.LISTENER_TYPE_URL, Listener.class) .put(Resources.V3.ROUTE_TYPE_URL, RouteConfiguration.class) + .put(Resources.V3.VIRTUAL_HOST_TYPE_URL, VirtualHost.class) .put(Resources.V3.SECRET_TYPE_URL, Secret.class) .build(); @@ -119,6 +122,10 @@ public static String getResourceName(Message resource) { return ((RouteConfiguration) resource).getName(); } + if (resource instanceof VirtualHost) { + return ((VirtualHost) resource).getName(); + } + if (resource instanceof Secret) { return ((Secret) resource).getName(); } diff --git a/cache/src/main/java/io/envoyproxy/controlplane/cache/SnapshotResources.java b/cache/src/main/java/io/envoyproxy/controlplane/cache/SnapshotResources.java index f270ada2a..374c71f77 100644 --- a/cache/src/main/java/io/envoyproxy/controlplane/cache/SnapshotResources.java +++ b/cache/src/main/java/io/envoyproxy/controlplane/cache/SnapshotResources.java @@ -2,6 +2,8 @@ import com.google.auto.value.AutoValue; import com.google.protobuf.Message; +import com.google.protobuf.MessageLiteOrBuilder; + import java.util.List; import java.util.Map; import java.util.stream.Collector; diff --git a/cache/src/main/java/io/envoyproxy/controlplane/cache/TestResources.java b/cache/src/main/java/io/envoyproxy/controlplane/cache/TestResources.java index cc877c344..aebe5f3c0 100644 --- a/cache/src/main/java/io/envoyproxy/controlplane/cache/TestResources.java +++ b/cache/src/main/java/io/envoyproxy/controlplane/cache/TestResources.java @@ -20,16 +20,18 @@ import io.envoyproxy.envoy.config.listener.v3.Filter; import io.envoyproxy.envoy.config.listener.v3.FilterChain; import io.envoyproxy.envoy.config.listener.v3.Listener; -import io.envoyproxy.envoy.config.route.v3.Route; -import io.envoyproxy.envoy.config.route.v3.RouteAction; -import io.envoyproxy.envoy.config.route.v3.RouteConfiguration; -import io.envoyproxy.envoy.config.route.v3.RouteMatch; -import io.envoyproxy.envoy.config.route.v3.VirtualHost; +import io.envoyproxy.envoy.config.route.v3.*; +import io.envoyproxy.envoy.config.route.v3.VirtualHost.Builder; import io.envoyproxy.envoy.extensions.filters.http.router.v3.Router; import io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager; import io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager.CodecType; import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.Secret; import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.TlsCertificate; +import io.envoyproxy.envoy.service.route.v3.VirtualHostDiscoveryService; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; /** * {@code TestResources} provides helper methods for generating resource messages for testing. It is @@ -209,6 +211,36 @@ public static Listener createListener( .build(); } + /** + * Returns a new test v3 route. + * + * @param routeName name of the new route + */ + public static RouteConfiguration createVHDSRoute(String routeName) { + + ApiVersion adsTransportVersion = ApiVersion.V3; + + ConfigSource edsSource = + ConfigSource.newBuilder() + .setResourceApiVersion(ApiVersion.V3) + .setApiConfigSource( + ApiConfigSource.newBuilder() + .setTransportApiVersion(adsTransportVersion) + .setApiType(ApiConfigSource.ApiType.DELTA_GRPC) + .addGrpcServices( + GrpcService.newBuilder() + .setEnvoyGrpc( + GrpcService.EnvoyGrpc.newBuilder() + .setClusterName(XDS_CLUSTER)))) + .build(); + + RouteConfiguration routeConfigurationbuilder = RouteConfiguration.newBuilder() + .setVhds(Vhds.newBuilder().setConfigSource(edsSource).build()) + .setName(routeName).build(); + + return routeConfigurationbuilder; + } + /** * Returns a new test v3 route. * @@ -229,6 +261,16 @@ public static RouteConfiguration createRoute(String routeName, String clusterNam .build(); } + public static VirtualHost createVirtualHost(String name, int index, String domains) { + return VirtualHost.newBuilder() + .setName("all") + .addDomains("*") + .addRoutes( + Route.newBuilder() + .setMatch(RouteMatch.newBuilder().setPrefix("/"))) + .build(); + } + /** * Returns a new test v3 secret. * diff --git a/cache/src/main/java/io/envoyproxy/controlplane/cache/v3/Snapshot.java b/cache/src/main/java/io/envoyproxy/controlplane/cache/v3/Snapshot.java index 97f0e0abf..110bca875 100644 --- a/cache/src/main/java/io/envoyproxy/controlplane/cache/v3/Snapshot.java +++ b/cache/src/main/java/io/envoyproxy/controlplane/cache/v3/Snapshot.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import io.envoyproxy.envoy.config.route.v3.VirtualHost; /** * {@code Snapshot} is a data class that contains an internally consistent snapshot of v3 xDS resources. Snapshots @@ -43,7 +44,10 @@ public static Snapshot create( Iterable endpoints, Iterable listeners, Iterable routes, + Iterable virtualHosts, Iterable secrets, + + String version) { return new AutoValue_Snapshot( @@ -56,7 +60,9 @@ public static Snapshot create( SnapshotResources .create(generateSnapshotResourceIterable(routes), version), SnapshotResources - .create(generateSnapshotResourceIterable(secrets), version)); + .create(generateSnapshotResourceIterable(secrets), version), + SnapshotResources + .create(generateSnapshotResourceIterable(virtualHosts), version)); } /** @@ -81,6 +87,8 @@ public static Snapshot create( String listenersVersion, Iterable routes, String routesVersion, + Iterable virtualHosts, + String virtualHostsVersion, Iterable secrets, String secretsVersion) { @@ -94,6 +102,8 @@ public static Snapshot create( listenersVersion), SnapshotResources .create(generateSnapshotResourceIterable(routes), routesVersion), + SnapshotResources + .create(generateSnapshotResourceIterable(virtualHosts), virtualHostsVersion), SnapshotResources.create(generateSnapshotResourceIterable(secrets), secretsVersion)); } @@ -105,7 +115,7 @@ public static Snapshot create( */ public static Snapshot createEmpty(String version) { return create(Collections.emptySet(), Collections.emptySet(), - Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), version); + Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), version); } /** @@ -132,6 +142,7 @@ public static Snapshot createEmpty(String version) { * Returns all secret items in the SDS payload. */ public abstract SnapshotResources secrets(); + public abstract SnapshotResources virtualHosts(); /** * Asserts that all dependent resources are included in the snapshot. All EDS resources are listed by name in CDS @@ -189,6 +200,8 @@ public Map> resources(String typeUrl) { return (Map) listeners().resources(); case ROUTE: return (Map) routes().resources(); + case VIRTUAL_HOST: + return (Map) virtualHosts().resources(); case SECRET: return (Map) secrets().resources(); default: @@ -211,6 +224,8 @@ public Map> versionedResources(ResourceType resourc return (Map) listeners().versionedResources(); case ROUTE: return (Map) routes().versionedResources(); + case VIRTUAL_HOST: + return (Map) virtualHosts().versionedResources(); case SECRET: return (Map) secrets().versionedResources(); default: @@ -266,6 +281,8 @@ public String version(ResourceType resourceType, List resourceNames) { return listeners().version(resourceNames); case ROUTE: return routes().version(resourceNames); + case VIRTUAL_HOST: + return virtualHosts().version(resourceNames); case SECRET: return secrets().version(resourceNames); default: diff --git a/cache/src/test/java/io/envoyproxy/controlplane/cache/v3/SimpleCacheTest.java b/cache/src/test/java/io/envoyproxy/controlplane/cache/v3/SimpleCacheTest.java index a5de127ed..b7c636931 100644 --- a/cache/src/test/java/io/envoyproxy/controlplane/cache/v3/SimpleCacheTest.java +++ b/cache/src/test/java/io/envoyproxy/controlplane/cache/v3/SimpleCacheTest.java @@ -7,13 +7,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Sets; import com.google.protobuf.Message; -import io.envoyproxy.controlplane.cache.NodeGroup; -import io.envoyproxy.controlplane.cache.Resources; -import io.envoyproxy.controlplane.cache.Response; -import io.envoyproxy.controlplane.cache.StatusInfo; -import io.envoyproxy.controlplane.cache.VersionedResource; -import io.envoyproxy.controlplane.cache.Watch; -import io.envoyproxy.controlplane.cache.XdsRequest; +import io.envoyproxy.controlplane.cache.*; import io.envoyproxy.envoy.config.cluster.v3.Cluster; import io.envoyproxy.envoy.config.core.v3.Node; import io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment; @@ -49,7 +43,9 @@ public class SimpleCacheTest { ImmutableList.of(ClusterLoadAssignment.getDefaultInstance()), ImmutableList.of(Listener.newBuilder().setName(LISTENER_NAME).build()), ImmutableList.of(RouteConfiguration.newBuilder().setName(ROUTE_NAME).build()), + ImmutableList.of(TestResources.createVirtualHost("v1", 1, "a")), ImmutableList.of(Secret.newBuilder().setName(SECRET_NAME).build()), + VERSION1); private static final Snapshot SNAPSHOT2 = Snapshot.create( @@ -57,6 +53,8 @@ public class SimpleCacheTest { ImmutableList.of(ClusterLoadAssignment.getDefaultInstance()), ImmutableList.of(Listener.newBuilder().setName(LISTENER_NAME).build()), ImmutableList.of(RouteConfiguration.newBuilder().setName(ROUTE_NAME).build()), + ImmutableList.of(TestResources.createVirtualHost("v1", 1, "a")), + ImmutableList.of(Secret.newBuilder().setName(SECRET_NAME).build()), VERSION2); @@ -67,6 +65,8 @@ public class SimpleCacheTest { ClusterLoadAssignment.newBuilder().setClusterName(SECONDARY_CLUSTER_NAME).build()), ImmutableList.of(Listener.newBuilder().setName(LISTENER_NAME).build()), ImmutableList.of(RouteConfiguration.newBuilder().setName(ROUTE_NAME).build()), + ImmutableList.of(TestResources.createVirtualHost("v1", 1, "a")), + ImmutableList.of(Secret.newBuilder().setName(SECRET_NAME).build()), VERSION2); @@ -429,7 +429,7 @@ public void watchesAreReleasedAfterCancel() { public void watchIsLeftOpenIfNotRespondedImmediately() { SimpleCache cache = new SimpleCache<>(new SingleNodeGroup()); cache.setSnapshot(SingleNodeGroup.GROUP, Snapshot.create( - ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), VERSION1)); + ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(),VERSION1)); ResponseTracker responseTracker = new ResponseTracker(); Watch watch = cache.createWatch( diff --git a/cache/src/test/java/io/envoyproxy/controlplane/cache/v3/SnapshotTest.java b/cache/src/test/java/io/envoyproxy/controlplane/cache/v3/SnapshotTest.java index d40b02bd6..dfb60dac2 100644 --- a/cache/src/test/java/io/envoyproxy/controlplane/cache/v3/SnapshotTest.java +++ b/cache/src/test/java/io/envoyproxy/controlplane/cache/v3/SnapshotTest.java @@ -1,9 +1,6 @@ package io.envoyproxy.controlplane.cache.v3; -import static io.envoyproxy.controlplane.cache.Resources.V3.CLUSTER_TYPE_URL; -import static io.envoyproxy.controlplane.cache.Resources.V3.ENDPOINT_TYPE_URL; -import static io.envoyproxy.controlplane.cache.Resources.V3.LISTENER_TYPE_URL; -import static io.envoyproxy.controlplane.cache.Resources.V3.ROUTE_TYPE_URL; +import static io.envoyproxy.controlplane.cache.Resources.V3.*; import static io.envoyproxy.envoy.config.core.v3.ApiVersion.V3; import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; @@ -17,6 +14,7 @@ import io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment; import io.envoyproxy.envoy.config.listener.v3.Listener; import io.envoyproxy.envoy.config.route.v3.RouteConfiguration; +import io.envoyproxy.envoy.config.route.v3.VirtualHost; import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.Secret; import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; @@ -29,6 +27,7 @@ public class SnapshotTest { private static final String LISTENER_NAME = "listener0"; private static final String ROUTE_NAME = "route0"; private static final String SECRET_NAME = "secret0"; + private static final String VIRTUAL_HOST_NAME = "virtual0"; private static final int ENDPOINT_PORT = ThreadLocalRandom.current().nextInt(10000, 20000); private static final int LISTENER_PORT = ThreadLocalRandom.current().nextInt(20000, 30000); @@ -41,6 +40,7 @@ public class SnapshotTest { private static final RouteConfiguration ROUTE = TestResources.createRoute(ROUTE_NAME, CLUSTER_NAME); private static final Secret SECRET = TestResources.createSecret(SECRET_NAME); + private static final VirtualHost VIRTUAL_HOST = TestResources.createVirtualHost(VIRTUAL_HOST_NAME, 1, "a"); @Test public void createSingleVersionSetsResourcesCorrectly() { @@ -51,6 +51,7 @@ public void createSingleVersionSetsResourcesCorrectly() { ImmutableList.of(ENDPOINT), ImmutableList.of(LISTENER), ImmutableList.of(ROUTE), + ImmutableList.of(VIRTUAL_HOST), ImmutableList.of(SECRET), version); @@ -83,13 +84,16 @@ public void createSeparateVersionsSetsResourcesCorrectly() { final String listenersVersion = UUID.randomUUID().toString(); final String routesVersion = UUID.randomUUID().toString(); final String secretsVersion = UUID.randomUUID().toString(); + final String virtualHostsVersion = UUID.randomUUID().toString(); Snapshot snapshot = Snapshot.create( ImmutableList.of(CLUSTER), clustersVersion, ImmutableList.of(ENDPOINT), endpointsVersion, ImmutableList.of(LISTENER), listenersVersion, ImmutableList.of(ROUTE), routesVersion, + ImmutableList.of(VIRTUAL_HOST), virtualHostsVersion, ImmutableList.of(SECRET), secretsVersion + ); assertThat(snapshot.clusters().resources()) @@ -122,6 +126,7 @@ public void resourcesReturnsExpectedResources() { ImmutableList.of(ENDPOINT), ImmutableList.of(LISTENER), ImmutableList.of(ROUTE), + ImmutableList.of(VIRTUAL_HOST), ImmutableList.of(SECRET), UUID.randomUUID().toString()); @@ -160,6 +165,7 @@ public void versionReturnsExpectedVersion() { ImmutableList.of(ENDPOINT), ImmutableList.of(LISTENER), ImmutableList.of(ROUTE), + ImmutableList.of(VIRTUAL_HOST), ImmutableList.of(SECRET), version); @@ -182,6 +188,7 @@ public void ensureConsistentReturnsWithoutExceptionForConsistentSnapshot() ImmutableList.of(ENDPOINT), ImmutableList.of(LISTENER), ImmutableList.of(ROUTE), + ImmutableList.of(VIRTUAL_HOST), ImmutableList.of(SECRET), UUID.randomUUID().toString()); @@ -195,6 +202,7 @@ public void ensureConsistentThrowsIfEndpointOrRouteRefCountMismatch() { ImmutableList.of(), ImmutableList.of(LISTENER), ImmutableList.of(ROUTE), + ImmutableList.of(VIRTUAL_HOST), ImmutableList.of(SECRET), UUID.randomUUID().toString()); @@ -211,6 +219,7 @@ public void ensureConsistentThrowsIfEndpointOrRouteRefCountMismatch() { ImmutableList.of(ENDPOINT), ImmutableList.of(LISTENER), ImmutableList.of(), + ImmutableList.of(VIRTUAL_HOST), ImmutableList.of(SECRET), UUID.randomUUID().toString()); @@ -233,6 +242,7 @@ public void ensureConsistentThrowsIfEndpointOrRouteNamesMismatch() { ImmutableList.of(TestResources.createEndpoint(otherClusterName, ENDPOINT_PORT)), ImmutableList.of(LISTENER), ImmutableList.of(ROUTE), + ImmutableList.of(VIRTUAL_HOST), ImmutableList.of(SECRET), UUID.randomUUID().toString()); @@ -250,6 +260,7 @@ public void ensureConsistentThrowsIfEndpointOrRouteNamesMismatch() { ImmutableList.of(ENDPOINT), ImmutableList.of(LISTENER), ImmutableList.of(TestResources.createRoute(otherRouteName, CLUSTER_NAME)), + ImmutableList.of(VIRTUAL_HOST), ImmutableList.of(SECRET), UUID.randomUUID().toString()); diff --git a/server/src/main/java/io/envoyproxy/controlplane/server/V3DiscoveryServer.java b/server/src/main/java/io/envoyproxy/controlplane/server/V3DiscoveryServer.java index 56347eaaf..b36ebba1f 100644 --- a/server/src/main/java/io/envoyproxy/controlplane/server/V3DiscoveryServer.java +++ b/server/src/main/java/io/envoyproxy/controlplane/server/V3DiscoveryServer.java @@ -1,11 +1,5 @@ package io.envoyproxy.controlplane.server; -import static io.envoyproxy.envoy.service.discovery.v3.AggregatedDiscoveryServiceGrpc.AggregatedDiscoveryServiceImplBase; -import static io.envoyproxy.envoy.service.endpoint.v3.EndpointDiscoveryServiceGrpc.EndpointDiscoveryServiceImplBase; -import static io.envoyproxy.envoy.service.listener.v3.ListenerDiscoveryServiceGrpc.ListenerDiscoveryServiceImplBase; -import static io.envoyproxy.envoy.service.route.v3.RouteDiscoveryServiceGrpc.RouteDiscoveryServiceImplBase; -import static io.envoyproxy.envoy.service.secret.v3.SecretDiscoveryServiceGrpc.SecretDiscoveryServiceImplBase; - import com.google.common.base.Preconditions; import com.google.protobuf.Any; import io.envoyproxy.controlplane.cache.ConfigWatcher; @@ -15,16 +9,20 @@ import io.envoyproxy.controlplane.server.serializer.DefaultProtoResourcesSerializer; import io.envoyproxy.controlplane.server.serializer.ProtoResourcesSerializer; import io.envoyproxy.envoy.service.cluster.v3.ClusterDiscoveryServiceGrpc.ClusterDiscoveryServiceImplBase; -import io.envoyproxy.envoy.service.discovery.v3.DeltaDiscoveryRequest; -import io.envoyproxy.envoy.service.discovery.v3.DeltaDiscoveryResponse; -import io.envoyproxy.envoy.service.discovery.v3.DiscoveryRequest; -import io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse; -import io.envoyproxy.envoy.service.discovery.v3.Resource; +import io.envoyproxy.envoy.service.discovery.v3.*; import io.grpc.stub.StreamObserver; + import java.util.Collection; import java.util.Collections; import java.util.List; +import static io.envoyproxy.envoy.service.discovery.v3.AggregatedDiscoveryServiceGrpc.AggregatedDiscoveryServiceImplBase; +import static io.envoyproxy.envoy.service.endpoint.v3.EndpointDiscoveryServiceGrpc.EndpointDiscoveryServiceImplBase; +import static io.envoyproxy.envoy.service.listener.v3.ListenerDiscoveryServiceGrpc.ListenerDiscoveryServiceImplBase; +import static io.envoyproxy.envoy.service.route.v3.RouteDiscoveryServiceGrpc.RouteDiscoveryServiceImplBase; +import static io.envoyproxy.envoy.service.secret.v3.SecretDiscoveryServiceGrpc.SecretDiscoveryServiceImplBase; +import static io.envoyproxy.envoy.service.route.v3.VirtualHostDiscoveryServiceGrpc.VirtualHostDiscoveryServiceImplBase; + public class V3DiscoveryServer extends DiscoveryServer { public V3DiscoveryServer(ConfigWatcher configWatcher) { @@ -176,6 +174,18 @@ public StreamObserver deltaSecrets( }; } + public VirtualHostDiscoveryServiceImplBase getVirtualHostDiscoveryServiceImpl() { + return new VirtualHostDiscoveryServiceImplBase() { + + @Override + public StreamObserver deltaVirtualHosts( + StreamObserver responseObserver) { + + return createDeltaRequestHandler(responseObserver, false, Resources.V3.VIRTUAL_HOST_TYPE_URL); + } + }; + } + @Override protected XdsRequest wrapXdsRequest(DiscoveryRequest request) { return XdsRequest.create(request); diff --git a/server/src/main/java/io/envoyproxy/controlplane/server/XdsDeltaDiscoveryRequestStreamObserver.java b/server/src/main/java/io/envoyproxy/controlplane/server/XdsDeltaDiscoveryRequestStreamObserver.java index 01a424778..6d410eb35 100644 --- a/server/src/main/java/io/envoyproxy/controlplane/server/XdsDeltaDiscoveryRequestStreamObserver.java +++ b/server/src/main/java/io/envoyproxy/controlplane/server/XdsDeltaDiscoveryRequestStreamObserver.java @@ -36,7 +36,7 @@ public class XdsDeltaDiscoveryRequestStreamObserver extends DeltaDiscov this.pendingResources = new HashSet<>(); Resources.ResourceType resourceType = Resources.TYPE_URLS_TO_RESOURCE_TYPE.get(defaultTypeUrl); this.isWildcard = Resources.ResourceType.CLUSTER.equals(resourceType) - || Resources.ResourceType.LISTENER.equals(resourceType); + || Resources.ResourceType.LISTENER.equals(resourceType) || Resources.ResourceType.VIRTUAL_HOST.equals(resourceType); this.responses = new ConcurrentHashMap<>(); } diff --git a/server/src/test/java/io/envoyproxy/controlplane/server/V3DeltaDiscoveryServerCallbacks.java b/server/src/test/java/io/envoyproxy/controlplane/server/V3DeltaDiscoveryServerCallbacks.java index fdb008056..e57308979 100644 --- a/server/src/test/java/io/envoyproxy/controlplane/server/V3DeltaDiscoveryServerCallbacks.java +++ b/server/src/test/java/io/envoyproxy/controlplane/server/V3DeltaDiscoveryServerCallbacks.java @@ -21,8 +21,8 @@ public class V3DeltaDiscoveryServerCallbacks implements DiscoveryServerCallbacks /** - * Returns an implementation of DiscoveryServerCallbacks that throws if it sees a nod-delta v3 request, - * and counts down on provided latches in response to certain events. + * Returns an implementation of DiscoveryServerCallbacks that throws if it sees a v2 request, and counts down on + * provided latches in response to certain events. * * @param onStreamOpenLatch latch to call countDown() on when a v3 stream is opened. * @param onStreamRequestLatch latch to call countDown() on when a v3 request is seen. diff --git a/server/src/test/java/io/envoyproxy/controlplane/server/V3DiscoveryServerAdsWarmingClusterIT.java b/server/src/test/java/io/envoyproxy/controlplane/server/V3DiscoveryServerAdsWarmingClusterIT.java index 26eeceb69..cff099ebe 100644 --- a/server/src/test/java/io/envoyproxy/controlplane/server/V3DiscoveryServerAdsWarmingClusterIT.java +++ b/server/src/test/java/io/envoyproxy/controlplane/server/V3DiscoveryServerAdsWarmingClusterIT.java @@ -196,6 +196,8 @@ private static Snapshot createSnapshotWithNotWorkingCluster(boolean ads, ImmutableList.of(route), "2", ImmutableList.of(), + "2", + ImmutableList.of(), "2"); } diff --git a/server/src/test/java/io/envoyproxy/controlplane/server/V3TestSnapshots.java b/server/src/test/java/io/envoyproxy/controlplane/server/V3TestSnapshots.java index 44980eea2..8174e1e94 100644 --- a/server/src/test/java/io/envoyproxy/controlplane/server/V3TestSnapshots.java +++ b/server/src/test/java/io/envoyproxy/controlplane/server/V3TestSnapshots.java @@ -37,6 +37,7 @@ static Snapshot createSnapshot( ImmutableList.of(listener), ImmutableList.of(route), ImmutableList.of(), + ImmutableList.of(), version); } @@ -80,6 +81,7 @@ private static Snapshot createSnapshotNoEds( ImmutableList.of(listener), ImmutableList.of(route), ImmutableList.of(), + ImmutableList.of(), version); } From 870215bd2058cd0ea034ecd6f1b0dee245adfcdd Mon Sep 17 00:00:00 2001 From: Gavrilov_A Date: Mon, 5 Dec 2022 23:40:06 +0300 Subject: [PATCH 3/3] bug fixes Signed-off-by: Gavrilov_A --- .../controlplane/cache/Resources.java | 20 ++++++++----- .../controlplane/cache/SnapshotResources.java | 5 ++-- .../controlplane/cache/TestResources.java | 30 +++++++++++-------- .../controlplane/cache/v3/Snapshot.java | 8 +++-- .../cache/v3/SimpleCacheTest.java | 23 ++++++++++---- .../controlplane/cache/v3/SnapshotTest.java | 7 +++-- .../server/V3DiscoveryServer.java | 30 ++++++++++++++----- ...dsDeltaDiscoveryRequestStreamObserver.java | 3 +- .../controlplane/server/TestMain.java | 5 +++- 9 files changed, 87 insertions(+), 44 deletions(-) diff --git a/cache/src/main/java/io/envoyproxy/controlplane/cache/Resources.java b/cache/src/main/java/io/envoyproxy/controlplane/cache/Resources.java index 55d2b0630..b5311d8d6 100644 --- a/cache/src/main/java/io/envoyproxy/controlplane/cache/Resources.java +++ b/cache/src/main/java/io/envoyproxy/controlplane/cache/Resources.java @@ -2,7 +2,6 @@ import static com.google.common.base.Strings.isNullOrEmpty; import static io.envoyproxy.controlplane.cache.Resources.ApiVersion.V3; -import static io.envoyproxy.controlplane.cache.Resources.ResourceType.*; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -78,16 +77,21 @@ public static class V3 { } public static final List RESOURCE_TYPES_IN_ORDER = - ImmutableList.of(CLUSTER, ENDPOINT, LISTENER, ROUTE, VIRTUAL_HOST, SECRET); + ImmutableList.of(ResourceType.CLUSTER, + ResourceType.ENDPOINT, + ResourceType.LISTENER, + ResourceType.ROUTE, + ResourceType.VIRTUAL_HOST, + ResourceType.SECRET); public static final Map TYPE_URLS_TO_RESOURCE_TYPE = new ImmutableMap.Builder() - .put(Resources.V3.CLUSTER_TYPE_URL, CLUSTER) - .put(Resources.V3.ENDPOINT_TYPE_URL, ENDPOINT) - .put(Resources.V3.LISTENER_TYPE_URL, LISTENER) - .put(Resources.V3.ROUTE_TYPE_URL, ROUTE) - .put(Resources.V3.VIRTUAL_HOST_TYPE_URL, VIRTUAL_HOST) - .put(Resources.V3.SECRET_TYPE_URL, SECRET) + .put(Resources.V3.CLUSTER_TYPE_URL, ResourceType.CLUSTER) + .put(Resources.V3.ENDPOINT_TYPE_URL, ResourceType.ENDPOINT) + .put(Resources.V3.LISTENER_TYPE_URL, ResourceType.LISTENER) + .put(Resources.V3.ROUTE_TYPE_URL, ResourceType.ROUTE) + .put(Resources.V3.VIRTUAL_HOST_TYPE_URL, ResourceType.VIRTUAL_HOST) + .put(Resources.V3.SECRET_TYPE_URL, ResourceType.SECRET) .build(); public static final Map> RESOURCE_TYPE_BY_URL = diff --git a/cache/src/main/java/io/envoyproxy/controlplane/cache/SnapshotResources.java b/cache/src/main/java/io/envoyproxy/controlplane/cache/SnapshotResources.java index 374c71f77..d2c3898dd 100644 --- a/cache/src/main/java/io/envoyproxy/controlplane/cache/SnapshotResources.java +++ b/cache/src/main/java/io/envoyproxy/controlplane/cache/SnapshotResources.java @@ -2,7 +2,6 @@ import com.google.auto.value.AutoValue; import com.google.protobuf.Message; -import com.google.protobuf.MessageLiteOrBuilder; import java.util.List; import java.util.Map; @@ -23,7 +22,7 @@ public static SnapshotResources create( Iterable resources, String version) { ResourceMapBuilder resourcesMapBuilder = createResourcesMap(resources); - return new AutoValue_SnapshotResources<>( + return new io.envoyproxy.controlplane.cache.AutoValue_SnapshotResources<>( resourcesMapBuilder.getVersionedResources(), resourcesMapBuilder.getResources(), (r) -> version @@ -42,7 +41,7 @@ public static SnapshotResources create( Iterable> resources, ResourceVersionResolver versionResolver) { ResourceMapBuilder resourcesMapBuilder = createResourcesMap(resources); - return new AutoValue_SnapshotResources<>( + return new io.envoyproxy.controlplane.cache.AutoValue_SnapshotResources<>( resourcesMapBuilder.getVersionedResources(), resourcesMapBuilder.getResources(), versionResolver); diff --git a/cache/src/main/java/io/envoyproxy/controlplane/cache/TestResources.java b/cache/src/main/java/io/envoyproxy/controlplane/cache/TestResources.java index aebe5f3c0..9b1cac2df 100644 --- a/cache/src/main/java/io/envoyproxy/controlplane/cache/TestResources.java +++ b/cache/src/main/java/io/envoyproxy/controlplane/cache/TestResources.java @@ -20,18 +20,18 @@ import io.envoyproxy.envoy.config.listener.v3.Filter; import io.envoyproxy.envoy.config.listener.v3.FilterChain; import io.envoyproxy.envoy.config.listener.v3.Listener; -import io.envoyproxy.envoy.config.route.v3.*; -import io.envoyproxy.envoy.config.route.v3.VirtualHost.Builder; +import io.envoyproxy.envoy.config.route.v3.Route; +import io.envoyproxy.envoy.config.route.v3.RouteAction; +import io.envoyproxy.envoy.config.route.v3.RouteConfiguration; +import io.envoyproxy.envoy.config.route.v3.RouteMatch; +import io.envoyproxy.envoy.config.route.v3.Vhds; +import io.envoyproxy.envoy.config.route.v3.VirtualHost; import io.envoyproxy.envoy.extensions.filters.http.router.v3.Router; import io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager; import io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager.CodecType; import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.Secret; import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.TlsCertificate; -import io.envoyproxy.envoy.service.route.v3.VirtualHostDiscoveryService; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; /** * {@code TestResources} provides helper methods for generating resource messages for testing. It is @@ -216,7 +216,7 @@ public static Listener createListener( * * @param routeName name of the new route */ - public static RouteConfiguration createVHDSRoute(String routeName) { + public static RouteConfiguration createVhdsRoute(String routeName) { ApiVersion adsTransportVersion = ApiVersion.V3; @@ -234,11 +234,9 @@ public static RouteConfiguration createVHDSRoute(String routeName) { .setClusterName(XDS_CLUSTER)))) .build(); - RouteConfiguration routeConfigurationbuilder = RouteConfiguration.newBuilder() + return RouteConfiguration.newBuilder() .setVhds(Vhds.newBuilder().setConfigSource(edsSource).build()) .setName(routeName).build(); - - return routeConfigurationbuilder; } /** @@ -261,10 +259,16 @@ public static RouteConfiguration createRoute(String routeName, String clusterNam .build(); } - public static VirtualHost createVirtualHost(String name, int index, String domains) { + /** + * Returns a new Virtual Host. + * + * @param name Virtual host name + * @param domain domain name + */ + public static VirtualHost createVirtualHost(String name, String domain) { return VirtualHost.newBuilder() - .setName("all") - .addDomains("*") + .setName(name) + .addDomains(domain) .addRoutes( Route.newBuilder() .setMatch(RouteMatch.newBuilder().setPrefix("/"))) diff --git a/cache/src/main/java/io/envoyproxy/controlplane/cache/v3/Snapshot.java b/cache/src/main/java/io/envoyproxy/controlplane/cache/v3/Snapshot.java index 110bca875..804542c5d 100644 --- a/cache/src/main/java/io/envoyproxy/controlplane/cache/v3/Snapshot.java +++ b/cache/src/main/java/io/envoyproxy/controlplane/cache/v3/Snapshot.java @@ -15,12 +15,13 @@ import io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment; import io.envoyproxy.envoy.config.listener.v3.Listener; import io.envoyproxy.envoy.config.route.v3.RouteConfiguration; +import io.envoyproxy.envoy.config.route.v3.VirtualHost; import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.Secret; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; -import io.envoyproxy.envoy.config.route.v3.VirtualHost; + /** * {@code Snapshot} is a data class that contains an internally consistent snapshot of v3 xDS resources. Snapshots @@ -50,7 +51,7 @@ public static Snapshot create( String version) { - return new AutoValue_Snapshot( + return new io.envoyproxy.controlplane.cache.v3.AutoValue_Snapshot( SnapshotResources .create(generateSnapshotResourceIterable(clusters), version), SnapshotResources @@ -93,7 +94,7 @@ public static Snapshot create( String secretsVersion) { // TODO(snowp): add a builder alternative - return new AutoValue_Snapshot( + return new io.envoyproxy.controlplane.cache.v3.AutoValue_Snapshot( SnapshotResources.create(generateSnapshotResourceIterable(clusters), clustersVersion), SnapshotResources.create(generateSnapshotResourceIterable(endpoints), @@ -142,6 +143,7 @@ public static Snapshot createEmpty(String version) { * Returns all secret items in the SDS payload. */ public abstract SnapshotResources secrets(); + public abstract SnapshotResources virtualHosts(); /** diff --git a/cache/src/test/java/io/envoyproxy/controlplane/cache/v3/SimpleCacheTest.java b/cache/src/test/java/io/envoyproxy/controlplane/cache/v3/SimpleCacheTest.java index b7c636931..dee15795d 100644 --- a/cache/src/test/java/io/envoyproxy/controlplane/cache/v3/SimpleCacheTest.java +++ b/cache/src/test/java/io/envoyproxy/controlplane/cache/v3/SimpleCacheTest.java @@ -7,7 +7,14 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Sets; import com.google.protobuf.Message; -import io.envoyproxy.controlplane.cache.*; +import io.envoyproxy.controlplane.cache.NodeGroup; +import io.envoyproxy.controlplane.cache.Resources; +import io.envoyproxy.controlplane.cache.Response; +import io.envoyproxy.controlplane.cache.StatusInfo; +import io.envoyproxy.controlplane.cache.TestResources; +import io.envoyproxy.controlplane.cache.VersionedResource; +import io.envoyproxy.controlplane.cache.Watch; +import io.envoyproxy.controlplane.cache.XdsRequest; import io.envoyproxy.envoy.config.cluster.v3.Cluster; import io.envoyproxy.envoy.config.core.v3.Node; import io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment; @@ -43,7 +50,7 @@ public class SimpleCacheTest { ImmutableList.of(ClusterLoadAssignment.getDefaultInstance()), ImmutableList.of(Listener.newBuilder().setName(LISTENER_NAME).build()), ImmutableList.of(RouteConfiguration.newBuilder().setName(ROUTE_NAME).build()), - ImmutableList.of(TestResources.createVirtualHost("v1", 1, "a")), + ImmutableList.of(TestResources.createVirtualHost("v1", "a")), ImmutableList.of(Secret.newBuilder().setName(SECRET_NAME).build()), VERSION1); @@ -53,7 +60,7 @@ public class SimpleCacheTest { ImmutableList.of(ClusterLoadAssignment.getDefaultInstance()), ImmutableList.of(Listener.newBuilder().setName(LISTENER_NAME).build()), ImmutableList.of(RouteConfiguration.newBuilder().setName(ROUTE_NAME).build()), - ImmutableList.of(TestResources.createVirtualHost("v1", 1, "a")), + ImmutableList.of(TestResources.createVirtualHost("v1", "a")), ImmutableList.of(Secret.newBuilder().setName(SECRET_NAME).build()), VERSION2); @@ -65,7 +72,7 @@ public class SimpleCacheTest { ClusterLoadAssignment.newBuilder().setClusterName(SECONDARY_CLUSTER_NAME).build()), ImmutableList.of(Listener.newBuilder().setName(LISTENER_NAME).build()), ImmutableList.of(RouteConfiguration.newBuilder().setName(ROUTE_NAME).build()), - ImmutableList.of(TestResources.createVirtualHost("v1", 1, "a")), + ImmutableList.of(TestResources.createVirtualHost("v1","a")), ImmutableList.of(Secret.newBuilder().setName(SECRET_NAME).build()), VERSION2); @@ -429,7 +436,13 @@ public void watchesAreReleasedAfterCancel() { public void watchIsLeftOpenIfNotRespondedImmediately() { SimpleCache cache = new SimpleCache<>(new SingleNodeGroup()); cache.setSnapshot(SingleNodeGroup.GROUP, Snapshot.create( - ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(),VERSION1)); + ImmutableList.of(), + ImmutableList.of(), + ImmutableList.of(), + ImmutableList.of(), + ImmutableList.of(), + ImmutableList.of(), + VERSION1)); ResponseTracker responseTracker = new ResponseTracker(); Watch watch = cache.createWatch( diff --git a/cache/src/test/java/io/envoyproxy/controlplane/cache/v3/SnapshotTest.java b/cache/src/test/java/io/envoyproxy/controlplane/cache/v3/SnapshotTest.java index dfb60dac2..0165b9617 100644 --- a/cache/src/test/java/io/envoyproxy/controlplane/cache/v3/SnapshotTest.java +++ b/cache/src/test/java/io/envoyproxy/controlplane/cache/v3/SnapshotTest.java @@ -1,6 +1,9 @@ package io.envoyproxy.controlplane.cache.v3; -import static io.envoyproxy.controlplane.cache.Resources.V3.*; +import static io.envoyproxy.controlplane.cache.Resources.V3.CLUSTER_TYPE_URL; +import static io.envoyproxy.controlplane.cache.Resources.V3.ENDPOINT_TYPE_URL; +import static io.envoyproxy.controlplane.cache.Resources.V3.LISTENER_TYPE_URL; +import static io.envoyproxy.controlplane.cache.Resources.V3.ROUTE_TYPE_URL; import static io.envoyproxy.envoy.config.core.v3.ApiVersion.V3; import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; @@ -40,7 +43,7 @@ public class SnapshotTest { private static final RouteConfiguration ROUTE = TestResources.createRoute(ROUTE_NAME, CLUSTER_NAME); private static final Secret SECRET = TestResources.createSecret(SECRET_NAME); - private static final VirtualHost VIRTUAL_HOST = TestResources.createVirtualHost(VIRTUAL_HOST_NAME, 1, "a"); + private static final VirtualHost VIRTUAL_HOST = TestResources.createVirtualHost(VIRTUAL_HOST_NAME, "a"); @Test public void createSingleVersionSetsResourcesCorrectly() { diff --git a/server/src/main/java/io/envoyproxy/controlplane/server/V3DiscoveryServer.java b/server/src/main/java/io/envoyproxy/controlplane/server/V3DiscoveryServer.java index b36ebba1f..ca8059a8f 100644 --- a/server/src/main/java/io/envoyproxy/controlplane/server/V3DiscoveryServer.java +++ b/server/src/main/java/io/envoyproxy/controlplane/server/V3DiscoveryServer.java @@ -1,5 +1,12 @@ package io.envoyproxy.controlplane.server; +import static io.envoyproxy.envoy.service.discovery.v3.AggregatedDiscoveryServiceGrpc.AggregatedDiscoveryServiceImplBase; +import static io.envoyproxy.envoy.service.endpoint.v3.EndpointDiscoveryServiceGrpc.EndpointDiscoveryServiceImplBase; +import static io.envoyproxy.envoy.service.listener.v3.ListenerDiscoveryServiceGrpc.ListenerDiscoveryServiceImplBase; +import static io.envoyproxy.envoy.service.route.v3.RouteDiscoveryServiceGrpc.RouteDiscoveryServiceImplBase; +import static io.envoyproxy.envoy.service.route.v3.VirtualHostDiscoveryServiceGrpc.VirtualHostDiscoveryServiceImplBase; +import static io.envoyproxy.envoy.service.secret.v3.SecretDiscoveryServiceGrpc.SecretDiscoveryServiceImplBase; + import com.google.common.base.Preconditions; import com.google.protobuf.Any; import io.envoyproxy.controlplane.cache.ConfigWatcher; @@ -8,21 +15,20 @@ import io.envoyproxy.controlplane.cache.XdsRequest; import io.envoyproxy.controlplane.server.serializer.DefaultProtoResourcesSerializer; import io.envoyproxy.controlplane.server.serializer.ProtoResourcesSerializer; + import io.envoyproxy.envoy.service.cluster.v3.ClusterDiscoveryServiceGrpc.ClusterDiscoveryServiceImplBase; -import io.envoyproxy.envoy.service.discovery.v3.*; + +import io.envoyproxy.envoy.service.discovery.v3.DeltaDiscoveryRequest; +import io.envoyproxy.envoy.service.discovery.v3.DeltaDiscoveryResponse; +import io.envoyproxy.envoy.service.discovery.v3.DiscoveryRequest; +import io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse; +import io.envoyproxy.envoy.service.discovery.v3.Resource; import io.grpc.stub.StreamObserver; import java.util.Collection; import java.util.Collections; import java.util.List; -import static io.envoyproxy.envoy.service.discovery.v3.AggregatedDiscoveryServiceGrpc.AggregatedDiscoveryServiceImplBase; -import static io.envoyproxy.envoy.service.endpoint.v3.EndpointDiscoveryServiceGrpc.EndpointDiscoveryServiceImplBase; -import static io.envoyproxy.envoy.service.listener.v3.ListenerDiscoveryServiceGrpc.ListenerDiscoveryServiceImplBase; -import static io.envoyproxy.envoy.service.route.v3.RouteDiscoveryServiceGrpc.RouteDiscoveryServiceImplBase; -import static io.envoyproxy.envoy.service.secret.v3.SecretDiscoveryServiceGrpc.SecretDiscoveryServiceImplBase; -import static io.envoyproxy.envoy.service.route.v3.VirtualHostDiscoveryServiceGrpc.VirtualHostDiscoveryServiceImplBase; - public class V3DiscoveryServer extends DiscoveryServer { public V3DiscoveryServer(ConfigWatcher configWatcher) { @@ -165,6 +171,11 @@ public StreamObserver streamSecrets( return createRequestHandler(responseObserver, false, Resources.V3.SECRET_TYPE_URL); } + /** + * Returns delta Secrets. + * + * @param responseObserver Stream observer + */ @Override public StreamObserver deltaSecrets( StreamObserver responseObserver) { @@ -174,6 +185,9 @@ public StreamObserver deltaSecrets( }; } + /** + * Returns VHDS implementation that uses this server. + */ public VirtualHostDiscoveryServiceImplBase getVirtualHostDiscoveryServiceImpl() { return new VirtualHostDiscoveryServiceImplBase() { diff --git a/server/src/main/java/io/envoyproxy/controlplane/server/XdsDeltaDiscoveryRequestStreamObserver.java b/server/src/main/java/io/envoyproxy/controlplane/server/XdsDeltaDiscoveryRequestStreamObserver.java index 6d410eb35..505c33f9c 100644 --- a/server/src/main/java/io/envoyproxy/controlplane/server/XdsDeltaDiscoveryRequestStreamObserver.java +++ b/server/src/main/java/io/envoyproxy/controlplane/server/XdsDeltaDiscoveryRequestStreamObserver.java @@ -36,7 +36,8 @@ public class XdsDeltaDiscoveryRequestStreamObserver extends DeltaDiscov this.pendingResources = new HashSet<>(); Resources.ResourceType resourceType = Resources.TYPE_URLS_TO_RESOURCE_TYPE.get(defaultTypeUrl); this.isWildcard = Resources.ResourceType.CLUSTER.equals(resourceType) - || Resources.ResourceType.LISTENER.equals(resourceType) || Resources.ResourceType.VIRTUAL_HOST.equals(resourceType); + || Resources.ResourceType.LISTENER.equals(resourceType) + || Resources.ResourceType.VIRTUAL_HOST.equals(resourceType); this.responses = new ConcurrentHashMap<>(); } diff --git a/server/src/test/java/io/envoyproxy/controlplane/server/TestMain.java b/server/src/test/java/io/envoyproxy/controlplane/server/TestMain.java index ecba91438..86d712eab 100644 --- a/server/src/test/java/io/envoyproxy/controlplane/server/TestMain.java +++ b/server/src/test/java/io/envoyproxy/controlplane/server/TestMain.java @@ -32,6 +32,7 @@ public static void main(String[] arg) throws IOException, InterruptedException { "cluster0", "127.0.0.1", 1234, Cluster.DiscoveryType.STATIC)), ImmutableList.of(), ImmutableList.of(), + ImmutableList.of(TestResources.createVhdsRoute("name1")), ImmutableList.of(), ImmutableList.of(), "1")); @@ -39,12 +40,13 @@ public static void main(String[] arg) throws IOException, InterruptedException { V3DiscoveryServer v3DiscoveryServer = new V3DiscoveryServer(cache); - ServerBuilder builder = + ServerBuilder builder = NettyServerBuilder.forPort(12345) .addService(v3DiscoveryServer.getAggregatedDiscoveryServiceImpl()) .addService(v3DiscoveryServer.getClusterDiscoveryServiceImpl()) .addService(v3DiscoveryServer.getEndpointDiscoveryServiceImpl()) .addService(v3DiscoveryServer.getListenerDiscoveryServiceImpl()) + .addService(v3DiscoveryServer.getVirtualHostDiscoveryServiceImpl()) .addService(v3DiscoveryServer.getRouteDiscoveryServiceImpl()); Server server = builder.build(); @@ -65,6 +67,7 @@ public static void main(String[] arg) throws IOException, InterruptedException { "cluster1", "127.0.0.1", 1235, Cluster.DiscoveryType.STATIC)), ImmutableList.of(), ImmutableList.of(), + ImmutableList.of(TestResources.createVhdsRoute("name2")), ImmutableList.of(), ImmutableList.of(), "1"));