Use a map for additional node addresses

This commit is contained in:
Evan Gilman 2016-01-26 10:30:28 -08:00 committed by James Phillips
parent a8fd9542dc
commit 71cf39b5f8
7 changed files with 32 additions and 18 deletions

View File

@ -405,7 +405,7 @@ RPC:
// Determine whether we should use the WAN address or not
addr := out.NodeServices.Node.Address
if d.agent.config.TranslateWanAddrs && datacenter != d.agent.config.Datacenter {
addr = out.NodeServices.Node.WanAddress
addr = out.NodeServices.Node.Addresses["wan"]
}
// Add the node record
@ -674,8 +674,8 @@ func (d *DNSServer) serviceNodeRecords(nodes structs.CheckServiceNodes, req, res
addr := node.Node.Address
if node.Service.Address != "" {
addr = node.Service.Address
} else if useWan == true && node.Node.WanAddress != "" {
addr = node.Node.WanAddress
} else if useWan == true && node.Node.Addresses["wan"] != "" {
addr = node.Node.Addresses["wan"]
}
// Avoid duplicate entries, possible if a node has
@ -724,8 +724,8 @@ func (d *DNSServer) serviceSRVRecords(dc string, nodes structs.CheckServiceNodes
addr := node.Node.Address
if node.Service.Address != "" {
addr = node.Service.Address
} else if useWan == true && node.Node.WanAddress != "" {
addr = node.Node.WanAddress
} else if useWan == true && node.Node.Addresses["wan"] != "" {
addr = node.Node.Addresses["wan"]
}
// Add the extra record

View File

@ -117,7 +117,9 @@ func TestDNS_NodeLookup(t *testing.T) {
Datacenter: "dc1",
Node: "foo",
Address: "127.0.0.1",
WanAddress: "127.0.0.2",
Addresses: map[string]string {
"wan": "127.0.0.2",
},
}
var out struct{}
@ -756,7 +758,9 @@ func TestDNS_ServiceLookup_WanAddress(t *testing.T) {
Datacenter: "dc2",
Node: "foo",
Address: "127.0.0.1",
WanAddress: "127.0.0.2",
Addresses: map[string]string {
"wan": "127.0.0.2",
},
Service: &structs.NodeService{
Service: "db",
},

View File

@ -526,7 +526,9 @@ func (l *localState) syncService(id string) error {
Datacenter: l.config.Datacenter,
Node: l.config.NodeName,
Address: l.config.AdvertiseAddr,
WanAddress: l.config.AdvertiseAddrWan,
Addresses: map[string]string {
"wan": l.config.AdvertiseAddrWan,
},
Service: l.services[id],
WriteRequest: structs.WriteRequest{Token: l.serviceToken(id)},
}
@ -584,7 +586,9 @@ func (l *localState) syncCheck(id string) error {
Datacenter: l.config.Datacenter,
Node: l.config.NodeName,
Address: l.config.AdvertiseAddr,
WanAddress: l.config.AdvertiseAddrWan,
Addresses: map[string]string {
"wan": l.config.AdvertiseAddrWan,
},
Service: service,
Check: l.checks[id],
WriteRequest: structs.WriteRequest{Token: l.checkToken(id)},

View File

@ -474,7 +474,9 @@ func (s *consulSnapshot) persistNodes(sink raft.SnapshotSink,
req := structs.RegisterRequest{
Node: n.Node,
Address: n.Address,
WanAddress: n.WanAddress,
Addresses: map[string]string {
"wan": n.Addresses["wan"],
},
}
// Register the node itself

View File

@ -381,7 +381,7 @@ func (s *Server) handleAliveMember(member serf.Member) error {
}
if node != nil && node.Address == member.Addr.String() {
// Check if the WAN address was updated
if node.WanAddress != member.Tags["wan_addr"] {
if node.Addresses["wan"] != member.Tags["wan_addr"] {
goto AFTER_CHECK
}
@ -423,7 +423,9 @@ AFTER_CHECK:
Datacenter: s.config.Datacenter,
Node: member.Name,
Address: member.Addr.String(),
WanAddress: member.Tags["wan_addr"],
Addresses: map[string]string {
"wan": member.Tags["wan_addr"],
},
Service: service,
Check: &structs.HealthCheck{
Node: member.Name,
@ -466,7 +468,9 @@ func (s *Server) handleFailedMember(member serf.Member) error {
Datacenter: s.config.Datacenter,
Node: member.Name,
Address: member.Addr.String(),
WanAddress: member.Tags["wan_addr"],
Addresses: map[string]string {
"wan": member.Tags["wan_addr"],
},
Check: &structs.HealthCheck{
Node: member.Name,
CheckID: SerfCheckID,

View File

@ -474,7 +474,7 @@ func (s *StateStore) EnsureRegistration(idx uint64, req *structs.RegisterRequest
func (s *StateStore) ensureRegistrationTxn(tx *memdb.Txn, idx uint64, watches *DumbWatchManager,
req *structs.RegisterRequest) error {
// Add the node.
node := &structs.Node{Node: req.Node, Address: req.Address, WanAddress: req.WanAddress}
node := &structs.Node{Node: req.Node, Address: req.Address, Addresses: req.Addresses}
if err := s.ensureNodeTxn(tx, idx, watches, node); err != nil {
return fmt.Errorf("failed inserting node: %s", err)
}
@ -1375,7 +1375,7 @@ func (s *StateStore) parseNodes(tx *memdb.Txn, idx uint64,
dump := &structs.NodeInfo{
Node: node.Node,
Address: node.Address,
WanAddress: node.WanAddress,
Addresses: node.Addresses,
}
// Query the node services

View File

@ -162,7 +162,7 @@ type RegisterRequest struct {
Datacenter string
Node string
Address string
WanAddress string
Addresses map[string]string
Service *NodeService
Check *HealthCheck
Checks HealthChecks
@ -248,7 +248,7 @@ func (r *ChecksInStateRequest) RequestDatacenter() string {
type Node struct {
Node string
Address string
WanAddress string
Addresses map[string]string
RaftIndex
}
@ -442,7 +442,7 @@ OUTER:
type NodeInfo struct {
Node string
Address string
WanAddress string
Addresses map[string]string
Services []*NodeService
Checks []*HealthCheck
}