mirror of https://github.com/status-im/consul.git
Add CE version of Gateway Upstream Disambiguation (#19860)
* Add CE version of gateway-upstream-disambiguation * Use NamespaceOrDefault and PartitionOrDefault * Add Changelog entry * Remove the unneeded reassignment * Use c.ID()
This commit is contained in:
parent
d93f7f730d
commit
8125a32a4e
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:bug
|
||||||
|
connect: Solves an issue where two upstream services with the same name in different namespaces were not getting routed to correctly by API Gateways.
|
||||||
|
```
|
|
@ -257,7 +257,7 @@ func targetForResolverNode(nodeName string, chains []*structs.CompiledDiscoveryC
|
||||||
splitterName := splitterPrefix + strings.TrimPrefix(nodeName, resolverPrefix)
|
splitterName := splitterPrefix + strings.TrimPrefix(nodeName, resolverPrefix)
|
||||||
|
|
||||||
for _, c := range chains {
|
for _, c := range chains {
|
||||||
targetChainPrefix := resolverPrefix + c.ServiceName + "."
|
targetChainPrefix := resolverPrefix + c.ID()
|
||||||
if strings.HasPrefix(nodeName, targetChainPrefix) && len(c.Nodes) == 1 {
|
if strings.HasPrefix(nodeName, targetChainPrefix) && len(c.Nodes) == 1 {
|
||||||
// we have a virtual resolver that just maps to another resolver, return
|
// we have a virtual resolver that just maps to another resolver, return
|
||||||
// the given node name
|
// the given node name
|
||||||
|
|
|
@ -712,6 +712,7 @@ func TestGatewayChainSynthesizer_Synthesize(t *testing.T) {
|
||||||
chain: &structs.CompiledDiscoveryChain{
|
chain: &structs.CompiledDiscoveryChain{
|
||||||
ServiceName: "foo",
|
ServiceName: "foo",
|
||||||
Namespace: "default",
|
Namespace: "default",
|
||||||
|
Partition: "default",
|
||||||
Datacenter: "dc1",
|
Datacenter: "dc1",
|
||||||
StartNode: "resolver:foo-2.default.default.dc2",
|
StartNode: "resolver:foo-2.default.default.dc2",
|
||||||
Nodes: map[string]*structs.DiscoveryGraphNode{
|
Nodes: map[string]*structs.DiscoveryGraphNode{
|
||||||
|
|
|
@ -445,6 +445,8 @@ func (s *ResourceGenerator) routesForAPIGateway(cfgSnap *proxycfg.ConfigSnapshot
|
||||||
readyListeners := getReadyListeners(cfgSnap)
|
readyListeners := getReadyListeners(cfgSnap)
|
||||||
listenerNames := maps.Keys(readyListeners)
|
listenerNames := maps.Keys(readyListeners)
|
||||||
sort.Strings(listenerNames)
|
sort.Strings(listenerNames)
|
||||||
|
|
||||||
|
// Iterate over all listeners that are ready and configure their routes.
|
||||||
for _, listenerName := range listenerNames {
|
for _, listenerName := range listenerNames {
|
||||||
readyListener, ok := readyListeners[listenerName]
|
readyListener, ok := readyListeners[listenerName]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -486,6 +488,7 @@ func (s *ResourceGenerator) routesForAPIGateway(cfgSnap *proxycfg.ConfigSnapshot
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
consolidatedRoute := consolidatedRoute // Reassignment to avoid closure issues with the loop variable.
|
||||||
domains := generateUpstreamAPIsDomains(readyListener.listenerKey, upstream, consolidatedRoute.Hostnames)
|
domains := generateUpstreamAPIsDomains(readyListener.listenerKey, upstream, consolidatedRoute.Hostnames)
|
||||||
|
|
||||||
filterBuilder := perRouteFilterBuilder{providerMap: cfgSnap.JWTProviders, listener: &readyListener.listenerCfg, route: &consolidatedRoute}
|
filterBuilder := perRouteFilterBuilder{providerMap: cfgSnap.JWTProviders, listener: &readyListener.listenerCfg, route: &consolidatedRoute}
|
||||||
|
|
Loading…
Reference in New Issue