Skip to content

Commit

Permalink
Merge pull request #8754 from hashicorp/fix_dns_name_for_gateways_1.8.x
Browse files Browse the repository at this point in the history
[backport/1.8.x]: use service datacenter for dns name
  • Loading branch information
rboyer authored Sep 25, 2020
2 parents 30eddc4 + 780d2d7 commit 53ae300
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/8704.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: show correct datacenter for gateways
```
11 changes: 6 additions & 5 deletions agent/ui_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ RPC:

// Generate the summary
// TODO (gateways) (freddy) Have Internal.ServiceDump return ServiceDump instead. Need to add bexpr filtering for type.
return summarizeServices(out.Nodes.ToServiceDump(), s.agent.config), nil
return summarizeServices(out.Nodes.ToServiceDump(), s.agent.config, args.Datacenter), nil
}

// UIGatewayServices is used to query all the nodes for services associated with a gateway along with their gateway config
Expand Down Expand Up @@ -199,10 +199,10 @@ RPC:
return nil, err
}

return summarizeServices(out.Dump, s.agent.config), nil
return summarizeServices(out.Dump, s.agent.config, args.Datacenter), nil
}

func summarizeServices(dump structs.ServiceDump, cfg *config.RuntimeConfig) []*ServiceSummary {
func summarizeServices(dump structs.ServiceDump, cfg *config.RuntimeConfig, datacenter string) []*ServiceSummary {
// Collect the summary information
var services []structs.ServiceID
summary := make(map[structs.ServiceID]*ServiceSummary)
Expand All @@ -226,7 +226,7 @@ func summarizeServices(dump structs.ServiceDump, cfg *config.RuntimeConfig) []*S
if csn.GatewayService != nil {
gwsvc := csn.GatewayService
sum := getService(gwsvc.Service.ToServiceID())
modifySummaryForGatewayService(cfg, sum, gwsvc)
modifySummaryForGatewayService(cfg, datacenter, sum, gwsvc)
}

// Will happen in cases where we only have the GatewayServices mapping
Expand Down Expand Up @@ -307,6 +307,7 @@ func summarizeServices(dump structs.ServiceDump, cfg *config.RuntimeConfig) []*S

func modifySummaryForGatewayService(
cfg *config.RuntimeConfig,
datacenter string,
sum *ServiceSummary,
gwsvc *structs.GatewayService,
) {
Expand All @@ -319,7 +320,7 @@ func modifySummaryForGatewayService(
}
dnsAddresses = append(dnsAddresses, serviceIngressDNSName(
gwsvc.Service.Name,
cfg.Datacenter,
datacenter,
domain,
&gwsvc.Service.EnterpriseMeta,
))
Expand Down
11 changes: 11 additions & 0 deletions agent/ui_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"path/filepath"
"testing"

"github.com/hashicorp/consul/agent/config"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/sdk/testutil"
Expand Down Expand Up @@ -698,3 +699,13 @@ func TestUIGatewayServiceNodes_Ingress(t *testing.T) {
}
assert.ElementsMatch(t, expect, dump)
}

func TestUIEndpoint_modifySummaryForGatewayService_UseRequestedDCInsteadOfConfigured(t *testing.T) {
dc := "dc2"
cfg := config.RuntimeConfig{Datacenter: "dc1", DNSDomain: "consul"}
sum := ServiceSummary{GatewayConfig: GatewayConfig{}}
gwsvc := structs.GatewayService{Service: structs.ServiceName{Name: "test"}, Port: 42}
modifySummaryForGatewayService(&cfg, dc, &sum, &gwsvc)
expected := serviceCanonicalDNSName("test", "ingress", "dc2", "consul", nil) + ":42"
require.Equal(t, expected, sum.GatewayConfig.Addresses[0])
}

0 comments on commit 53ae300

Please sign in to comment.