mirror of https://github.com/status-im/consul.git
Sets up config for more address tags down the road, renames struct members.
This commit is contained in:
parent
de8fd561d0
commit
c60a526fde
|
@ -161,6 +161,11 @@ func Create(config *Config, logOutput io.Writer) (*Agent, error) {
|
||||||
config.AdvertiseAddrWan = config.AdvertiseAddr
|
config.AdvertiseAddrWan = config.AdvertiseAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create the default set of tagged addresses.
|
||||||
|
config.TaggedAddresses = map[string]string{
|
||||||
|
"wan": config.AdvertiseAddrWan,
|
||||||
|
}
|
||||||
|
|
||||||
agent := &Agent{
|
agent := &Agent{
|
||||||
config: config,
|
config: config,
|
||||||
logger: log.New(logOutput, "", log.LstdFlags),
|
logger: log.New(logOutput, "", log.LstdFlags),
|
||||||
|
@ -287,7 +292,6 @@ func (a *Agent) consulConfig() *consul.Config {
|
||||||
if a.config.AdvertiseAddrs.SerfWan != nil {
|
if a.config.AdvertiseAddrs.SerfWan != nil {
|
||||||
base.SerfWANConfig.MemberlistConfig.AdvertiseAddr = a.config.AdvertiseAddrs.SerfWan.IP.String()
|
base.SerfWANConfig.MemberlistConfig.AdvertiseAddr = a.config.AdvertiseAddrs.SerfWan.IP.String()
|
||||||
base.SerfWANConfig.MemberlistConfig.AdvertisePort = a.config.AdvertiseAddrs.SerfWan.Port
|
base.SerfWANConfig.MemberlistConfig.AdvertisePort = a.config.AdvertiseAddrs.SerfWan.Port
|
||||||
a.config.AdvertiseAddrWan = a.config.AdvertiseAddrs.SerfWan.IP.String()
|
|
||||||
}
|
}
|
||||||
if a.config.AdvertiseAddrs.RPC != nil {
|
if a.config.AdvertiseAddrs.RPC != nil {
|
||||||
base.RPCAdvertise = a.config.AdvertiseAddrs.RPC
|
base.RPCAdvertise = a.config.AdvertiseAddrs.RPC
|
||||||
|
|
|
@ -168,9 +168,11 @@ func TestAgent_CheckAdvertiseAddrsSettings(t *testing.T) {
|
||||||
if rpc != c.AdvertiseAddrs.RPC {
|
if rpc != c.AdvertiseAddrs.RPC {
|
||||||
t.Fatalf("RPC is not properly set to %v: %s", c.AdvertiseAddrs.RPC, rpc)
|
t.Fatalf("RPC is not properly set to %v: %s", c.AdvertiseAddrs.RPC, rpc)
|
||||||
}
|
}
|
||||||
advertiseWanAddress := agent.config.AdvertiseAddrWan
|
expected := map[string]string{
|
||||||
if serfWanAddr != advertiseWanAddress {
|
"wan": agent.config.AdvertiseAddrWan,
|
||||||
t.Fatalf("AdvertiseAddrWan is not properly set to '%s': %s", serfWanAddr, advertiseWanAddress)
|
}
|
||||||
|
if !reflect.DeepEqual(agent.config.TaggedAddresses, expected) {
|
||||||
|
t.Fatalf("Tagged addresses not set up properly: %v", agent.config.TaggedAddresses)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -190,7 +190,8 @@ type Config struct {
|
||||||
AdvertiseAddrWan string `mapstructure:"advertise_addr_wan"`
|
AdvertiseAddrWan string `mapstructure:"advertise_addr_wan"`
|
||||||
|
|
||||||
// TranslateWanAddrs controls whether or not Consul should prefer
|
// TranslateWanAddrs controls whether or not Consul should prefer
|
||||||
// the AdvertiseAddrWan address when doing lookups in remote datacenters.
|
// the "wan" tagged address when doing lookups in remote datacenters.
|
||||||
|
// See TaggedAddresses below for more details.
|
||||||
TranslateWanAddrs bool `mapstructure:"translate_wan_addrs"`
|
TranslateWanAddrs bool `mapstructure:"translate_wan_addrs"`
|
||||||
|
|
||||||
// Port configurations
|
// Port configurations
|
||||||
|
@ -199,6 +200,14 @@ type Config struct {
|
||||||
// Address configurations
|
// Address configurations
|
||||||
Addresses AddressConfig
|
Addresses AddressConfig
|
||||||
|
|
||||||
|
// Tagged addresses. These are used to publish a set of addresses for
|
||||||
|
// for a node, which can be used by the remote agent. We currently
|
||||||
|
// populate only the "wan" tag based on the SerfWan advertise address,
|
||||||
|
// but this structure is here for possible future features with other
|
||||||
|
// user-defined tags. The "wan" tag will be used by remote agents if
|
||||||
|
// they are configured with TranslateWanAddrs set to true.
|
||||||
|
TaggedAddresses map[string]string
|
||||||
|
|
||||||
// LeaveOnTerm controls if Serf does a graceful leave when receiving
|
// LeaveOnTerm controls if Serf does a graceful leave when receiving
|
||||||
// the TERM signal. Defaults false. This can be changed on reload.
|
// the TERM signal. Defaults false. This can be changed on reload.
|
||||||
LeaveOnTerm bool `mapstructure:"leave_on_terminate"`
|
LeaveOnTerm bool `mapstructure:"leave_on_terminate"`
|
||||||
|
|
|
@ -405,7 +405,7 @@ RPC:
|
||||||
// Determine whether we should use the WAN address or not
|
// Determine whether we should use the WAN address or not
|
||||||
addr := out.NodeServices.Node.Address
|
addr := out.NodeServices.Node.Address
|
||||||
if d.agent.config.TranslateWanAddrs && datacenter != d.agent.config.Datacenter {
|
if d.agent.config.TranslateWanAddrs && datacenter != d.agent.config.Datacenter {
|
||||||
addr = out.NodeServices.Node.Addresses["wan"]
|
addr = out.NodeServices.Node.TaggedAddresses["wan"]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the node record
|
// Add the node record
|
||||||
|
@ -674,8 +674,8 @@ func (d *DNSServer) serviceNodeRecords(nodes structs.CheckServiceNodes, req, res
|
||||||
addr := node.Node.Address
|
addr := node.Node.Address
|
||||||
if node.Service.Address != "" {
|
if node.Service.Address != "" {
|
||||||
addr = node.Service.Address
|
addr = node.Service.Address
|
||||||
} else if useWan == true && node.Node.Addresses["wan"] != "" {
|
} else if useWan == true && node.Node.TaggedAddresses["wan"] != "" {
|
||||||
addr = node.Node.Addresses["wan"]
|
addr = node.Node.TaggedAddresses["wan"]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Avoid duplicate entries, possible if a node has
|
// 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
|
addr := node.Node.Address
|
||||||
if node.Service.Address != "" {
|
if node.Service.Address != "" {
|
||||||
addr = node.Service.Address
|
addr = node.Service.Address
|
||||||
} else if useWan == true && node.Node.Addresses["wan"] != "" {
|
} else if useWan == true && node.Node.TaggedAddresses["wan"] != "" {
|
||||||
addr = node.Node.Addresses["wan"]
|
addr = node.Node.TaggedAddresses["wan"]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the extra record
|
// Add the extra record
|
||||||
|
|
|
@ -117,7 +117,7 @@ func TestDNS_NodeLookup(t *testing.T) {
|
||||||
Datacenter: "dc1",
|
Datacenter: "dc1",
|
||||||
Node: "foo",
|
Node: "foo",
|
||||||
Address: "127.0.0.1",
|
Address: "127.0.0.1",
|
||||||
Addresses: map[string]string {
|
TaggedAddresses: map[string]string{
|
||||||
"wan": "127.0.0.2",
|
"wan": "127.0.0.2",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -758,7 +758,7 @@ func TestDNS_ServiceLookup_WanAddress(t *testing.T) {
|
||||||
Datacenter: "dc2",
|
Datacenter: "dc2",
|
||||||
Node: "foo",
|
Node: "foo",
|
||||||
Address: "127.0.0.1",
|
Address: "127.0.0.1",
|
||||||
Addresses: map[string]string {
|
TaggedAddresses: map[string]string{
|
||||||
"wan": "127.0.0.2",
|
"wan": "127.0.0.2",
|
||||||
},
|
},
|
||||||
Service: &structs.NodeService{
|
Service: &structs.NodeService{
|
||||||
|
|
|
@ -523,14 +523,12 @@ func (l *localState) deleteCheck(id string) error {
|
||||||
// syncService is used to sync a service to the server
|
// syncService is used to sync a service to the server
|
||||||
func (l *localState) syncService(id string) error {
|
func (l *localState) syncService(id string) error {
|
||||||
req := structs.RegisterRequest{
|
req := structs.RegisterRequest{
|
||||||
Datacenter: l.config.Datacenter,
|
Datacenter: l.config.Datacenter,
|
||||||
Node: l.config.NodeName,
|
Node: l.config.NodeName,
|
||||||
Address: l.config.AdvertiseAddr,
|
Address: l.config.AdvertiseAddr,
|
||||||
Addresses: map[string]string {
|
TaggedAddresses: l.config.TaggedAddresses,
|
||||||
"wan": l.config.AdvertiseAddrWan,
|
Service: l.services[id],
|
||||||
},
|
WriteRequest: structs.WriteRequest{Token: l.serviceToken(id)},
|
||||||
Service: l.services[id],
|
|
||||||
WriteRequest: structs.WriteRequest{Token: l.serviceToken(id)},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the service has associated checks that are out of sync,
|
// If the service has associated checks that are out of sync,
|
||||||
|
@ -583,15 +581,13 @@ func (l *localState) syncCheck(id string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
req := structs.RegisterRequest{
|
req := structs.RegisterRequest{
|
||||||
Datacenter: l.config.Datacenter,
|
Datacenter: l.config.Datacenter,
|
||||||
Node: l.config.NodeName,
|
Node: l.config.NodeName,
|
||||||
Address: l.config.AdvertiseAddr,
|
Address: l.config.AdvertiseAddr,
|
||||||
Addresses: map[string]string {
|
TaggedAddresses: l.config.TaggedAddresses,
|
||||||
"wan": l.config.AdvertiseAddrWan,
|
Service: service,
|
||||||
},
|
Check: l.checks[id],
|
||||||
Service: service,
|
WriteRequest: structs.WriteRequest{Token: l.checkToken(id)},
|
||||||
Check: l.checks[id],
|
|
||||||
WriteRequest: structs.WriteRequest{Token: l.checkToken(id)},
|
|
||||||
}
|
}
|
||||||
var out struct{}
|
var out struct{}
|
||||||
err := l.iface.RPC("Catalog.Register", &req, &out)
|
err := l.iface.RPC("Catalog.Register", &req, &out)
|
||||||
|
|
|
@ -472,11 +472,9 @@ func (s *consulSnapshot) persistNodes(sink raft.SnapshotSink,
|
||||||
for node := nodes.Next(); node != nil; node = nodes.Next() {
|
for node := nodes.Next(); node != nil; node = nodes.Next() {
|
||||||
n := node.(*structs.Node)
|
n := node.(*structs.Node)
|
||||||
req := structs.RegisterRequest{
|
req := structs.RegisterRequest{
|
||||||
Node: n.Node,
|
Node: n.Node,
|
||||||
Address: n.Address,
|
Address: n.Address,
|
||||||
Addresses: map[string]string {
|
TaggedAddresses: n.TaggedAddresses,
|
||||||
"wan": n.Addresses["wan"],
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the node itself
|
// Register the node itself
|
||||||
|
|
|
@ -381,7 +381,7 @@ func (s *Server) handleAliveMember(member serf.Member) error {
|
||||||
}
|
}
|
||||||
if node != nil && node.Address == member.Addr.String() {
|
if node != nil && node.Address == member.Addr.String() {
|
||||||
// Check if the WAN address was updated
|
// Check if the WAN address was updated
|
||||||
if node.Addresses["wan"] != member.Tags["wan_addr"] {
|
if node.TaggedAddresses["wan"] != member.Tags["wan_addr"] {
|
||||||
goto AFTER_CHECK
|
goto AFTER_CHECK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,10 +423,10 @@ AFTER_CHECK:
|
||||||
Datacenter: s.config.Datacenter,
|
Datacenter: s.config.Datacenter,
|
||||||
Node: member.Name,
|
Node: member.Name,
|
||||||
Address: member.Addr.String(),
|
Address: member.Addr.String(),
|
||||||
Addresses: map[string]string {
|
TaggedAddresses: map[string]string{
|
||||||
"wan": member.Tags["wan_addr"],
|
"wan": member.Tags["wan_addr"],
|
||||||
},
|
},
|
||||||
Service: service,
|
Service: service,
|
||||||
Check: &structs.HealthCheck{
|
Check: &structs.HealthCheck{
|
||||||
Node: member.Name,
|
Node: member.Name,
|
||||||
CheckID: SerfCheckID,
|
CheckID: SerfCheckID,
|
||||||
|
@ -468,7 +468,7 @@ func (s *Server) handleFailedMember(member serf.Member) error {
|
||||||
Datacenter: s.config.Datacenter,
|
Datacenter: s.config.Datacenter,
|
||||||
Node: member.Name,
|
Node: member.Name,
|
||||||
Address: member.Addr.String(),
|
Address: member.Addr.String(),
|
||||||
Addresses: map[string]string {
|
TaggedAddresses: map[string]string{
|
||||||
"wan": member.Tags["wan_addr"],
|
"wan": member.Tags["wan_addr"],
|
||||||
},
|
},
|
||||||
Check: &structs.HealthCheck{
|
Check: &structs.HealthCheck{
|
||||||
|
|
|
@ -474,7 +474,11 @@ func (s *StateStore) EnsureRegistration(idx uint64, req *structs.RegisterRequest
|
||||||
func (s *StateStore) ensureRegistrationTxn(tx *memdb.Txn, idx uint64, watches *DumbWatchManager,
|
func (s *StateStore) ensureRegistrationTxn(tx *memdb.Txn, idx uint64, watches *DumbWatchManager,
|
||||||
req *structs.RegisterRequest) error {
|
req *structs.RegisterRequest) error {
|
||||||
// Add the node.
|
// Add the node.
|
||||||
node := &structs.Node{Node: req.Node, Address: req.Address, Addresses: req.Addresses}
|
node := &structs.Node{
|
||||||
|
Node: req.Node,
|
||||||
|
Address: req.Address,
|
||||||
|
TaggedAddresses: req.TaggedAddresses,
|
||||||
|
}
|
||||||
if err := s.ensureNodeTxn(tx, idx, watches, node); err != nil {
|
if err := s.ensureNodeTxn(tx, idx, watches, node); err != nil {
|
||||||
return fmt.Errorf("failed inserting node: %s", err)
|
return fmt.Errorf("failed inserting node: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -1373,9 +1377,9 @@ func (s *StateStore) parseNodes(tx *memdb.Txn, idx uint64,
|
||||||
|
|
||||||
// Create the wrapped node
|
// Create the wrapped node
|
||||||
dump := &structs.NodeInfo{
|
dump := &structs.NodeInfo{
|
||||||
Node: node.Node,
|
Node: node.Node,
|
||||||
Address: node.Address,
|
Address: node.Address,
|
||||||
Addresses: node.Addresses,
|
TaggedAddresses: node.TaggedAddresses,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query the node services
|
// Query the node services
|
||||||
|
|
|
@ -159,13 +159,13 @@ type QueryMeta struct {
|
||||||
// to register a node as providing a service. If no service
|
// to register a node as providing a service. If no service
|
||||||
// is provided, the node is registered.
|
// is provided, the node is registered.
|
||||||
type RegisterRequest struct {
|
type RegisterRequest struct {
|
||||||
Datacenter string
|
Datacenter string
|
||||||
Node string
|
Node string
|
||||||
Address string
|
Address string
|
||||||
Addresses map[string]string
|
TaggedAddresses map[string]string
|
||||||
Service *NodeService
|
Service *NodeService
|
||||||
Check *HealthCheck
|
Check *HealthCheck
|
||||||
Checks HealthChecks
|
Checks HealthChecks
|
||||||
WriteRequest
|
WriteRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,9 +246,9 @@ func (r *ChecksInStateRequest) RequestDatacenter() string {
|
||||||
|
|
||||||
// Used to return information about a node
|
// Used to return information about a node
|
||||||
type Node struct {
|
type Node struct {
|
||||||
Node string
|
Node string
|
||||||
Address string
|
Address string
|
||||||
Addresses map[string]string
|
TaggedAddresses map[string]string
|
||||||
|
|
||||||
RaftIndex
|
RaftIndex
|
||||||
}
|
}
|
||||||
|
@ -440,11 +440,11 @@ OUTER:
|
||||||
// a node. This is currently used for the UI only, as it is
|
// a node. This is currently used for the UI only, as it is
|
||||||
// rather expensive to generate.
|
// rather expensive to generate.
|
||||||
type NodeInfo struct {
|
type NodeInfo struct {
|
||||||
Node string
|
Node string
|
||||||
Address string
|
Address string
|
||||||
Addresses map[string]string
|
TaggedAddresses map[string]string
|
||||||
Services []*NodeService
|
Services []*NodeService
|
||||||
Checks []*HealthCheck
|
Checks []*HealthCheck
|
||||||
}
|
}
|
||||||
|
|
||||||
// NodeDump is used to dump all the nodes with all their
|
// NodeDump is used to dump all the nodes with all their
|
||||||
|
|
Loading…
Reference in New Issue