From 60066e5154e747e0f96315170a49cfa24ee775e3 Mon Sep 17 00:00:00 2001 From: freddygv Date: Mon, 1 Nov 2021 14:43:44 -0600 Subject: [PATCH] Exclude default partition from GatewayKey string This will behave the way we handle SNI and SPIFFE IDs, where the default partition is excluded. Excluding the default ensures that don't attempt to compare default.dc2 to dc2 in OSS. --- agent/proxycfg/snapshot.go | 5 +++-- agent/proxycfg/state_test.go | 6 +++--- agent/proxycfg/testing.go | 12 ++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/agent/proxycfg/snapshot.go b/agent/proxycfg/snapshot.go index acc737c841..8e9b4fee34 100644 --- a/agent/proxycfg/snapshot.go +++ b/agent/proxycfg/snapshot.go @@ -8,6 +8,7 @@ import ( "github.com/mitchellh/copystructure" + "github.com/hashicorp/consul/acl" "github.com/hashicorp/consul/agent/connect" "github.com/hashicorp/consul/agent/structs" ) @@ -61,7 +62,7 @@ type GatewayKey struct { func (k GatewayKey) String() string { resp := k.Datacenter - if k.Partition != "" { + if !structs.IsDefaultPartition(k.Partition) { resp = k.Partition + "." + resp } return resp @@ -79,7 +80,7 @@ func gatewayKeyFromString(s string) GatewayKey { split := strings.SplitN(s, ".", 2) if len(split) == 1 { - return GatewayKey{Datacenter: split[0]} + return GatewayKey{Datacenter: split[0], Partition: acl.DefaultPartitionName} } return GatewayKey{Partition: split[0], Datacenter: split[1]} } diff --git a/agent/proxycfg/state_test.go b/agent/proxycfg/state_test.go index 1378ac0a53..b4d1fc202f 100644 --- a/agent/proxycfg/state_test.go +++ b/agent/proxycfg/state_test.go @@ -649,8 +649,8 @@ func TestState_WatchesAndUpdates(t *testing.T) { "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:default.dc2:api-failover-remote?dc=dc2": genVerifyGatewayWatch("dc2"), - "mesh-gateway:default.dc1:api-failover-local?dc=dc2": genVerifyGatewayWatch("dc1"), + "mesh-gateway:dc2:api-failover-remote?dc=dc2": genVerifyGatewayWatch("dc2"), + "mesh-gateway:dc1:api-failover-local?dc=dc2": 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:default.dc1:api-dc2"] = genVerifyGatewayWatch("dc1") + stage1.requiredWatches["mesh-gateway:dc1:api-dc2"] = genVerifyGatewayWatch("dc1") } return testCase{ diff --git a/agent/proxycfg/testing.go b/agent/proxycfg/testing.go index 870d8e7a1d..33444598b4 100644 --- a/agent/proxycfg/testing.go +++ b/agent/proxycfg/testing.go @@ -1432,7 +1432,7 @@ func setupTestVariationConfigEntriesAndSnapshot( TestUpstreamNodesDC2(t) snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{ "db": { - "default.dc2": TestGatewayNodesDC2(t), + "dc2": TestGatewayNodesDC2(t), }, } case "failover-through-double-remote-gateway-triggered": @@ -1445,8 +1445,8 @@ func setupTestVariationConfigEntriesAndSnapshot( snap.WatchedUpstreamEndpoints["db"]["db.default.default.dc3"] = TestUpstreamNodesDC2(t) snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{ "db": { - "default.dc2": TestGatewayNodesDC2(t), - "default.dc3": TestGatewayNodesDC3(t), + "dc2": TestGatewayNodesDC2(t), + "dc3": TestGatewayNodesDC3(t), }, } case "failover-through-local-gateway-triggered": @@ -1458,7 +1458,7 @@ func setupTestVariationConfigEntriesAndSnapshot( TestUpstreamNodesDC2(t) snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{ "db": { - "default.dc1": TestGatewayNodesDC1(t), + "dc1": TestGatewayNodesDC1(t), }, } case "failover-through-double-local-gateway-triggered": @@ -1471,7 +1471,7 @@ func setupTestVariationConfigEntriesAndSnapshot( snap.WatchedUpstreamEndpoints["db"]["db.default.default.dc3"] = TestUpstreamNodesDC2(t) snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{ "db": { - "default.dc1": TestGatewayNodesDC1(t), + "dc1": TestGatewayNodesDC1(t), }, } case "splitter-with-resolver-redirect-multidc": @@ -1547,7 +1547,7 @@ func testConfigSnapshotMeshGateway(t testing.T, populateServices bool, useFedera }, WatchedServicesSet: true, WatchedGateways: map[string]context.CancelFunc{ - "default.dc2": nil, + "dc2": nil, }, ServiceGroups: map[structs.ServiceName]structs.CheckServiceNodes{ structs.NewServiceName("foo", nil): TestGatewayServiceGroupFooDC1(t),