Skip to content

Commit

Permalink
[Backport 1.17.x] Add CE version of Gateway Upstream Disambiguation (#…
Browse files Browse the repository at this point in the history
…19868)

* Add CE version of Gateway Upstream Disambiguation

* Add range variable shadow

---------

Co-authored-by: Thomas Eckert <teckert@hashicorp.com>
  • Loading branch information
Andrew Stucki and Thomas Eckert authored Dec 8, 2023
1 parent a34009b commit 880713a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/19860.txt
Original file line number Diff line number Diff line change
@@ -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.
```
2 changes: 1 addition & 1 deletion agent/consul/discoverychain/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func targetForResolverNode(nodeName string, chains []*structs.CompiledDiscoveryC
splitterName := splitterPrefix + strings.TrimPrefix(nodeName, resolverPrefix)

for _, c := range chains {
targetChainPrefix := resolverPrefix + c.ServiceName + "."
targetChainPrefix := resolverPrefix + c.ID()
if strings.HasPrefix(nodeName, targetChainPrefix) && len(c.Nodes) == 1 {
// we have a virtual resolver that just maps to another resolver, return
// the given node name
Expand Down
1 change: 1 addition & 0 deletions agent/consul/discoverychain/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ func TestGatewayChainSynthesizer_Synthesize(t *testing.T) {
chain: &structs.CompiledDiscoveryChain{
ServiceName: "foo",
Namespace: "default",
Partition: "default",
Datacenter: "dc1",
StartNode: "resolver:foo-2.default.default.dc2",
Nodes: map[string]*structs.DiscoveryGraphNode{
Expand Down
3 changes: 3 additions & 0 deletions agent/xds/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ func (s *ResourceGenerator) routesForAPIGateway(cfgSnap *proxycfg.ConfigSnapshot
readyListeners := getReadyListeners(cfgSnap)
listenerNames := maps.Keys(readyListeners)
sort.Strings(listenerNames)

// Iterate over all listeners that are ready and configure their routes.
for _, listenerName := range listenerNames {
readyListener, ok := readyListeners[listenerName]
if !ok {
Expand Down Expand Up @@ -481,6 +483,7 @@ func (s *ResourceGenerator) routesForAPIGateway(cfgSnap *proxycfg.ConfigSnapshot
continue
}

consolidatedRoute := consolidatedRoute // Reassignment to avoid closure issues with the loop variable.
domains := generateUpstreamAPIsDomains(readyListener.listenerKey, upstream, consolidatedRoute.Hostnames)

filterBuilder := perRouteFilterBuilder{providerMap: cfgSnap.JWTProviders, listener: &readyListener.listenerCfg, route: &consolidatedRoute}
Expand Down

0 comments on commit 880713a

Please sign in to comment.