cluster: don't track FQDN addresses as inital peers (#1416)
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
parent
6a7c912559
commit
8034f137e1
|
@ -232,6 +232,9 @@ func (p *Peer) setInitialFailed(peers []string, myAddr string) {
|
|||
return
|
||||
}
|
||||
|
||||
p.peerLock.RLock()
|
||||
defer p.peerLock.RUnlock()
|
||||
|
||||
now := time.Now()
|
||||
for _, peerAddr := range peers {
|
||||
if peerAddr == myAddr {
|
||||
|
@ -239,10 +242,16 @@ func (p *Peer) setInitialFailed(peers []string, myAddr string) {
|
|||
// we don't connect to ourselves.
|
||||
continue
|
||||
}
|
||||
ip, port, err := net.SplitHostPort(peerAddr)
|
||||
host, port, err := net.SplitHostPort(peerAddr)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
ip := net.ParseIP(host)
|
||||
if ip == nil {
|
||||
// Don't add textual addresses since memberlist only advertises
|
||||
// dotted decimal or IPv6 addresses.
|
||||
continue
|
||||
}
|
||||
portUint, err := strconv.ParseUint(port, 10, 16)
|
||||
if err != nil {
|
||||
continue
|
||||
|
@ -252,7 +261,7 @@ func (p *Peer) setInitialFailed(peers []string, myAddr string) {
|
|||
status: StatusFailed,
|
||||
leaveTime: now,
|
||||
Node: &memberlist.Node{
|
||||
Addr: net.ParseIP(ip),
|
||||
Addr: ip,
|
||||
Port: uint16(portUint),
|
||||
},
|
||||
}
|
||||
|
|
|
@ -179,7 +179,7 @@ func TestRemoveFailedPeers(t *testing.T) {
|
|||
func TestInitiallyFailingPeers(t *testing.T) {
|
||||
logger := log.NewNopLogger()
|
||||
myAddr := "1.2.3.4:5000"
|
||||
peerAddrs := []string{myAddr, "2.3.4.5:5000", "3.4.5.6:5000"}
|
||||
peerAddrs := []string{myAddr, "2.3.4.5:5000", "3.4.5.6:5000", "foo.example.com:5000"}
|
||||
p, err := Join(
|
||||
logger,
|
||||
prometheus.NewRegistry(),
|
||||
|
@ -200,10 +200,11 @@ func TestInitiallyFailingPeers(t *testing.T) {
|
|||
|
||||
p.setInitialFailed(peerAddrs, myAddr)
|
||||
|
||||
// We shouldn't have added "our" bind addr to the failed peers list
|
||||
require.Equal(t, len(peerAddrs)-1, len(p.failedPeers))
|
||||
// We shouldn't have added "our" bind addr and the FQDN address to the
|
||||
// failed peers list.
|
||||
require.Equal(t, len(peerAddrs)-2, len(p.failedPeers))
|
||||
for _, addr := range peerAddrs {
|
||||
if addr == myAddr {
|
||||
if addr == myAddr || addr == "foo.example.com:5000" {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue