From d26b4860fd08cf254c08efffff8f5a30853ce387 Mon Sep 17 00:00:00 2001 From: freddygv Date: Mon, 13 Dec 2021 17:51:13 -0700 Subject: [PATCH] Account for new upstreams constraint in tests --- agent/proxycfg/state_test.go | 25 +++++++++++++------------ agent/xds/clusters_test.go | 17 ++++++++++++----- agent/xds/listeners_test.go | 33 ++++++++++++++++++++++----------- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/agent/proxycfg/state_test.go b/agent/proxycfg/state_test.go index 149de6e090..77d8fee39b 100644 --- a/agent/proxycfg/state_test.go +++ b/agent/proxycfg/state_test.go @@ -566,7 +566,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { Err: nil, }, { - CorrelationID: "discovery-chain:api", + CorrelationID: fmt.Sprintf("discovery-chain:%s", api.String()), Result: &structs.DiscoveryChainResponse{ Chain: discoverychain.TestCompileConfigEntries(t, "api", "default", "default", "dc1", "trustdomain.consul", func(req *discoverychain.CompileRequest) { @@ -576,7 +576,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { Err: nil, }, { - CorrelationID: "discovery-chain:api-failover-remote?dc=dc2", + CorrelationID: fmt.Sprintf("discovery-chain:%s-failover-remote?dc=dc2", api.String()), Result: &structs.DiscoveryChainResponse{ Chain: discoverychain.TestCompileConfigEntries(t, "api-failover-remote", "default", "default", "dc2", "trustdomain.consul", func(req *discoverychain.CompileRequest) { @@ -586,7 +586,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { Err: nil, }, { - CorrelationID: "discovery-chain:api-failover-local?dc=dc2", + CorrelationID: fmt.Sprintf("discovery-chain:%s-failover-local?dc=dc2", api.String()), Result: &structs.DiscoveryChainResponse{ Chain: discoverychain.TestCompileConfigEntries(t, "api-failover-local", "default", "default", "dc2", "trustdomain.consul", func(req *discoverychain.CompileRequest) { @@ -596,7 +596,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { Err: nil, }, { - CorrelationID: "discovery-chain:api-failover-direct?dc=dc2", + CorrelationID: fmt.Sprintf("discovery-chain:%s-failover-direct?dc=dc2", api.String()), Result: &structs.DiscoveryChainResponse{ Chain: discoverychain.TestCompileConfigEntries(t, "api-failover-direct", "default", "default", "dc2", "trustdomain.consul", func(req *discoverychain.CompileRequest) { @@ -606,7 +606,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { Err: nil, }, { - CorrelationID: "discovery-chain:api-dc2", + CorrelationID: fmt.Sprintf("discovery-chain:%s-dc2", api.String()), Result: &structs.DiscoveryChainResponse{ Chain: discoverychain.TestCompileConfigEntries(t, "api-dc2", "default", "default", "dc1", "trustdomain.consul", func(req *discoverychain.CompileRequest) { @@ -645,12 +645,12 @@ func TestState_WatchesAndUpdates(t *testing.T) { stage1 := verificationStage{ requiredWatches: map[string]verifyWatchRequest{ - "upstream-target:api.default.default.dc1:api": genVerifyServiceWatch("api", "", "dc1", true), - "upstream-target:api-failover-remote.default.default.dc2:api-failover-remote?dc=dc2": genVerifyServiceWatch("api-failover-remote", "", "dc2", true), - "upstream-target:api-failover-local.default.default.dc2:api-failover-local?dc=dc2": genVerifyServiceWatch("api-failover-local", "", "dc2", true), - "upstream-target:api-failover-direct.default.default.dc2:api-failover-direct?dc=dc2": genVerifyServiceWatch("api-failover-direct", "", "dc2", true), - "mesh-gateway:dc2:api-failover-remote?dc=dc2": genVerifyGatewayWatch("dc2"), - "mesh-gateway:dc1:api-failover-local?dc=dc2": genVerifyGatewayWatch("dc1"), + fmt.Sprintf("upstream-target:api.default.default.dc1:%s", api.String()): genVerifyServiceWatch("api", "", "dc1", true), + fmt.Sprintf("upstream-target:api-failover-remote.default.default.dc2:%s-failover-remote?dc=dc2", api.String()): genVerifyServiceWatch("api-failover-remote", "", "dc2", true), + fmt.Sprintf("upstream-target:api-failover-local.default.default.dc2:%s-failover-local?dc=dc2", api.String()): genVerifyServiceWatch("api-failover-local", "", "dc2", true), + fmt.Sprintf("upstream-target:api-failover-direct.default.default.dc2:%s-failover-direct?dc=dc2", api.String()): genVerifyServiceWatch("api-failover-direct", "", "dc2", true), + fmt.Sprintf("mesh-gateway:dc2:%s-failover-remote?dc=dc2", api.String()): genVerifyGatewayWatch("dc2"), + fmt.Sprintf("mesh-gateway:dc1:%s-failover-local?dc=dc2", api.String()): genVerifyGatewayWatch("dc1"), }, verifySnapshot: func(t testing.TB, snap *ConfigSnapshot) { require.True(t, snap.Valid()) @@ -673,7 +673,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { } if meshGatewayProxyConfigValue == structs.MeshGatewayModeLocal { - stage1.requiredWatches["mesh-gateway:dc1:api-dc2"] = genVerifyGatewayWatch("dc1") + stage1.requiredWatches[fmt.Sprintf("mesh-gateway:dc1:%s-dc2", api.String())] = genVerifyGatewayWatch("dc1") } return testCase{ @@ -2093,6 +2093,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { DestinationName: db.Name, DestinationNamespace: db.NamespaceOrDefault(), Datacenter: "dc2", + LocalBindPort: 8080, MeshGateway: structs.MeshGatewayConfig{Mode: structs.MeshGatewayModeLocal}, }, }, diff --git a/agent/xds/clusters_test.go b/agent/xds/clusters_test.go index c71b20170f..c6cc33a4f6 100644 --- a/agent/xds/clusters_test.go +++ b/agent/xds/clusters_test.go @@ -665,10 +665,17 @@ func TestClustersFromSnapshot(t *testing.T) { create: proxycfg.TestConfigSnapshot, setup: func(snap *proxycfg.ConfigSnapshot) { snap.Proxy.Mode = structs.ProxyModeTransparent + kafka := structs.NewServiceName("kafka", nil) + mongo := structs.NewServiceName("mongo", nil) + + snap.ConnectProxy.IntentionUpstreams = map[string]struct{}{ + kafka.String(): {}, + mongo.String(): {}, + } // We add a passthrough cluster for each upstream service name snap.ConnectProxy.PassthroughUpstreams = map[string]proxycfg.ServicePassthroughAddrs{ - "default/kafka": { + kafka.String(): { SNI: "kafka.default.dc1.internal.e5b08d03-bfc3-c870-1833-baddb116e648.consul", SpiffeID: connect.SpiffeIDService{ Host: "e5b08d03-bfc3-c870-1833-baddb116e648.consul", @@ -680,7 +687,7 @@ func TestClustersFromSnapshot(t *testing.T) { "9.9.9.9": {}, }, }, - "default/mongo": { + mongo.String(): { SNI: "mongo.default.dc1.internal.e5b08d03-bfc3-c870-1833-baddb116e648.consul", SpiffeID: connect.SpiffeIDService{ Host: "e5b08d03-bfc3-c870-1833-baddb116e648.consul", @@ -696,9 +703,9 @@ func TestClustersFromSnapshot(t *testing.T) { } // There should still be a cluster for non-passthrough requests - snap.ConnectProxy.DiscoveryChain["mongo"] = discoverychain.TestCompileConfigEntries(t, "mongo", "default", "default", "dc1", connect.TestClusterID+".consul", nil) - snap.ConnectProxy.WatchedUpstreamEndpoints["mongo"] = map[string]structs.CheckServiceNodes{ - "mongo.default.dc1": { + snap.ConnectProxy.DiscoveryChain[mongo.String()] = discoverychain.TestCompileConfigEntries(t, "mongo", "default", "default", "dc1", connect.TestClusterID+".consul", nil) + snap.ConnectProxy.WatchedUpstreamEndpoints[mongo.String()] = map[string]structs.CheckServiceNodes{ + "mongo.default.default.dc1": { structs.CheckServiceNode{ Node: &structs.Node{ Datacenter: "dc1", diff --git a/agent/xds/listeners_test.go b/agent/xds/listeners_test.go index acf197961b..cbfe6c7285 100644 --- a/agent/xds/listeners_test.go +++ b/agent/xds/listeners_test.go @@ -850,8 +850,13 @@ func TestListenersFromSnapshot(t *testing.T) { snap.ConnectProxy.MeshConfigSet = true // DiscoveryChain without an UpstreamConfig should yield a filter chain when in transparent proxy mode - snap.ConnectProxy.DiscoveryChain["google"] = discoverychain.TestCompileConfigEntries(t, "google", "default", "default", "dc1", connect.TestClusterID+".consul", nil) - snap.ConnectProxy.WatchedUpstreamEndpoints["google"] = map[string]structs.CheckServiceNodes{ + google := structs.NewServiceName("google", nil) + snap.ConnectProxy.IntentionUpstreams = map[string]struct{}{ + google.String(): {}, + } + snap.ConnectProxy.DiscoveryChain[google.String()] = discoverychain.TestCompileConfigEntries(t, "google", "default", "default", "dc1", connect.TestClusterID+".consul", nil) + + snap.ConnectProxy.WatchedUpstreamEndpoints[google.String()] = map[string]structs.CheckServiceNodes{ "google.default.default.dc1": { structs.CheckServiceNode{ Node: &structs.Node{ @@ -905,8 +910,12 @@ func TestListenersFromSnapshot(t *testing.T) { } // DiscoveryChain without an UpstreamConfig should yield a filter chain when in transparent proxy mode - snap.ConnectProxy.DiscoveryChain["google"] = discoverychain.TestCompileConfigEntries(t, "google", "default", "default", "dc1", connect.TestClusterID+".consul", nil) - snap.ConnectProxy.WatchedUpstreamEndpoints["google"] = map[string]structs.CheckServiceNodes{ + google := structs.NewServiceName("google", nil) + snap.ConnectProxy.IntentionUpstreams = map[string]struct{}{ + google.String(): {}, + } + snap.ConnectProxy.DiscoveryChain[google.String()] = discoverychain.TestCompileConfigEntries(t, "google", "default", "default", "dc1", connect.TestClusterID+".consul", nil) + snap.ConnectProxy.WatchedUpstreamEndpoints[google.String()] = map[string]structs.CheckServiceNodes{ "google.default.default.dc1": { structs.CheckServiceNode{ Node: &structs.Node{ @@ -934,13 +943,15 @@ func TestListenersFromSnapshot(t *testing.T) { create: proxycfg.TestConfigSnapshot, setup: func(snap *proxycfg.ConfigSnapshot) { snap.Proxy.Mode = structs.ProxyModeTransparent + kafka := structs.NewServiceName("kafka", nil) + mongo := structs.NewServiceName("mongo", nil) - snap.ConnectProxy.DiscoveryChain["mongo"] = discoverychain.TestCompileConfigEntries(t, "mongo", "default", "default", "dc1", connect.TestClusterID+".consul", nil) - - snap.ConnectProxy.DiscoveryChain["kafka"] = discoverychain.TestCompileConfigEntries(t, "kafka", "default", "default", "dc1", connect.TestClusterID+".consul", nil) - - kafka := structs.NewServiceName("kafka", structs.DefaultEnterpriseMetaInDefaultPartition()) - mongo := structs.NewServiceName("mongo", structs.DefaultEnterpriseMetaInDefaultPartition()) + snap.ConnectProxy.IntentionUpstreams = map[string]struct{}{ + kafka.String(): {}, + mongo.String(): {}, + } + snap.ConnectProxy.DiscoveryChain[mongo.String()] = discoverychain.TestCompileConfigEntries(t, "mongo", "default", "default", "dc1", connect.TestClusterID+".consul", nil) + snap.ConnectProxy.DiscoveryChain[kafka.String()] = discoverychain.TestCompileConfigEntries(t, "kafka", "default", "default", "dc1", connect.TestClusterID+".consul", nil) // We add a filter chains for each passthrough service name. // The filter chain will route to a cluster with the same SNI name. @@ -961,7 +972,7 @@ func TestListenersFromSnapshot(t *testing.T) { } // There should still be a filter chain for mongo's virtual address - snap.ConnectProxy.WatchedUpstreamEndpoints["mongo"] = map[string]structs.CheckServiceNodes{ + snap.ConnectProxy.WatchedUpstreamEndpoints[mongo.String()] = map[string]structs.CheckServiceNodes{ "mongo.default.default.dc1": { structs.CheckServiceNode{ Node: &structs.Node{