mirror of https://github.com/status-im/consul.git
Remove useInDatacenter from disco chain requests
useInDatacenter was used to determine whether the mesh gateway mode of the upstream should be returned in the discovery chain target. This commit makes it so that the mesh gateway mode is returned every time, and it is up to the caller to decide whether mesh gateways should be watched or used.
This commit is contained in:
parent
ef559dfdd4
commit
eacb73cb78
|
@ -57,7 +57,6 @@ func (c *DiscoveryChain) Get(args *structs.DiscoveryChainRequest, reply *structs
|
||||||
EvaluateInNamespace: entMeta.NamespaceOrDefault(),
|
EvaluateInNamespace: entMeta.NamespaceOrDefault(),
|
||||||
EvaluateInPartition: entMeta.PartitionOrDefault(),
|
EvaluateInPartition: entMeta.PartitionOrDefault(),
|
||||||
EvaluateInDatacenter: evalDC,
|
EvaluateInDatacenter: evalDC,
|
||||||
UseInDatacenter: c.srv.config.Datacenter,
|
|
||||||
OverrideMeshGateway: args.OverrideMeshGateway,
|
OverrideMeshGateway: args.OverrideMeshGateway,
|
||||||
OverrideProtocol: args.OverrideProtocol,
|
OverrideProtocol: args.OverrideProtocol,
|
||||||
OverrideConnectTimeout: args.OverrideConnectTimeout,
|
OverrideConnectTimeout: args.OverrideConnectTimeout,
|
||||||
|
|
|
@ -18,7 +18,6 @@ type CompileRequest struct {
|
||||||
EvaluateInPartition string
|
EvaluateInPartition string
|
||||||
EvaluateInDatacenter string
|
EvaluateInDatacenter string
|
||||||
EvaluateInTrustDomain string
|
EvaluateInTrustDomain string
|
||||||
UseInDatacenter string // where the results will be used from
|
|
||||||
|
|
||||||
// OverrideMeshGateway allows for the setting to be overridden for any
|
// OverrideMeshGateway allows for the setting to be overridden for any
|
||||||
// resolver in the compiled chain.
|
// resolver in the compiled chain.
|
||||||
|
@ -62,7 +61,6 @@ func Compile(req CompileRequest) (*structs.CompiledDiscoveryChain, error) {
|
||||||
evaluateInPartition = req.EvaluateInPartition
|
evaluateInPartition = req.EvaluateInPartition
|
||||||
evaluateInDatacenter = req.EvaluateInDatacenter
|
evaluateInDatacenter = req.EvaluateInDatacenter
|
||||||
evaluateInTrustDomain = req.EvaluateInTrustDomain
|
evaluateInTrustDomain = req.EvaluateInTrustDomain
|
||||||
useInDatacenter = req.UseInDatacenter
|
|
||||||
entries = req.Entries
|
entries = req.Entries
|
||||||
)
|
)
|
||||||
if serviceName == "" {
|
if serviceName == "" {
|
||||||
|
@ -80,9 +78,6 @@ func Compile(req CompileRequest) (*structs.CompiledDiscoveryChain, error) {
|
||||||
if evaluateInTrustDomain == "" {
|
if evaluateInTrustDomain == "" {
|
||||||
return nil, fmt.Errorf("evaluateInTrustDomain is required")
|
return nil, fmt.Errorf("evaluateInTrustDomain is required")
|
||||||
}
|
}
|
||||||
if useInDatacenter == "" {
|
|
||||||
return nil, fmt.Errorf("useInDatacenter is required")
|
|
||||||
}
|
|
||||||
if entries == nil {
|
if entries == nil {
|
||||||
return nil, fmt.Errorf("entries is required")
|
return nil, fmt.Errorf("entries is required")
|
||||||
}
|
}
|
||||||
|
@ -93,7 +88,6 @@ func Compile(req CompileRequest) (*structs.CompiledDiscoveryChain, error) {
|
||||||
evaluateInNamespace: evaluateInNamespace,
|
evaluateInNamespace: evaluateInNamespace,
|
||||||
evaluateInDatacenter: evaluateInDatacenter,
|
evaluateInDatacenter: evaluateInDatacenter,
|
||||||
evaluateInTrustDomain: evaluateInTrustDomain,
|
evaluateInTrustDomain: evaluateInTrustDomain,
|
||||||
useInDatacenter: useInDatacenter,
|
|
||||||
overrideMeshGateway: req.OverrideMeshGateway,
|
overrideMeshGateway: req.OverrideMeshGateway,
|
||||||
overrideProtocol: req.OverrideProtocol,
|
overrideProtocol: req.OverrideProtocol,
|
||||||
overrideConnectTimeout: req.OverrideConnectTimeout,
|
overrideConnectTimeout: req.OverrideConnectTimeout,
|
||||||
|
@ -130,7 +124,6 @@ type compiler struct {
|
||||||
evaluateInPartition string
|
evaluateInPartition string
|
||||||
evaluateInDatacenter string
|
evaluateInDatacenter string
|
||||||
evaluateInTrustDomain string
|
evaluateInTrustDomain string
|
||||||
useInDatacenter string
|
|
||||||
overrideMeshGateway structs.MeshGatewayConfig
|
overrideMeshGateway structs.MeshGatewayConfig
|
||||||
overrideProtocol string
|
overrideProtocol string
|
||||||
overrideConnectTimeout time.Duration
|
overrideConnectTimeout time.Duration
|
||||||
|
@ -936,10 +929,10 @@ RESOLVE_AGAIN:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO (mesh-gateway)- maybe allow using a gateway within a datacenter at some point
|
// TODO(partitions): Document this change in behavior. Discovery chain targets will now return a mesh gateway
|
||||||
if target.Datacenter == c.useInDatacenter {
|
// mode as long as they are not external. Regardless of the datacenter/partition where
|
||||||
target.MeshGateway.Mode = structs.MeshGatewayModeDefault
|
// the chain will be used.
|
||||||
} else if target.External {
|
if target.External {
|
||||||
// Bypass mesh gateways if it is an external service.
|
// Bypass mesh gateways if it is an external service.
|
||||||
target.MeshGateway.Mode = structs.MeshGatewayModeDefault
|
target.MeshGateway.Mode = structs.MeshGatewayModeDefault
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -105,7 +105,6 @@ func TestCompile(t *testing.T) {
|
||||||
EvaluateInPartition: "default",
|
EvaluateInPartition: "default",
|
||||||
EvaluateInDatacenter: "dc1",
|
EvaluateInDatacenter: "dc1",
|
||||||
EvaluateInTrustDomain: "trustdomain.consul",
|
EvaluateInTrustDomain: "trustdomain.consul",
|
||||||
UseInDatacenter: "dc1",
|
|
||||||
Entries: tc.entries,
|
Entries: tc.entries,
|
||||||
}
|
}
|
||||||
if tc.setup != nil {
|
if tc.setup != nil {
|
||||||
|
@ -1338,7 +1337,11 @@ func testcase_DatacenterFailover_WithMeshGateways() compileTestCase {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Targets: map[string]*structs.DiscoveryTarget{
|
Targets: map[string]*structs.DiscoveryTarget{
|
||||||
"main.default.default.dc1": newTarget("main", "", "default", "default", "dc1", nil),
|
"main.default.default.dc1": newTarget("main", "", "default", "default", "dc1", func(t *structs.DiscoveryTarget) {
|
||||||
|
t.MeshGateway = structs.MeshGatewayConfig{
|
||||||
|
Mode: structs.MeshGatewayModeRemote,
|
||||||
|
}
|
||||||
|
}),
|
||||||
"main.default.default.dc2": newTarget("main", "", "default", "default", "dc2", func(t *structs.DiscoveryTarget) {
|
"main.default.default.dc2": newTarget("main", "", "default", "default", "dc2", func(t *structs.DiscoveryTarget) {
|
||||||
t.MeshGateway = structs.MeshGatewayConfig{
|
t.MeshGateway = structs.MeshGatewayConfig{
|
||||||
Mode: structs.MeshGatewayModeRemote,
|
Mode: structs.MeshGatewayModeRemote,
|
||||||
|
@ -1469,7 +1472,11 @@ func testcase_DefaultResolver_WithProxyDefaults() compileTestCase {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Targets: map[string]*structs.DiscoveryTarget{
|
Targets: map[string]*structs.DiscoveryTarget{
|
||||||
"main.default.default.dc1": newTarget("main", "", "default", "default", "dc1", nil),
|
"main.default.default.dc1": newTarget("main", "", "default", "default", "dc1", func(t *structs.DiscoveryTarget) {
|
||||||
|
t.MeshGateway = structs.MeshGatewayConfig{
|
||||||
|
Mode: structs.MeshGatewayModeRemote,
|
||||||
|
}
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return compileTestCase{entries: entries, expect: expect, expectIsDefault: true}
|
return compileTestCase{entries: entries, expect: expect, expectIsDefault: true}
|
||||||
|
|
|
@ -12,7 +12,7 @@ func TestCompileConfigEntries(t testing.T,
|
||||||
evaluateInPartition string,
|
evaluateInPartition string,
|
||||||
evaluateInDatacenter string,
|
evaluateInDatacenter string,
|
||||||
evaluateInTrustDomain string,
|
evaluateInTrustDomain string,
|
||||||
useInDatacenter string,
|
_ string,
|
||||||
setup func(req *CompileRequest), entries ...structs.ConfigEntry) *structs.CompiledDiscoveryChain {
|
setup func(req *CompileRequest), entries ...structs.ConfigEntry) *structs.CompiledDiscoveryChain {
|
||||||
set := structs.NewDiscoveryChainConfigEntries()
|
set := structs.NewDiscoveryChainConfigEntries()
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ func TestCompileConfigEntries(t testing.T,
|
||||||
EvaluateInPartition: evaluateInPartition,
|
EvaluateInPartition: evaluateInPartition,
|
||||||
EvaluateInDatacenter: evaluateInDatacenter,
|
EvaluateInDatacenter: evaluateInDatacenter,
|
||||||
EvaluateInTrustDomain: evaluateInTrustDomain,
|
EvaluateInTrustDomain: evaluateInTrustDomain,
|
||||||
UseInDatacenter: useInDatacenter,
|
|
||||||
Entries: set,
|
Entries: set,
|
||||||
}
|
}
|
||||||
if setup != nil {
|
if setup != nil {
|
||||||
|
|
|
@ -394,7 +394,6 @@ func (s *Store) discoveryChainTargetsTxn(tx ReadTxn, ws memdb.WatchSet, dc, serv
|
||||||
EvaluateInNamespace: source.NamespaceOrDefault(),
|
EvaluateInNamespace: source.NamespaceOrDefault(),
|
||||||
EvaluateInPartition: source.PartitionOrDefault(),
|
EvaluateInPartition: source.PartitionOrDefault(),
|
||||||
EvaluateInDatacenter: dc,
|
EvaluateInDatacenter: dc,
|
||||||
UseInDatacenter: dc,
|
|
||||||
}
|
}
|
||||||
idx, chain, err := s.serviceDiscoveryChainTxn(tx, ws, source.Name, entMeta, req)
|
idx, chain, err := s.serviceDiscoveryChainTxn(tx, ws, source.Name, entMeta, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -452,7 +451,6 @@ func (s *Store) discoveryChainSourcesTxn(tx ReadTxn, ws memdb.WatchSet, dc strin
|
||||||
EvaluateInNamespace: sn.NamespaceOrDefault(),
|
EvaluateInNamespace: sn.NamespaceOrDefault(),
|
||||||
EvaluateInPartition: sn.PartitionOrDefault(),
|
EvaluateInPartition: sn.PartitionOrDefault(),
|
||||||
EvaluateInDatacenter: dc,
|
EvaluateInDatacenter: dc,
|
||||||
UseInDatacenter: dc,
|
|
||||||
}
|
}
|
||||||
idx, chain, err := s.serviceDiscoveryChainTxn(tx, ws, sn.Name, &sn.EnterpriseMeta, req)
|
idx, chain, err := s.serviceDiscoveryChainTxn(tx, ws, sn.Name, &sn.EnterpriseMeta, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -723,7 +721,6 @@ func testCompileDiscoveryChain(
|
||||||
EvaluateInPartition: entMeta.PartitionOrDefault(),
|
EvaluateInPartition: entMeta.PartitionOrDefault(),
|
||||||
EvaluateInDatacenter: "dc1",
|
EvaluateInDatacenter: "dc1",
|
||||||
EvaluateInTrustDomain: "b6fc9da3-03d4-4b5a-9134-c045e9b20152.consul",
|
EvaluateInTrustDomain: "b6fc9da3-03d4-4b5a-9134-c045e9b20152.consul",
|
||||||
UseInDatacenter: "dc1",
|
|
||||||
Entries: speculativeEntries,
|
Entries: speculativeEntries,
|
||||||
}
|
}
|
||||||
chain, err := discoverychain.Compile(req)
|
chain, err := discoverychain.Compile(req)
|
||||||
|
@ -1208,7 +1205,6 @@ func protocolForService(
|
||||||
EvaluateInDatacenter: "dc1",
|
EvaluateInDatacenter: "dc1",
|
||||||
// Use a dummy trust domain since that won't affect the protocol here.
|
// Use a dummy trust domain since that won't affect the protocol here.
|
||||||
EvaluateInTrustDomain: "b6fc9da3-03d4-4b5a-9134-c045e9b20152.consul",
|
EvaluateInTrustDomain: "b6fc9da3-03d4-4b5a-9134-c045e9b20152.consul",
|
||||||
UseInDatacenter: "dc1",
|
|
||||||
Entries: entries,
|
Entries: entries,
|
||||||
}
|
}
|
||||||
chain, err := discoverychain.Compile(req)
|
chain, err := discoverychain.Compile(req)
|
||||||
|
|
|
@ -264,6 +264,11 @@ func TestDiscoveryChainRead(t *testing.T) {
|
||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
expectTarget_DC1 := newTarget("web", "", "default", "default", "dc1")
|
||||||
|
expectTarget_DC1.MeshGateway = structs.MeshGatewayConfig{
|
||||||
|
Mode: structs.MeshGatewayModeLocal,
|
||||||
|
}
|
||||||
|
|
||||||
expectTarget_DC2 := newTarget("web", "", "default", "default", "dc2")
|
expectTarget_DC2 := newTarget("web", "", "default", "default", "dc2")
|
||||||
expectTarget_DC2.MeshGateway = structs.MeshGatewayConfig{
|
expectTarget_DC2.MeshGateway = structs.MeshGatewayConfig{
|
||||||
Mode: structs.MeshGatewayModeLocal,
|
Mode: structs.MeshGatewayModeLocal,
|
||||||
|
@ -291,7 +296,7 @@ func TestDiscoveryChainRead(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Targets: map[string]*structs.DiscoveryTarget{
|
Targets: map[string]*structs.DiscoveryTarget{
|
||||||
"web.default.default.dc1": newTarget("web", "", "default", "default", "dc1"),
|
expectTarget_DC1.ID: expectTarget_DC1,
|
||||||
expectTarget_DC2.ID: expectTarget_DC2,
|
expectTarget_DC2.ID: expectTarget_DC2,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue