Skip to content

Commit

Permalink
Adds support for service tagged addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniele Vazzola committed Jul 25, 2020
1 parent d1f1b0d commit de992d8
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 23 deletions.
6 changes: 6 additions & 0 deletions dependency/catalog_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ func TestCatalogNodeQuery_Fetch(t *testing.T) {
"meta1": "value1",
},
},
&CatalogNodeService{
ID: "service-taggedAddresses",
Service: "service-taggedAddresses",
Tags: ServiceTags([]string{}),
Meta: map[string]string{},
},
},
},
},
Expand Down
4 changes: 4 additions & 0 deletions dependency/catalog_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func TestCatalogServicesQuery_Fetch(t *testing.T) {
Name: "service-meta",
Tags: ServiceTags([]string{"tag1"}),
},
&CatalogSnippet{
Name: "service-taggedAddresses",
Tags: ServiceTags([]string{}),
},
},
},
}
Expand Down
18 changes: 18 additions & 0 deletions dependency/dependency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ func TestMain(m *testing.M) {
if err := consul_agent.ServiceRegister(serviceMetaService); err != nil {
Fatalf("%v", err)
}
// service with serviceTaggedAddresses
serviceTaggedAddressesService := &api.AgentServiceRegistration{
ID: "service-taggedAddresses",
Name: "service-taggedAddresses",
TaggedAddresses: map[string]api.ServiceAddress{
"lan": {
Address: "192.0.2.1",
Port: 80,
},
"wan": {
Address: "192.0.2.2",
Port: 443,
},
},
}
if err := consul_agent.ServiceRegister(serviceTaggedAddressesService); err != nil {
Fatalf("%v", err)
}
// connect enabled service
testService := &api.AgentServiceRegistration{
Name: "foo",
Expand Down
48 changes: 25 additions & 23 deletions dependency/health_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,21 @@ func init() {

// HealthService is a service entry in Consul.
type HealthService struct {
Node string
NodeID string
NodeAddress string
NodeTaggedAddresses map[string]string
NodeMeta map[string]string
ServiceMeta map[string]string
Address string
ID string
Name string
Tags ServiceTags
Checks api.HealthChecks
Status string
Port int
Weights api.AgentWeights
Node string
NodeID string
NodeAddress string
NodeTaggedAddresses map[string]string
NodeMeta map[string]string
ServiceMeta map[string]string
Address string
ServiceTaggedAddresses map[string]api.ServiceAddress
ID string
Name string
Tags ServiceTags
Checks api.HealthChecks
Status string
Port int
Weights api.AgentWeights
}

// HealthServiceQuery is the representation of all a service query in Consul.
Expand Down Expand Up @@ -177,15 +178,16 @@ func (d *HealthServiceQuery) Fetch(clients *ClientSet, opts *QueryOptions) (inte
}

list = append(list, &HealthService{
Node: entry.Node.Node,
NodeID: entry.Node.ID,
NodeAddress: entry.Node.Address,
NodeTaggedAddresses: entry.Node.TaggedAddresses,
NodeMeta: entry.Node.Meta,
ServiceMeta: entry.Service.Meta,
Address: address,
ID: entry.Service.ID,
Name: entry.Service.Service,
Node: entry.Node.Node,
NodeID: entry.Node.ID,
NodeAddress: entry.Node.Address,
NodeTaggedAddresses: entry.Node.TaggedAddresses,
NodeMeta: entry.Node.Meta,
ServiceMeta: entry.Service.Meta,
Address: address,
ServiceTaggedAddresses: entry.Service.TaggedAddresses,
ID: entry.Service.ID,
Name: entry.Service.Service,
Tags: ServiceTags(
deepCopyAndSortTags(entry.Service.Tags)),
Status: status,
Expand Down
37 changes: 37 additions & 0 deletions dependency/health_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,43 @@ func TestHealthServiceQuery_Fetch(t *testing.T) {
},
},
},
{
"service-taggedAddresses",
"service-taggedAddresses",
[]*HealthService{
&HealthService{
Node: testConsul.Config.NodeName,
NodeAddress: testConsul.Config.Bind,
NodeTaggedAddresses: map[string]string{
"lan": "127.0.0.1",
"wan": "127.0.0.1",
},
NodeMeta: map[string]string{
"consul-network-segment": "",
},
ServiceMeta: map[string]string{},
Address: testConsul.Config.Bind,
ServiceTaggedAddresses: map[string]api.ServiceAddress{
"lan": {
Address: "192.0.2.1",
Port: 80,
},
"wan": {
Address: "192.0.2.2",
Port: 443,
},
},
ID: "service-taggedAddresses",
Name: "service-taggedAddresses",
Tags: []string{},
Status: "passing",
Weights: api.AgentWeights{
Passing: 1,
Warning: 1,
},
},
},
},
}

for i, tc := range cases {
Expand Down

0 comments on commit de992d8

Please sign in to comment.