Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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.SCOPED_ROUTE;
import static io.envoyproxy.controlplane.cache.Resources.ResourceType.SECRET;

import com.google.common.base.Preconditions;
Expand All @@ -21,6 +22,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.ScopedRouteConfiguration;
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;
Expand All @@ -42,6 +44,7 @@ public enum ResourceType {
ENDPOINT,
LISTENER,
ROUTE,
SCOPED_ROUTE,
SECRET
}

Expand All @@ -64,6 +67,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 SCOPED_ROUTE_TYPE_URL =
"type.googleapis.com/envoy.config.route.v3" + ".ScopedRouteConfiguration";
public static final String SECRET_TYPE_URL =
"type.googleapis.com/envoy.extensions" + ".transport_sockets.tls.v3.Secret";

Expand All @@ -73,18 +78,20 @@ public static class V3 {
ENDPOINT_TYPE_URL,
LISTENER_TYPE_URL,
ROUTE_TYPE_URL,
SCOPED_ROUTE_TYPE_URL,
SECRET_TYPE_URL);
}

public static final List<ResourceType> RESOURCE_TYPES_IN_ORDER =
ImmutableList.of(CLUSTER, ENDPOINT, LISTENER, ROUTE, SECRET);
ImmutableList.of(CLUSTER, ENDPOINT, LISTENER, ROUTE, SCOPED_ROUTE, SECRET);

public static final Map<String, ResourceType> TYPE_URLS_TO_RESOURCE_TYPE =
new ImmutableMap.Builder<String, ResourceType>()
.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.SCOPED_ROUTE_TYPE_URL, SCOPED_ROUTE)
.put(Resources.V3.SECRET_TYPE_URL, SECRET)
.build();

Expand All @@ -94,6 +101,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.SCOPED_ROUTE_TYPE_URL, ScopedRouteConfiguration.class)
.put(Resources.V3.SECRET_TYPE_URL, Secret.class)
.build();

Expand All @@ -119,6 +127,10 @@ public static String getResourceName(Message resource) {
return ((RouteConfiguration) resource).getName();
}

if (resource instanceof ScopedRouteConfiguration) {
return ((ScopedRouteConfiguration) resource).getName();
}

