config: drop advertise_addrs

Fixes #3516
This commit is contained in:
Frank Schroeder 2017-09-29 11:35:51 +02:00 committed by Frank Schröder
parent 9b3481265a
commit 42f8ff7b3c
3 changed files with 70 additions and 61 deletions

View File

@ -371,9 +371,9 @@ func (b *Builder) Build() (rt RuntimeConfig, err error) {
// 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 := b.makeTCPAddr(b.expandFirstIP("advertise_addresses.rpc", c.AdvertiseAddrs.RPC), advertiseAddrLAN, serverPort)
serfAdvertiseAddrLAN := b.makeTCPAddr(b.expandFirstIP("advertise_addresses.serf_lan", c.AdvertiseAddrs.SerfLAN), advertiseAddrLAN, serfPortLAN)
serfAdvertiseAddrWAN := b.makeTCPAddr(b.expandFirstIP("advertise_addresses.serf_wan", c.AdvertiseAddrs.SerfWAN), advertiseAddrWAN, serfPortWAN)
rpcAdvertiseAddr := &net.TCPAddr{IP: advertiseAddrLAN.IP, Port: serverPort}
serfAdvertiseAddrLAN := &net.TCPAddr{IP: advertiseAddrLAN.IP, Port: serfPortLAN}
serfAdvertiseAddrWAN := &net.TCPAddr{IP: advertiseAddrWAN.IP, Port: serfPortWAN}
// determine client addresses
clientAddrs := b.expandIPs("client_addr", c.ClientAddr)
@ -683,15 +683,6 @@ func (b *Builder) Validate(rt RuntimeConfig) error {
if ipaddr.IsAny(rt.AdvertiseAddrWAN.IP) {
return fmt.Errorf("Advertise WAN address cannot be 0.0.0.0, :: or [::]")
}
if ipaddr.IsAny(rt.RPCAdvertiseAddr) {
return fmt.Errorf("advertise_addrs.rpc cannot be 0.0.0.0, :: or [::]")
}
if ipaddr.IsAny(rt.SerfAdvertiseAddrLAN) {
return fmt.Errorf("advertise_addrs.serf_lan cannot be 0.0.0.0, :: or [::]")
}
if ipaddr.IsAny(rt.SerfAdvertiseAddrWAN) {
return fmt.Errorf("advertise_addrs.serf_wan cannot be 0.0.0.0, :: or [::]")
}
if err := b.validateSegments(rt); err != nil {
return err
}

View File

@ -136,7 +136,6 @@ type Config struct {
Addresses Addresses `json:"addresses,omitempty" hcl:"addresses" mapstructure:"addresses"`
AdvertiseAddrLAN *string `json:"advertise_addr,omitempty" hcl:"advertise_addr" mapstructure:"advertise_addr"`
AdvertiseAddrWAN *string `json:"advertise_addr_wan,omitempty" hcl:"advertise_addr_wan" mapstructure:"advertise_addr_wan"`
AdvertiseAddrs AdvertiseAddrsConfig `json:"advertise_addrs,omitempty" hcl:"advertise_addrs" mapstructure:"advertise_addrs"`
Autopilot Autopilot `json:"autopilot,omitempty" hcl:"autopilot" mapstructure:"autopilot"`
BindAddr *string `json:"bind_addr,omitempty" hcl:"bind_addr" mapstructure:"bind_addr"`
Bootstrap *bool `json:"bootstrap,omitempty" hcl:"bootstrap" mapstructure:"bootstrap"`

View File

@ -893,22 +893,78 @@ func TestConfigFlagsAndEdgecases(t *testing.T) {
},
},
{
desc: "serf advertise address lan template",
desc: "advertise address lan with ports",
flags: []string{`-data-dir=` + dataDir},
json: []string{`{ "advertise_addrs": { "serf_lan": "{{ printf \"1.2.3.4\" }}" } }`},
hcl: []string{`advertise_addrs = { serf_lan = "{{ printf \"1.2.3.4\" }}" }`},
json: []string{`{
"ports": {
"server": 1000,
"serf_lan": 2000,
"serf_wan": 3000
},
"advertise_addr": "1.2.3.4"
}`},
hcl: []string{`
ports {
server = 1000
serf_lan = 2000
serf_wan = 3000
}
advertise_addr = "1.2.3.4"
`},
patch: func(rt *RuntimeConfig) {
rt.SerfAdvertiseAddrLAN = tcpAddr("1.2.3.4:8301")
rt.AdvertiseAddrLAN = ipAddr("1.2.3.4")
rt.AdvertiseAddrWAN = ipAddr("1.2.3.4")
rt.RPCAdvertiseAddr = tcpAddr("1.2.3.4:1000")
rt.RPCBindAddr = tcpAddr("0.0.0.0:1000")
rt.SerfAdvertiseAddrLAN = tcpAddr("1.2.3.4:2000")
rt.SerfAdvertiseAddrWAN = tcpAddr("1.2.3.4:3000")
rt.SerfBindAddrLAN = tcpAddr("0.0.0.0:2000")
rt.SerfBindAddrWAN = tcpAddr("0.0.0.0:3000")
rt.SerfPortLAN = 2000
rt.SerfPortWAN = 3000
rt.ServerPort = 1000
rt.TaggedAddresses = map[string]string{
"lan": "1.2.3.4",
"wan": "1.2.3.4",
}
rt.DataDir = dataDir
},
},
{
desc: "serf advertise address wan template",
desc: "advertise address wan with ports",
flags: []string{`-data-dir=` + dataDir},
json: []string{`{ "advertise_addrs": { "serf_wan": "{{ printf \"1.2.3.4\" }}" } }`},
hcl: []string{`advertise_addrs = { serf_wan = "{{ printf \"1.2.3.4\" }}" }`},
json: []string{`{
"ports": {
"server": 1000,
"serf_lan": 2000,
"serf_wan": 3000
},
"advertise_addr_wan": "1.2.3.4"
}`},
hcl: []string{`
ports {
server = 1000
serf_lan = 2000
serf_wan = 3000
}
advertise_addr_wan = "1.2.3.4"
`},
patch: func(rt *RuntimeConfig) {
rt.SerfAdvertiseAddrWAN = tcpAddr("1.2.3.4:8302")
rt.AdvertiseAddrLAN = ipAddr("10.0.0.1")
rt.AdvertiseAddrWAN = ipAddr("1.2.3.4")
rt.RPCAdvertiseAddr = tcpAddr("10.0.0.1:1000")
rt.RPCBindAddr = tcpAddr("0.0.0.0:1000")
rt.SerfAdvertiseAddrLAN = tcpAddr("10.0.0.1:2000")
rt.SerfAdvertiseAddrWAN = tcpAddr("1.2.3.4:3000")
rt.SerfBindAddrLAN = tcpAddr("0.0.0.0:2000")
rt.SerfBindAddrWAN = tcpAddr("0.0.0.0:3000")
rt.SerfPortLAN = 2000
rt.SerfPortWAN = 3000
rt.ServerPort = 1000
rt.TaggedAddresses = map[string]string{
"lan": "10.0.0.1",
"wan": "1.2.3.4",
}
rt.DataDir = dataDir
},
},
@ -1397,33 +1453,6 @@ func TestConfigFlagsAndEdgecases(t *testing.T) {
hcl: []string{`advertise_addr_wan = "::"`},
err: "Advertise WAN address cannot be 0.0.0.0, :: or [::]",
},
{
desc: "advertise_addrs.rpc any",
flags: []string{
`-data-dir=` + dataDir,
},
json: []string{`{ "advertise_addrs":{ "rpc": "[::]" } }`},
hcl: []string{`advertise_addrs = { rpc = "[::]" }`},
err: "advertise_addrs.rpc cannot be 0.0.0.0, :: or [::]",
},
{
desc: "advertise_addrs.serf_lan any",
flags: []string{
`-data-dir=` + dataDir,
},
json: []string{`{ "advertise_addrs":{ "serf_lan": "[::]" } }`},
hcl: []string{`advertise_addrs = { serf_lan = "[::]" }`},
err: "advertise_addrs.serf_lan cannot be 0.0.0.0, :: or [::]",
},
{
desc: "advertise_addrs.serf_wan any",
flags: []string{
`-data-dir=` + dataDir,
},
json: []string{`{ "advertise_addrs":{ "serf_wan": "0.0.0.0" } }`},
hcl: []string{`advertise_addrs = { serf_wan = "0.0.0.0" }`},
err: "advertise_addrs.serf_wan cannot be 0.0.0.0, :: or [::]",
},
{
desc: "dns_config.udp_answer_limit invalid",
flags: []string{
@ -1914,11 +1943,6 @@ func TestFullConfig(t *testing.T) {
},
"advertise_addr": "17.99.29.16",
"advertise_addr_wan": "78.63.37.19",
"advertise_addrs": {
"rpc": "28.27.94.38",
"serf_lan": "49.38.36.95",
"serf_wan": "63.38.52.13"
},
"autopilot": {
"cleanup_dead_servers": true,
"disable_upgrade_migration": true,
@ -2334,11 +2358,6 @@ func TestFullConfig(t *testing.T) {
}
advertise_addr = "17.99.29.16"
advertise_addr_wan = "78.63.37.19"
advertise_addrs = {
rpc = "28.27.94.38"
serf_lan = "49.38.36.95"
serf_wan = "63.38.52.13"
}
autopilot = {
cleanup_dead_servers = true
disable_upgrade_migration = true
@ -3022,7 +3041,7 @@ func TestFullConfig(t *testing.T) {
NodeName: "otlLxGaI",
NonVotingServer: true,
PidFile: "43xN80Km",
RPCAdvertiseAddr: tcpAddr("28.27.94.38:3757"),
RPCAdvertiseAddr: tcpAddr("17.99.29.16:3757"),
RPCBindAddr: tcpAddr("16.99.34.17:3757"),
RPCProtocol: 30793,
RPCRateLimit: 12029.43,
@ -3218,8 +3237,8 @@ func TestFullConfig(t *testing.T) {
},
},
},
SerfAdvertiseAddrLAN: tcpAddr("49.38.36.95:8301"),
SerfAdvertiseAddrWAN: tcpAddr("63.38.52.13:8302"),
SerfAdvertiseAddrLAN: tcpAddr("17.99.29.16:8301"),
SerfAdvertiseAddrWAN: tcpAddr("78.63.37.19:8302"),
SerfBindAddrLAN: tcpAddr("99.43.63.15:8301"),
SerfBindAddrWAN: tcpAddr("67.88.33.19:8302"),
SessionTTLMin: 26627 * time.Second,