From 6c0bb5a8102e62d2ef4cdf33e7ec3452900ea6ab Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Tue, 27 Mar 2018 09:44:41 -0500 Subject: [PATCH] Fix test and remove unused method --- agent/config/builder.go | 20 ++++++++++++++++---- agent/config/runtime_test.go | 12 +++++++++++- agent/consul/server.go | 10 ---------- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/agent/config/builder.go b/agent/config/builder.go index 1b3f95f590..22e451bf5f 100644 --- a/agent/config/builder.go +++ b/agent/config/builder.go @@ -408,14 +408,23 @@ func (b *Builder) Build() (rt RuntimeConfig, err error) { // derive other bind addresses from the bindAddr rpcBindAddr := b.makeTCPAddr(bindAddr, nil, serverPort) serfBindAddrLAN := b.makeTCPAddr(b.expandFirstIP("serf_lan", c.SerfBindAddrLAN), bindAddr, serfPortLAN) - serfBindAddrWAN := b.makeTCPAddr(b.expandFirstIP("serf_wan", c.SerfBindAddrWAN), bindAddr, serfPortWAN) + + // Only initialize serf WAN bind address when its enabled + var serfBindAddrWAN *net.TCPAddr + if serfPortWAN >= 0 { + serfBindAddrWAN = b.makeTCPAddr(b.expandFirstIP("serf_wan", c.SerfBindAddrWAN), bindAddr, serfPortWAN) + } // derive other advertise addresses from the advertise address advertiseAddrLAN := b.makeIPAddr(b.expandFirstIP("advertise_addr", c.AdvertiseAddrLAN), advertiseAddr) advertiseAddrWAN := b.makeIPAddr(b.expandFirstIP("advertise_addr_wan", c.AdvertiseAddrWAN), advertiseAddrLAN) rpcAdvertiseAddr := &net.TCPAddr{IP: advertiseAddrLAN.IP, Port: serverPort} serfAdvertiseAddrLAN := &net.TCPAddr{IP: advertiseAddrLAN.IP, Port: serfPortLAN} - serfAdvertiseAddrWAN := &net.TCPAddr{IP: advertiseAddrWAN.IP, Port: serfPortWAN} + // Only initialize serf WAN advertise address when its enabled + var serfAdvertiseAddrWAN *net.TCPAddr + if serfPortWAN >= 0 { + serfAdvertiseAddrWAN = &net.TCPAddr{IP: advertiseAddrWAN.IP, Port: serfPortWAN} + } // determine client addresses clientAddrs := b.expandIPs("client_addr", c.ClientAddr) @@ -866,8 +875,11 @@ func (b *Builder) Validate(rt RuntimeConfig) error { if err := addrUnique(inuse, "Serf Advertise LAN", rt.SerfAdvertiseAddrLAN); err != nil { return err } - if err := addrUnique(inuse, "Serf Advertise WAN", rt.SerfAdvertiseAddrWAN); err != nil { - return err + // Validate serf WAN advertise address only when its set + if rt.SerfAdvertiseAddrWAN != nil { + if err := addrUnique(inuse, "Serf Advertise WAN", rt.SerfAdvertiseAddrWAN); err != nil { + return err + } } if b.err != nil { return b.err diff --git a/agent/config/runtime_test.go b/agent/config/runtime_test.go index a4b411d785..633c9cf654 100644 --- a/agent/config/runtime_test.go +++ b/agent/config/runtime_test.go @@ -1079,7 +1079,17 @@ func TestConfigFlagsAndEdgecases(t *testing.T) { } advertise_addr_wan = "1.2.3.4" `}, - err: nil, + patch: func(rt *RuntimeConfig) { + rt.AdvertiseAddrWAN = ipAddr("1.2.3.4") + rt.SerfAdvertiseAddrWAN = nil + rt.SerfBindAddrWAN = nil + rt.TaggedAddresses = map[string]string{ + "lan": "10.0.0.1", + "wan": "1.2.3.4", + } + rt.DataDir = dataDir + rt.SerfPortWAN = -1 + }, }, { desc: "serf bind address lan template", diff --git a/agent/consul/server.go b/agent/consul/server.go index dcc711dd79..fa633a4efe 100644 --- a/agent/consul/server.go +++ b/agent/consul/server.go @@ -32,7 +32,6 @@ import ( "github.com/hashicorp/consul/types" "github.com/hashicorp/raft" raftboltdb "github.com/hashicorp/raft-boltdb" - "github.com/hashicorp/serf/coordinate" "github.com/hashicorp/serf/serf" ) @@ -1045,15 +1044,6 @@ func (s *Server) GetLANCoordinate() (lib.CoordinateSet, error) { return cs, nil } -// GetWANCoordinate returns the coordinate of the server in the WAN gossip pool. -func (s *Server) GetWANCoordinate() (*coordinate.Coordinate, error) { - if s.serfWAN == nil { - // Return zero values if WAN federation is disabled - return &coordinate.Coordinate{}, nil - } - return s.serfWAN.GetCoordinate() -} - // Atomically sets a readiness state flag when leadership is obtained, to indicate that server is past its barrier write func (s *Server) setConsistentReadReady() { atomic.StoreInt32(&s.readyForConsistentReads, 1)