Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

VHDS Support #529

Merged
merged 4 commits into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/cache/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
Cluster
Route
ScopedRoute
VirtualHost
Listener
Secret
Runtime
Expand Down
6 changes: 4 additions & 2 deletions pkg/cache/v3/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ func (f *fixtureGenerator) snapshot() *cache.Snapshot {
map[rsrc.Type][]types.Resource{
rsrc.EndpointType: {testEndpoint},
rsrc.ClusterType: {testCluster},
rsrc.RouteType: {testRoute},
rsrc.ListenerType: {testListener},
rsrc.RouteType: {testRoute, testEmbeddedRoute},
rsrc.ScopedRouteType: {testScopedRoute},
rsrc.VirtualHostType: {testVirtualHost},
rsrc.ListenerType: {testScopedListener, testListener},
rsrc.RuntimeType: {testRuntime},
rsrc.SecretType: {testSecret[0]},
rsrc.ExtensionConfigType: {testExtensionConfig},
Expand Down
7 changes: 6 additions & 1 deletion pkg/cache/v3/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ func GetResponseType(typeURL resource.Type) types.ResponseType {
return types.Route
case resource.ScopedRouteType:
return types.ScopedRoute
case resource.VirtualHostType:
return types.VirtualHost
case resource.ListenerType:
return types.Listener
case resource.SecretType:
Expand All @@ -67,6 +69,8 @@ func GetResponseTypeURL(responseType types.ResponseType) (string, error) {
return resource.RouteType, nil
case types.ScopedRoute:
return resource.ScopedRouteType, nil
case types.VirtualHost:
return resource.VirtualHostType, nil
case types.Listener:
return resource.ListenerType, nil
case types.Secret:
Expand All @@ -78,7 +82,6 @@ func GetResponseTypeURL(responseType types.ResponseType) (string, error) {
default:
return "", fmt.Errorf("couldn't map response type %v to known resource type", responseType)
}

}

// GetResourceName returns the resource name for a valid xDS response type.
Expand All @@ -92,6 +95,8 @@ func GetResourceName(res types.Resource) string {
return v.GetName()
case *route.ScopedRouteConfiguration:
return v.GetName()
case *route.VirtualHost:
return v.GetName()
case *listener.Listener:
return v.GetName()
case *auth.Secret:
Expand Down
25 changes: 20 additions & 5 deletions pkg/cache/v3/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ import (
const (
clusterName = "cluster0"
routeName = "route0"
embeddedRouteName = "embeddedRoute0"
scopedRouteName = "scopedRoute0"
listenerName = "listener0"
scopedListenerName = "scopedListener0"
virtualHostName = "virtualHost0"
runtimeName = "runtime0"
tlsName = "secret0"
rootName = "root0"
Expand All @@ -43,10 +45,12 @@ const (
var (
testEndpoint = resource.MakeEndpoint(clusterName, 8080)
testCluster = resource.MakeCluster(resource.Ads, clusterName)
testRoute = resource.MakeRoute(routeName, clusterName)
testScopedRoute = resource.MakeScopedRoute(scopedRouteName, routeName, []string{"1.2.3.4"})
testRoute = resource.MakeRouteConfig(routeName, clusterName)
testEmbeddedRoute = resource.MakeRouteConfig(embeddedRouteName, clusterName)
testScopedRoute = resource.MakeScopedRouteConfig(scopedRouteName, routeName, []string{"1.2.3.4"})
testVirtualHost = resource.MakeVirtualHost(virtualHostName, clusterName)
testListener = resource.MakeRouteHTTPListener(resource.Ads, listenerName, 80, routeName)
testScopedListener = resource.MakeScopedRouteHTTPListenerForRoute(resource.Ads, scopedListenerName, 80, scopedRouteName)
testScopedListener = resource.MakeScopedRouteHTTPListenerForRoute(resource.Ads, scopedListenerName, 80, embeddedRouteName)
testRuntime = resource.MakeRuntime(runtimeName)
testSecret = resource.MakeSecrets(tlsName, rootName)
testExtensionConfig = resource.MakeExtensionConfig(resource.Ads, extensionConfigName, routeName)
Expand All @@ -57,6 +61,7 @@ func TestValidate(t *testing.T) {
assert.NoError(t, testCluster.Validate())
assert.NoError(t, testRoute.Validate())
assert.NoError(t, testScopedRoute.Validate())
assert.NoError(t, testVirtualHost.Validate())
assert.NoError(t, testListener.Validate())
assert.NoError(t, testScopedListener.Validate())
assert.NoError(t, testRuntime.Validate())
Expand Down Expand Up @@ -91,6 +96,9 @@ func TestGetResourceName(t *testing.T) {
if name := cache.GetResourceName(testScopedRoute); name != scopedRouteName {
t.Errorf("GetResourceName(%v) => got %q, want %q", testScopedRoute, name, scopedRouteName)
}
if name := cache.GetResourceName(testVirtualHost); name != virtualHostName {
t.Errorf("GetResourceName(%v) => got %q, want %q", testVirtualHost, name, virtualHostName)
}
if name := cache.GetResourceName(testListener); name != listenerName {
t.Errorf("GetResourceName(%v) => got %q, want %q", testListener, name, listenerName)
}
Expand Down Expand Up @@ -140,10 +148,18 @@ func TestGetResourceReferences(t *testing.T) {
in: testRoute,
out: map[rsrc.Type]map[string]bool{},
},
{
in: resource.MakeVHDSRouteConfig(resource.Ads, routeName),
out: map[rsrc.Type]map[string]bool{},
},
{
in: testScopedRoute,
out: map[rsrc.Type]map[string]bool{rsrc.RouteType: {routeName: true}},
},
{
in: testVirtualHost,
out: map[rsrc.Type]map[string]bool{},
},
{
in: testEndpoint,
out: map[rsrc.Type]map[string]bool{},
Expand All @@ -160,10 +176,9 @@ func TestGetResourceReferences(t *testing.T) {
}
}
}

func TestGetAllResourceReferencesReturnsExpectedRefs(t *testing.T) {
expected := map[rsrc.Type]map[string]bool{
rsrc.RouteType: {routeName: true, scopedRouteName: true},
rsrc.RouteType: {routeName: true, embeddedRouteName: true},
rsrc.EndpointType: {clusterName: true},
}

Expand Down
24 changes: 15 additions & 9 deletions pkg/cache/v3/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,31 @@ var (
snapshotWithTTL, _ = cache.NewSnapshotWithTTLs(fixture.version, map[rsrc.Type][]types.ResourceWithTTL{
rsrc.EndpointType: {{Resource: testEndpoint, TTL: &ttl}},
rsrc.ClusterType: {{Resource: testCluster}},
rsrc.RouteType: {{Resource: testRoute}},
rsrc.ListenerType: {{Resource: testListener}},
rsrc.RouteType: {{Resource: testRoute}, {Resource: testEmbeddedRoute}},
rsrc.ScopedRouteType: {{Resource: testScopedRoute}},
rsrc.VirtualHostType: {{Resource: testVirtualHost}},
rsrc.ListenerType: {{Resource: testScopedListener}, {Resource: testListener}},
rsrc.RuntimeType: {{Resource: testRuntime}},
rsrc.SecretType: {{Resource: testSecret[0]}},
rsrc.ExtensionConfigType: {{Resource: testExtensionConfig}},
})

names = map[string][]string{
rsrc.EndpointType: {clusterName},
rsrc.ClusterType: nil,
rsrc.RouteType: {routeName},
rsrc.ListenerType: nil,
rsrc.RuntimeType: nil,
rsrc.EndpointType: {clusterName},
rsrc.ClusterType: nil,
rsrc.RouteType: {routeName, embeddedRouteName},
rsrc.ScopedRouteType: nil,
rsrc.VirtualHostType: nil,
rsrc.ListenerType: nil,
rsrc.RuntimeType: nil,
}

testTypes = []string{
rsrc.EndpointType,
rsrc.ClusterType,
rsrc.RouteType,
rsrc.ScopedRouteType,
rsrc.VirtualHostType,
rsrc.ListenerType,
rsrc.RuntimeType,
}
Expand Down Expand Up @@ -431,8 +437,8 @@ func TestSnapshotCreateWatchWithResourcePreviouslyNotRequested(t *testing.T) {
snapshot2, _ := cache.NewSnapshot(fixture.version, map[rsrc.Type][]types.Resource{
rsrc.EndpointType: {testEndpoint, resource.MakeEndpoint(clusterName2, 8080)},
rsrc.ClusterType: {testCluster, resource.MakeCluster(resource.Ads, clusterName2)},
rsrc.RouteType: {testRoute, resource.MakeRoute(routeName2, clusterName2)},
rsrc.ListenerType: {testListener, resource.MakeRouteHTTPListener(resource.Ads, listenerName2, 80, routeName2)},
rsrc.RouteType: {testRoute, resource.MakeRouteConfig(routeName2, clusterName2)},
rsrc.ListenerType: {testScopedListener, resource.MakeRouteHTTPListener(resource.Ads, listenerName2, 80, routeName2)},
rsrc.RuntimeType: {},
rsrc.SecretType: {},
rsrc.ExtensionConfigType: {},
Expand Down
20 changes: 10 additions & 10 deletions pkg/cache/v3/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestListenerWithMissingRoutesIsInconsistent(t *testing.T) {

func TestListenerWithUnidentifiedRouteIsInconsistent(t *testing.T) {
if snap, _ := cache.NewSnapshot(fixture.version, map[rsrc.Type][]types.Resource{
rsrc.RouteType: {resource.MakeRoute("test", clusterName)},
rsrc.RouteType: {resource.MakeRouteConfig("test", clusterName)},
rsrc.ListenerType: {testListener},
}); snap.Consistent() == nil {
t.Errorf("got consistent snapshot %#v", snap)
Expand All @@ -75,7 +75,7 @@ func TestRouteListenerWithRouteIsConsistent(t *testing.T) {
resource.MakeRouteHTTPListener(resource.Xds, "listener1", 80, "testRoute0"),
},
rsrc.RouteType: {
resource.MakeRoute("testRoute0", clusterName),
resource.MakeRouteConfig("testRoute0", clusterName),
},
})

Expand All @@ -90,7 +90,7 @@ func TestScopedRouteListenerWithScopedRouteOnlyIsInconsistent(t *testing.T) {
resource.MakeScopedRouteHTTPListener(resource.Xds, "listener0", 80),
},
rsrc.ScopedRouteType: {
resource.MakeScopedRoute("scopedRoute0", "testRoute0", []string{"1.2.3.4"}),
resource.MakeScopedRouteConfig("scopedRoute0", "testRoute0", []string{"1.2.3.4"}),
},
}); snap.Consistent() == nil {
t.Errorf("got consistent snapshot %#v", snap)
Expand All @@ -103,10 +103,10 @@ func TestScopedRouteListenerWithScopedRouteAndRouteIsConsistent(t *testing.T) {
resource.MakeScopedRouteHTTPListener(resource.Xds, "listener0", 80),
},
rsrc.ScopedRouteType: {
resource.MakeScopedRoute("scopedRoute0", "testRoute0", []string{"1.2.3.4"}),
resource.MakeScopedRouteConfig("scopedRoute0", "testRoute0", []string{"1.2.3.4"}),
},
rsrc.RouteType: {
resource.MakeRoute("testRoute0", clusterName),
resource.MakeRouteConfig("testRoute0", clusterName),
},
})

Expand All @@ -119,7 +119,7 @@ func TestScopedRouteListenerWithInlineScopedRouteAndRouteIsConsistent(t *testing
resource.MakeScopedRouteHTTPListenerForRoute(resource.Xds, "listener0", 80, "testRoute0"),
},
rsrc.RouteType: {
resource.MakeRoute("testRoute0", clusterName),
resource.MakeRouteConfig("testRoute0", clusterName),
},
})

Expand All @@ -133,7 +133,7 @@ func TestScopedRouteListenerWithInlineScopedRouteAndNoRouteIsInconsistent(t *tes
resource.MakeScopedRouteHTTPListenerForRoute(resource.Xds, "listener0", 80, "testRoute0"),
},
rsrc.RouteType: {
resource.MakeRoute("testRoute1", clusterName),
resource.MakeRouteConfig("testRoute1", clusterName),
},
})

Expand All @@ -148,11 +148,11 @@ func TestMultipleListenersWithScopedRouteAndRouteIsConsistent(t *testing.T) {
resource.MakeRouteHTTPListener(resource.Xds, "listener1", 80, "testRoute1"),
},
rsrc.ScopedRouteType: {
resource.MakeScopedRoute("scopedRoute0", "testRoute0", []string{"1.2.3.4"}),
resource.MakeScopedRouteConfig("scopedRoute0", "testRoute0", []string{"1.2.3.4"}),
},
rsrc.RouteType: {
resource.MakeRoute("testRoute0", clusterName),
resource.MakeRoute("testRoute1", clusterName),
resource.MakeRouteConfig("testRoute0", clusterName),
resource.MakeRouteConfig("testRoute1", clusterName),
},
})

Expand Down
1 change: 1 addition & 0 deletions pkg/resource/v3/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
ClusterType = apiTypePrefix + "envoy.config.cluster.v3.Cluster"
RouteType = apiTypePrefix + "envoy.config.route.v3.RouteConfiguration"
ScopedRouteType = apiTypePrefix + "envoy.config.route.v3.ScopedRouteConfiguration"
VirtualHostType = apiTypePrefix + "envoy.config.route.v3.VirtualHost"
ListenerType = apiTypePrefix + "envoy.config.listener.v3.Listener"
SecretType = apiTypePrefix + "envoy.extensions.transport_sockets.tls.v3.Secret"
ExtensionConfigType = apiTypePrefix + "envoy.config.core.v3.TypedExtensionConfig"
Expand Down
24 changes: 19 additions & 5 deletions pkg/server/v3/delta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,38 +159,45 @@ func makeDeltaResponses() map[string][]cache.DeltaResponse {
SystemVersionInfo: "4",
},
},
rsrc.VirtualHostType: {
&cache.RawDeltaResponse{
Resources: []types.Resource{virtualHost},
DeltaRequest: &discovery.DeltaDiscoveryRequest{TypeUrl: rsrc.VirtualHostType},
SystemVersionInfo: "5",
},
},
rsrc.ListenerType: {
&cache.RawDeltaResponse{
Resources: []types.Resource{httpListener, httpScopedListener},
DeltaRequest: &discovery.DeltaDiscoveryRequest{TypeUrl: rsrc.ListenerType},
SystemVersionInfo: "5",
SystemVersionInfo: "6",
},
},
rsrc.SecretType: {
&cache.RawDeltaResponse{
SystemVersionInfo: "6",
SystemVersionInfo: "7",
Resources: []types.Resource{secret},
DeltaRequest: &discovery.DeltaDiscoveryRequest{TypeUrl: rsrc.SecretType},
},
},
rsrc.RuntimeType: {
&cache.RawDeltaResponse{
SystemVersionInfo: "7",
SystemVersionInfo: "8",
Resources: []types.Resource{runtime},
DeltaRequest: &discovery.DeltaDiscoveryRequest{TypeUrl: rsrc.RuntimeType},
},
},
rsrc.ExtensionConfigType: {
&cache.RawDeltaResponse{
SystemVersionInfo: "8",
SystemVersionInfo: "9",
Resources: []types.Resource{extensionConfig},
DeltaRequest: &discovery.DeltaDiscoveryRequest{TypeUrl: rsrc.ExtensionConfigType},
},
},
// Pass-through type (types without explicit handling)
opaqueType: {
&cache.RawDeltaResponse{
SystemVersionInfo: "9",
SystemVersionInfo: "10",
Resources: []types.Resource{opaque},
DeltaRequest: &discovery.DeltaDiscoveryRequest{TypeUrl: opaqueType},
},
Expand All @@ -209,6 +216,8 @@ func process(typ string, resp *mockDeltaStream, s server.Server) error {
err = s.DeltaRoutes(resp)
case rsrc.ScopedRouteType:
err = s.DeltaScopedRoutes(resp)
case rsrc.VirtualHostType:
err = s.DeltaVirtualHosts(resp)
case rsrc.ListenerType:
err = s.DeltaListeners(resp)
case rsrc.SecretType:
Expand Down Expand Up @@ -338,6 +347,10 @@ func TestDeltaAggregatedHandlers(t *testing.T) {
TypeUrl: rsrc.ScopedRouteType,
ResourceNamesSubscribe: []string{scopedRouteName},
},
{
TypeUrl: rsrc.VirtualHostType,
ResourceNamesSubscribe: []string{virtualHostName},
},
{
TypeUrl: rsrc.SecretType,
ResourceNamesSubscribe: []string{secretName},
Expand Down Expand Up @@ -368,6 +381,7 @@ func TestDeltaAggregatedHandlers(t *testing.T) {
rsrc.ClusterType: 1,
rsrc.RouteType: 1,
rsrc.ScopedRouteType: 1,
rsrc.VirtualHostType: 1,
rsrc.ListenerType: 1,
rsrc.SecretType: 1},
config.deltaCounts,
Expand Down
9 changes: 9 additions & 0 deletions pkg/server/v3/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Server interface {
clusterservice.ClusterDiscoveryServiceServer
routeservice.RouteDiscoveryServiceServer
routeservice.ScopedRoutesDiscoveryServiceServer
routeservice.VirtualHostDiscoveryServiceServer
listenerservice.ListenerDiscoveryServiceServer
discoverygrpc.AggregatedDiscoveryServiceServer
secretservice.SecretDiscoveryServiceServer
Expand Down Expand Up @@ -218,6 +219,8 @@ func (s *server) StreamExtensionConfigs(stream extensionconfigservice.ExtensionC
return s.StreamHandler(stream, resource.ExtensionConfigType)
}

// VHDS doesn't support SOTW requests, so no handler for it exists.

// Fetch is the universal fetch method.
func (s *server) Fetch(ctx context.Context, req *discovery.DiscoveryRequest) (*discovery.DiscoveryResponse, error) {
return s.rest.Fetch(ctx, req)
Expand Down Expand Up @@ -287,6 +290,8 @@ func (s *server) FetchExtensionConfigs(ctx context.Context, req *discovery.Disco
return s.Fetch(ctx, req)
}

// VHDS doesn't support REST requests, so no handler exists for this.

func (s *server) DeltaStreamHandler(stream stream.DeltaStream, typeURL string) error {
return s.delta.DeltaStreamHandler(stream, typeURL)
}
Expand Down Expand Up @@ -326,3 +331,7 @@ func (s *server) DeltaRuntime(stream runtimeservice.RuntimeDiscoveryService_Delt
func (s *server) DeltaExtensionConfigs(stream extensionconfigservice.ExtensionConfigDiscoveryService_DeltaExtensionConfigsServer) error {
return s.DeltaStreamHandler(stream, resource.ExtensionConfigType)
}

func (s *server) DeltaVirtualHosts(stream routeservice.VirtualHostDiscoveryService_DeltaVirtualHostsServer) error {
return s.DeltaStreamHandler(stream, resource.VirtualHostType)
}
Loading