mirror of
https://github.com/status-im/consul.git
synced 2025-02-23 19:08:22 +00:00
Add segment addr field to tags for LAN flood joiner
This commit is contained in:
parent
d129767657
commit
14b027a3c2
@ -24,7 +24,7 @@ func (s *Server) FloodNotify() {
|
|||||||
// Flood is a long-running goroutine that floods servers from the LAN to the
|
// Flood is a long-running goroutine that floods servers from the LAN to the
|
||||||
// given global Serf instance, such as the WAN. This will exit once either of
|
// given global Serf instance, such as the WAN. This will exit once either of
|
||||||
// the Serf instances are shut down.
|
// the Serf instances are shut down.
|
||||||
func (s *Server) Flood(portFn router.FloodPortFn, global *serf.Serf) {
|
func (s *Server) Flood(addrFn router.FloodAddrFn, portFn router.FloodPortFn, global *serf.Serf) {
|
||||||
s.floodLock.Lock()
|
s.floodLock.Lock()
|
||||||
floodCh := make(chan struct{})
|
floodCh := make(chan struct{})
|
||||||
s.floodCh = append(s.floodCh, floodCh)
|
s.floodCh = append(s.floodCh, floodCh)
|
||||||
@ -61,6 +61,6 @@ func (s *Server) Flood(portFn router.FloodPortFn, global *serf.Serf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FLOOD:
|
FLOOD:
|
||||||
router.FloodJoins(s.logger, portFn, s.config.Datacenter, s.serfLAN, global)
|
router.FloodJoins(s.logger, addrFn, portFn, s.config.Datacenter, s.serfLAN, global)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -410,7 +410,7 @@ func NewServerLogger(config *Config, logger *log.Logger, tokens *token.Store) (*
|
|||||||
}
|
}
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
go s.Flood(portFn, s.serfWAN)
|
go s.Flood(nil, portFn, s.serfWAN)
|
||||||
|
|
||||||
// Start monitoring leadership. This must happen after Serf is set up
|
// Start monitoring leadership. This must happen after Serf is set up
|
||||||
// since it can fire events when leadership is obtained.
|
// since it can fire events when leadership is obtained.
|
||||||
|
@ -43,6 +43,7 @@ func (s *Server) setupSerf(conf *serf.Config, ch chan serf.Event, path string, w
|
|||||||
conf.Tags["segment"] = segment
|
conf.Tags["segment"] = segment
|
||||||
if segment == "" {
|
if segment == "" {
|
||||||
for _, s := range s.config.Segments {
|
for _, s := range s.config.Segments {
|
||||||
|
conf.Tags["segment_addr_"+s.Name] = s.Advertise
|
||||||
conf.Tags["segment_port_"+s.Name] = fmt.Sprintf("%d", s.Port)
|
conf.Tags["segment_port_"+s.Name] = fmt.Sprintf("%d", s.Port)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ type Server struct {
|
|||||||
Datacenter string
|
Datacenter string
|
||||||
Segment string
|
Segment string
|
||||||
Port int
|
Port int
|
||||||
|
SegmentAddrs map[string]string
|
||||||
SegmentPorts map[string]int
|
SegmentPorts map[string]int
|
||||||
WanJoinPort int
|
WanJoinPort int
|
||||||
Bootstrap bool
|
Bootstrap bool
|
||||||
@ -96,8 +97,13 @@ func IsConsulServer(m serf.Member) (bool, *Server) {
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
segment_addrs := make(map[string]string)
|
||||||
segment_ports := make(map[string]int)
|
segment_ports := make(map[string]int)
|
||||||
for name, value := range m.Tags {
|
for name, value := range m.Tags {
|
||||||
|
if strings.HasPrefix(name, "segment_addr_") {
|
||||||
|
segment_addrs[strings.TrimPrefix(name, "segment_addr_")] = value
|
||||||
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(name, "segment_port_") {
|
if strings.HasPrefix(name, "segment_port_") {
|
||||||
segment_port, err := strconv.Atoi(value)
|
segment_port, err := strconv.Atoi(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -146,6 +152,7 @@ func IsConsulServer(m serf.Member) (bool, *Server) {
|
|||||||
Datacenter: datacenter,
|
Datacenter: datacenter,
|
||||||
Segment: segment,
|
Segment: segment,
|
||||||
Port: port,
|
Port: port,
|
||||||
|
SegmentAddrs: segment_addrs,
|
||||||
SegmentPorts: segment_ports,
|
SegmentPorts: segment_ports,
|
||||||
WanJoinPort: wan_join_port,
|
WanJoinPort: wan_join_port,
|
||||||
Bootstrap: bootstrap,
|
Bootstrap: bootstrap,
|
||||||
|
@ -10,6 +10,10 @@ import (
|
|||||||
"github.com/hashicorp/serf/serf"
|
"github.com/hashicorp/serf/serf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// FloodAddrFn gets the address to use for a given server when flood-joining. This
|
||||||
|
// will return false if it doesn't have one.
|
||||||
|
type FloodAddrFn func(*metadata.Server) (string, bool)
|
||||||
|
|
||||||
// FloodPortFn gets the port to use for a given server when flood-joining. This
|
// FloodPortFn gets the port to use for a given server when flood-joining. This
|
||||||
// will return false if it doesn't have one.
|
// will return false if it doesn't have one.
|
||||||
type FloodPortFn func(*metadata.Server) (int, bool)
|
type FloodPortFn func(*metadata.Server) (int, bool)
|
||||||
@ -19,7 +23,7 @@ type FloodPortFn func(*metadata.Server) (int, bool)
|
|||||||
// local area are of the form <node> and those in the global area are of the
|
// local area are of the form <node> and those in the global area are of the
|
||||||
// form <node>.<dc> as is done for WAN and general network areas in Consul
|
// form <node>.<dc> as is done for WAN and general network areas in Consul
|
||||||
// Enterprise.
|
// Enterprise.
|
||||||
func FloodJoins(logger *log.Logger, portFn FloodPortFn,
|
func FloodJoins(logger *log.Logger, addrFn FloodAddrFn, portFn FloodPortFn,
|
||||||
localDatacenter string, localSerf *serf.Serf, globalSerf *serf.Serf) {
|
localDatacenter string, localSerf *serf.Serf, globalSerf *serf.Serf) {
|
||||||
|
|
||||||
// Names in the global Serf have the datacenter suffixed.
|
// Names in the global Serf have the datacenter suffixed.
|
||||||
@ -64,6 +68,11 @@ func FloodJoins(logger *log.Logger, portFn FloodPortFn,
|
|||||||
logger.Printf("[DEBUG] consul: Failed to flood-join %q (bad address %q): %v",
|
logger.Printf("[DEBUG] consul: Failed to flood-join %q (bad address %q): %v",
|
||||||
server.Name, server.Addr.String(), err)
|
server.Name, server.Addr.String(), err)
|
||||||
}
|
}
|
||||||
|
if addrFn != nil {
|
||||||
|
if a, ok := addrFn(server); ok {
|
||||||
|
addr = a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Let the callback see if it can get the port number, otherwise
|
// Let the callback see if it can get the port number, otherwise
|
||||||
// leave it blank to behave as if we just supplied an address.
|
// leave it blank to behave as if we just supplied an address.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user