mirror of https://github.com/status-im/consul.git
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.
This commit is contained in:
parent
e3666b0bc4
commit
60066e5154
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/mitchellh/copystructure"
|
"github.com/mitchellh/copystructure"
|
||||||
|
|
||||||
|
"github.com/hashicorp/consul/acl"
|
||||||
"github.com/hashicorp/consul/agent/connect"
|
"github.com/hashicorp/consul/agent/connect"
|
||||||
"github.com/hashicorp/consul/agent/structs"
|
"github.com/hashicorp/consul/agent/structs"
|
||||||
)
|
)
|
||||||
|
@ -61,7 +62,7 @@ type GatewayKey struct {
|
||||||
|
|
||||||
func (k GatewayKey) String() string {
|
func (k GatewayKey) String() string {
|
||||||
resp := k.Datacenter
|
resp := k.Datacenter
|
||||||
if k.Partition != "" {
|
if !structs.IsDefaultPartition(k.Partition) {
|
||||||
resp = k.Partition + "." + resp
|
resp = k.Partition + "." + resp
|
||||||
}
|
}
|
||||||
return resp
|
return resp
|
||||||
|
@ -79,7 +80,7 @@ func gatewayKeyFromString(s string) GatewayKey {
|
||||||
split := strings.SplitN(s, ".", 2)
|
split := strings.SplitN(s, ".", 2)
|
||||||
|
|
||||||
if len(split) == 1 {
|
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]}
|
return GatewayKey{Partition: split[0], Datacenter: split[1]}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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-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-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),
|
"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:dc2:api-failover-remote?dc=dc2": genVerifyGatewayWatch("dc2"),
|
||||||
"mesh-gateway:default.dc1:api-failover-local?dc=dc2": genVerifyGatewayWatch("dc1"),
|
"mesh-gateway:dc1:api-failover-local?dc=dc2": genVerifyGatewayWatch("dc1"),
|
||||||
},
|
},
|
||||||
verifySnapshot: func(t testing.TB, snap *ConfigSnapshot) {
|
verifySnapshot: func(t testing.TB, snap *ConfigSnapshot) {
|
||||||
require.True(t, snap.Valid())
|
require.True(t, snap.Valid())
|
||||||
|
@ -673,7 +673,7 @@ func TestState_WatchesAndUpdates(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if meshGatewayProxyConfigValue == structs.MeshGatewayModeLocal {
|
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{
|
return testCase{
|
||||||
|
|
|
@ -1432,7 +1432,7 @@ func setupTestVariationConfigEntriesAndSnapshot(
|
||||||
TestUpstreamNodesDC2(t)
|
TestUpstreamNodesDC2(t)
|
||||||
snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{
|
snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{
|
||||||
"db": {
|
"db": {
|
||||||
"default.dc2": TestGatewayNodesDC2(t),
|
"dc2": TestGatewayNodesDC2(t),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
case "failover-through-double-remote-gateway-triggered":
|
case "failover-through-double-remote-gateway-triggered":
|
||||||
|
@ -1445,8 +1445,8 @@ func setupTestVariationConfigEntriesAndSnapshot(
|
||||||
snap.WatchedUpstreamEndpoints["db"]["db.default.default.dc3"] = TestUpstreamNodesDC2(t)
|
snap.WatchedUpstreamEndpoints["db"]["db.default.default.dc3"] = TestUpstreamNodesDC2(t)
|
||||||
snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{
|
snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{
|
||||||
"db": {
|
"db": {
|
||||||
"default.dc2": TestGatewayNodesDC2(t),
|
"dc2": TestGatewayNodesDC2(t),
|
||||||
"default.dc3": TestGatewayNodesDC3(t),
|
"dc3": TestGatewayNodesDC3(t),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
case "failover-through-local-gateway-triggered":
|
case "failover-through-local-gateway-triggered":
|
||||||
|
@ -1458,7 +1458,7 @@ func setupTestVariationConfigEntriesAndSnapshot(
|
||||||
TestUpstreamNodesDC2(t)
|
TestUpstreamNodesDC2(t)
|
||||||
snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{
|
snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{
|
||||||
"db": {
|
"db": {
|
||||||
"default.dc1": TestGatewayNodesDC1(t),
|
"dc1": TestGatewayNodesDC1(t),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
case "failover-through-double-local-gateway-triggered":
|
case "failover-through-double-local-gateway-triggered":
|
||||||
|
@ -1471,7 +1471,7 @@ func setupTestVariationConfigEntriesAndSnapshot(
|
||||||
snap.WatchedUpstreamEndpoints["db"]["db.default.default.dc3"] = TestUpstreamNodesDC2(t)
|
snap.WatchedUpstreamEndpoints["db"]["db.default.default.dc3"] = TestUpstreamNodesDC2(t)
|
||||||
snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{
|
snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{
|
||||||
"db": {
|
"db": {
|
||||||
"default.dc1": TestGatewayNodesDC1(t),
|
"dc1": TestGatewayNodesDC1(t),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
case "splitter-with-resolver-redirect-multidc":
|
case "splitter-with-resolver-redirect-multidc":
|
||||||
|
@ -1547,7 +1547,7 @@ func testConfigSnapshotMeshGateway(t testing.T, populateServices bool, useFedera
|
||||||
},
|
},
|
||||||
WatchedServicesSet: true,
|
WatchedServicesSet: true,
|
||||||
WatchedGateways: map[string]context.CancelFunc{
|
WatchedGateways: map[string]context.CancelFunc{
|
||||||
"default.dc2": nil,
|
"dc2": nil,
|
||||||
},
|
},
|
||||||
ServiceGroups: map[structs.ServiceName]structs.CheckServiceNodes{
|
ServiceGroups: map[structs.ServiceName]structs.CheckServiceNodes{
|
||||||
structs.NewServiceName("foo", nil): TestGatewayServiceGroupFooDC1(t),
|
structs.NewServiceName("foo", nil): TestGatewayServiceGroupFooDC1(t),
|
||||||
|
|
Loading…
Reference in New Issue