if (resource instanceof Secret) {
return ((Secret) resource).getName();
}
Expand Down Expand Up @@ -173,6 +185,11 @@ public static <T extends Message> Set<String> getResourceReferences(Collection<V
refs.add(c.getName());
}
}
} else if (r instanceof ScopedRouteConfiguration) {
ScopedRouteConfiguration s = (ScopedRouteConfiguration) r;
if (!isNullOrEmpty(s.getRouteConfigurationName())) {
refs.add(s.getRouteConfigurationName());
}
} else if (r instanceof Listener) {

Listener l = (Listener) r;
Expand All @@ -196,6 +213,14 @@ public static <T extends Message> Set<String> getResourceReferences(Collection<V
&& !isNullOrEmpty(config.getRds().getRouteConfigName())) {
refs.add(config.getRds().getRouteConfigName());
}
if (config.getRouteSpecifierCase() == RouteSpecifierCase.SCOPED_ROUTES) {
if (config.getScopedRoutes().hasScopedRouteConfigurationsList()) {
for (ScopedRouteConfiguration s :
config.getScopedRoutes().getScopedRouteConfigurationsList().getScopedRouteConfigurationsList()) {
refs.add(s.getRouteConfigurationName());
}
}
}
} catch (InvalidProtocolBufferException e) {
LOGGER.error(
"Failed to convert v3 HTTP connection manager config struct into protobuf "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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.ScopedRouteConfiguration;
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;
Expand Down Expand Up @@ -231,6 +232,19 @@ public static RouteConfiguration createRoute(String routeName, String clusterNam
.build();
}

/**
* Returns a new test v3 scoped route.
*
* @param scppedRouteName name of the new scoped route
* @param routeName name of the route that is associated with this scoped route
*/
public static ScopedRouteConfiguration createScopedRoute(String scppedRouteName, String routeName) {
return ScopedRouteConfiguration.newBuilder()
.setName(scppedRouteName)
.setRouteConfigurationName(routeName)
.build();
}

/**
* Returns a new test v3 secret.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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.ScopedRouteConfiguration;
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.Secret;
import java.util.Collections;
import java.util.List;
Expand All @@ -32,17 +33,19 @@ public abstract class Snapshot extends io.envoyproxy.controlplane.cache.Snapshot
* Returns a new {@link io.envoyproxy.controlplane.cache.v3.Snapshot} instance that is versioned uniformly across all
* resources.
*
* @param clusters the cluster resources in this snapshot
* @param endpoints the endpoint resources in this snapshot
* @param listeners the listener resources in this snapshot
* @param routes the route resources in this snapshot
* @param version the version associated with all resources in this snapshot
* @param clusters the cluster resources in this snapshot
* @param endpoints the endpoint resources in this snapshot
* @param listeners the listener resources in this snapshot
* @param routes the route resources in this snapshot
* @param scopedRoutes the scopedRoute resources in this snapshot
* @param version the version associated with all resources in this snapshot
*/
public static Snapshot create(
Iterable<Cluster> clusters,
Iterable<ClusterLoadAssignment> endpoints,
Iterable<Listener> listeners,
Iterable<RouteConfiguration> routes,
Iterable<ScopedRouteConfiguration> scopedRoutes,
Iterable<Secret> secrets,
String version) {

Expand All @@ -55,6 +58,8 @@ public static Snapshot create(
.create(generateSnapshotResourceIterable(listeners), version),
SnapshotResources
.create(generateSnapshotResourceIterable(routes), version),
SnapshotResources
.create(generateSnapshotResourceIterable(scopedRoutes), version),
SnapshotResources
.create(generateSnapshotResourceIterable(secrets), version));
}
Expand All @@ -63,14 +68,16 @@ public static Snapshot create(
* Returns a new {@link io.envoyproxy.controlplane.cache.v3.Snapshot} instance that has separate versions for each
* resource type.
*
* @param clusters the cluster resources in this snapshot
* @param clustersVersion the version of the cluster resources
* @param endpoints the endpoint resources in this snapshot
* @param endpointsVersion the version of the endpoint resources
* @param listeners the listener resources in this snapshot
* @param listenersVersion the version of the listener resources
* @param routes the route resources in this snapshot
* @param routesVersion the version of the route resources
* @param clusters the cluster resources in this snapshot
* @param clustersVersion the version of the cluster resources
* @param endpoints the endpoint resources in this snapshot
* @param endpointsVersion the version of the endpoint resources
* @param listeners the listener resources in this snapshot
* @param listenersVersion the version of the listener resources
* @param routes the route resources in this snapshot
* @param routesVersion the version of the route resources
* @param scopedRoutes the route resources in this snapshot
* @param scopedRoutesVersion the version of the route resources
*/
public static Snapshot create(
Iterable<Cluster> clusters,
Expand All @@ -81,6 +88,8 @@ public static Snapshot create(
String listenersVersion,
Iterable<RouteConfiguration> routes,
String routesVersion,
Iterable<ScopedRouteConfiguration> scopedRoutes,
String scopedRoutesVersion,
Iterable<Secret> secrets,
String secretsVersion) {

Expand All @@ -94,6 +103,8 @@ public static Snapshot create(
listenersVersion),
SnapshotResources
.create(generateSnapshotResourceIterable(routes), routesVersion),
SnapshotResources
.create(generateSnapshotResourceIterable(scopedRoutes), scopedRoutesVersion),
SnapshotResources.create(generateSnapshotResourceIterable(secrets),
secretsVersion));
}
Expand All @@ -105,7 +116,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);
}

/**
Expand All @@ -128,6 +139,11 @@ public static Snapshot createEmpty(String version) {
*/
public abstract SnapshotResources<RouteConfiguration> routes();

/**
* Returns all scoped route items in the SRDS payload.
*/
public abstract SnapshotResources<ScopedRouteConfiguration> scopedRoutes();

/**
* Returns all secret items in the SDS payload.
*/
Expand All @@ -154,6 +170,14 @@ public void ensureConsistent() throws SnapshotConsistencyException {

ensureAllResourceNamesExist(Resources.V3.LISTENER_TYPE_URL, Resources.V3.ROUTE_TYPE_URL,
listenerRouteRefs, routes().versionedResources());

Set<String> srdsRefs = Resources.getResourceReferences(scopedRoutes().versionedResources().values());
ensureAllResourceNamesExist(
Resources.V3.SCOPED_ROUTE_TYPE_URL,
Resources.V3.ROUTE_TYPE_URL,
srdsRefs,
routes().versionedResources()
);
}

/**
Expand Down Expand Up @@ -189,6 +213,8 @@ public Map<String, VersionedResource<?>> resources(String typeUrl) {
return (Map) listeners().resources();
case ROUTE:
return (Map) routes().resources();
case SCOPED_ROUTE:
return (Map) scopedRoutes().resources();
case SECRET:
return (Map) secrets().resources();
default:
Expand All @@ -211,6 +237,8 @@ public Map<String, VersionedResource<?>> versionedResources(ResourceType resourc
return (Map) listeners().versionedResources();
case ROUTE:
return (Map) routes().versionedResources();
case SCOPED_ROUTE:
return (Map) scopedRoutes().versionedResources();
case SECRET:
return (Map) secrets().versionedResources();
default:
Expand Down Expand Up @@ -266,6 +294,8 @@ public String version(ResourceType resourceType, List<String> resourceNames) {
return listeners().version(resourceNames);
case ROUTE:
return routes().version(resourceNames);
case SCOPED_ROUTE:
return scopedRoutes().version(resourceNames);
case SECRET:
return secrets().version(resourceNames);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void getResourceReferencesReturnsExpectedReferencesForValidResourceMessag
.put((Collection)ImmutableList.of(ROUTE), ImmutableSet.of())
.put(
(Collection) ImmutableList.of(CLUSTER, ENDPOINT, LISTENER, ROUTE),
(Collection) ImmutableSet.of(CLUSTER_NAME, ROUTE_NAME))
ImmutableSet.of(CLUSTER_NAME, ROUTE_NAME))
.build();

cases.forEach(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static io.envoyproxy.controlplane.cache.Resources.V3.CLUSTER_TYPE_URL;
import static io.envoyproxy.controlplane.cache.Resources.V3.ROUTE_TYPE_URL;
import static io.envoyproxy.controlplane.cache.Resources.V3.SCOPED_ROUTE_TYPE_URL;
import static org.assertj.core.api.Assertions.assertThat;

import com.google.common.collect.ImmutableList;
Expand All @@ -19,6 +20,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.ScopedRouteConfiguration;
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.Secret;
import io.envoyproxy.envoy.service.discovery.v3.DiscoveryRequest;
import java.util.Collections;
Expand All @@ -39,6 +41,7 @@ public class SimpleCacheTest {
private static final String SECONDARY_CLUSTER_NAME = "cluster1";
private static final String LISTENER_NAME = "listener0";
private static final String ROUTE_NAME = "route0";
private static final String SCOPED_ROUTE_NAME = "scoped_route0";
private static final String SECRET_NAME = "secret0";

private static final String VERSION1 = UUID.randomUUID().toString();
Expand All @@ -49,6 +52,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(ScopedRouteConfiguration.newBuilder().setName(SCOPED_ROUTE_NAME).build()),
ImmutableList.of(Secret.newBuilder().setName(SECRET_NAME).build()),
VERSION1);

Expand All @@ -57,6 +61,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(ScopedRouteConfiguration.newBuilder().setName(SCOPED_ROUTE_NAME).build()),
ImmutableList.of(Secret.newBuilder().setName(SECRET_NAME).build()),
VERSION2);

Expand All @@ -67,6 +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(ScopedRouteConfiguration.newBuilder().setName(SCOPED_ROUTE_NAME).build()),
ImmutableList.of(Secret.newBuilder().setName(SECRET_NAME).build()),
VERSION2);

Expand Down Expand Up @@ -297,6 +303,7 @@ public void successfullyWatchAllResourceTypesWithSetBeforeWatchWithRequestVersio
Resources.V3.CLUSTER_TYPE_URL, Resources.V3.ENDPOINT_TYPE_URL,
Resources.V3.ENDPOINT_TYPE_URL, Resources.V3.LISTENER_TYPE_URL,
Resources.V3.LISTENER_TYPE_URL, ROUTE_TYPE_URL, ROUTE_TYPE_URL,
SCOPED_ROUTE_TYPE_URL, SCOPED_ROUTE_TYPE_URL,
Resources.V3.SECRET_TYPE_URL, Resources.V3.SECRET_TYPE_URL);
}

Expand Down Expand Up @@ -460,7 +467,8 @@ public void watchesAreReleasedAfterCancel() {
public void watchIsLeftOpenIfNotRespondedImmediately() {
SimpleCache<String> 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(
Expand Down
Loading