From c0ff73251323d3243dbc2b0218ed44335e13b9da Mon Sep 17 00:00:00 2001 From: Evan Gilman Date: Mon, 15 Aug 2016 16:15:03 -0700 Subject: [PATCH 1/8] Use bind address for consul service checks --- command/agent/agent.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/command/agent/agent.go b/command/agent/agent.go index 49a28cac8..510c6482e 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -434,6 +434,16 @@ func (a *Agent) setupServer() error { }, }, } + // Resolve ServiceCheck addresses + if a.config.Addresses.HTTP != "" && a.config.Addresses.HTTP != "0.0.0.0" { + httpServ.Checks[0].PortLabel = net.JoinHostPort(a.config.Addresses.HTTP, strconv.Itoa(a.config.Ports.HTTP)) + } + if a.config.Addresses.RPC != "" && a.config.Addresses.RPC != "0.0.0.0" { + rpcServ.Checks[0].PortLabel = net.JoinHostPort(a.config.Addresses.RPC, strconv.Itoa(a.config.Ports.RPC)) + } + if a.config.Addresses.Serf != "" && a.config.Addresses.Serf != "0.0.0.0" { + serfServ.Checks[0].PortLabel = net.JoinHostPort(a.config.Addresses.Serf, strconv.Itoa(a.config.Ports.Serf)) + } a.consulSyncer.SetServices(consul.ServerDomain, map[consul.ServiceKey]*structs.Service{ consul.GenerateServiceKey(httpServ): httpServ, consul.GenerateServiceKey(rpcServ): rpcServ, From 06909d2465e75f492adc221ef9bdf401f514462c Mon Sep 17 00:00:00 2001 From: Evan Gilman Date: Tue, 16 Aug 2016 12:32:53 -0700 Subject: [PATCH 2/8] Use bind address for consul healtchecks in nomad client too --- command/agent/agent.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/command/agent/agent.go b/command/agent/agent.go index 510c6482e..14b863f18 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -521,6 +521,9 @@ func (a *Agent) setupClient() error { }, }, } + if a.config.Addresses.HTTP != "" && a.config.Addresses.HTTP != "0.0.0.0" { + httpServ.Checks[0].PortLabel = net.JoinHostPort(a.config.Addresses.HTTP, strconv.Itoa(a.config.Ports.HTTP)) + } a.consulSyncer.SetServices(consul.ClientDomain, map[consul.ServiceKey]*structs.Service{ consul.GenerateServiceKey(httpServ): httpServ, }) From de33949df85deceef231cae514ae8a91cef13aa9 Mon Sep 17 00:00:00 2001 From: Evan Gilman Date: Fri, 2 Sep 2016 16:23:45 -0700 Subject: [PATCH 3/8] Add address selector methods to the agent --- command/agent/agent.go | 251 +++++++++++++---------- command/agent/agent_test.go | 17 +- command/agent/config.go | 3 + command/agent/http.go | 6 +- website/source/docs/agent/config.html.md | 4 + 5 files changed, 172 insertions(+), 109 deletions(-) diff --git a/command/agent/agent.go b/command/agent/agent.go index 14b863f18..05f777933 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -152,74 +152,37 @@ func (a *Agent) serverConfig() (*nomad.Config, error) { } // Set up the bind addresses - if addr := a.config.BindAddr; addr != "" { - conf.RPCAddr.IP = net.ParseIP(addr) - conf.SerfConfig.MemberlistConfig.BindAddr = addr - } - if addr := a.config.Addresses.RPC; addr != "" { - conf.RPCAddr.IP = net.ParseIP(addr) - } - - if addr := a.config.Addresses.Serf; addr != "" { - conf.SerfConfig.MemberlistConfig.BindAddr = addr - } - - // Set up the ports - if port := a.config.Ports.RPC; port != 0 { - conf.RPCAddr.Port = port - } - if port := a.config.Ports.Serf; port != 0 { - conf.SerfConfig.MemberlistConfig.BindPort = port - } - - // Resolve the Server's HTTP Address - if a.config.AdvertiseAddrs.HTTP != "" { - a.serverHTTPAddr = a.config.AdvertiseAddrs.HTTP - } else if a.config.Addresses.HTTP != "" { - a.serverHTTPAddr = net.JoinHostPort(a.config.Addresses.HTTP, strconv.Itoa(a.config.Ports.HTTP)) - } else if a.config.BindAddr != "" { - a.serverHTTPAddr = net.JoinHostPort(a.config.BindAddr, strconv.Itoa(a.config.Ports.HTTP)) - } else { - a.serverHTTPAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(a.config.Ports.HTTP)) - } - addr, err := net.ResolveTCPAddr("tcp", a.serverHTTPAddr) + rpcAddr, err := a.getRPCAddr(true) if err != nil { - return nil, fmt.Errorf("error resolving HTTP addr %+q: %v", a.serverHTTPAddr, err) + return nil, err } - a.serverHTTPAddr = net.JoinHostPort(addr.IP.String(), strconv.Itoa(addr.Port)) - - // Resolve the Server's RPC Address - if a.config.AdvertiseAddrs.RPC != "" { - a.serverRPCAddr = a.config.AdvertiseAddrs.RPC - } else if a.config.Addresses.RPC != "" { - a.serverRPCAddr = net.JoinHostPort(a.config.Addresses.RPC, strconv.Itoa(a.config.Ports.RPC)) - } else if a.config.BindAddr != "" { - a.serverRPCAddr = net.JoinHostPort(a.config.BindAddr, strconv.Itoa(a.config.Ports.RPC)) - } else { - a.serverRPCAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(a.config.Ports.RPC)) - } - addr, err = net.ResolveTCPAddr("tcp", a.serverRPCAddr) + serfAddr, err := a.getSerfAddr(true) if err != nil { - return nil, fmt.Errorf("error resolving RPC addr %+q: %v", a.serverRPCAddr, err) + return nil, err } - a.serverRPCAddr = net.JoinHostPort(addr.IP.String(), strconv.Itoa(addr.Port)) + conf.RPCAddr.Port = rpcAddr.Port + conf.RPCAddr.IP = rpcAddr.IP + conf.SerfConfig.MemberlistConfig.BindPort = serfAddr.Port + conf.SerfConfig.MemberlistConfig.BindAddr = serfAddr.IP.String() - // Resolve the Server's Serf Address - if a.config.AdvertiseAddrs.Serf != "" { - a.serverSerfAddr = a.config.AdvertiseAddrs.Serf - } else if a.config.Addresses.Serf != "" { - a.serverSerfAddr = net.JoinHostPort(a.config.Addresses.Serf, strconv.Itoa(a.config.Ports.Serf)) - } else if a.config.BindAddr != "" { - a.serverSerfAddr = net.JoinHostPort(a.config.BindAddr, strconv.Itoa(a.config.Ports.Serf)) - } else { - a.serverSerfAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(a.config.Ports.Serf)) - } - addr, err = net.ResolveTCPAddr("tcp", a.serverSerfAddr) + // Set up the advertise addresses + httpAddr, err := a.getHTTPAddr(false) if err != nil { - return nil, fmt.Errorf("error resolving Serf addr %+q: %v", a.serverSerfAddr, err) + return nil, err } - a.serverSerfAddr = net.JoinHostPort(addr.IP.String(), strconv.Itoa(addr.Port)) + rpcAddr, err = a.getRPCAddr(false) + if err != nil { + return nil, err + } + serfAddr, err = a.getSerfAddr(false) + if err != nil { + return nil, err + } + a.serverHTTPAddr = net.JoinHostPort(httpAddr.IP.String(), strconv.Itoa(httpAddr.Port)) + a.serverRPCAddr = net.JoinHostPort(rpcAddr.IP.String(), strconv.Itoa(rpcAddr.Port)) + a.serverSerfAddr = net.JoinHostPort(serfAddr.IP.String(), strconv.Itoa(serfAddr.Port)) + // Set up gc threshold and heartbeat grace period if gcThreshold := a.config.Server.NodeGCThreshold; gcThreshold != "" { dur, err := time.ParseDuration(gcThreshold) if err != nil { @@ -317,22 +280,11 @@ func (a *Agent) clientConfig() (*clientconfig.Config, error) { conf.Node.Meta = a.config.Client.Meta conf.Node.NodeClass = a.config.Client.NodeClass - // Resolve the Client's HTTP address - if a.config.AdvertiseAddrs.HTTP != "" { - a.clientHTTPAddr = a.config.AdvertiseAddrs.HTTP - } else if a.config.Addresses.HTTP != "" { - a.clientHTTPAddr = net.JoinHostPort(a.config.Addresses.HTTP, strconv.Itoa(a.config.Ports.HTTP)) - } else if a.config.BindAddr != "" { - a.clientHTTPAddr = net.JoinHostPort(a.config.BindAddr, strconv.Itoa(a.config.Ports.HTTP)) - } else { - a.clientHTTPAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(a.config.Ports.HTTP)) - } - addr, err := net.ResolveTCPAddr("tcp", a.clientHTTPAddr) + // Set up the HTTP advertise address + httpAddr, err := a.selectAddr(a.getHTTPAddr, false) if err != nil { - return nil, fmt.Errorf("error resolving HTTP addr %+q: %v", a.clientHTTPAddr, err) + return nil, err } - httpAddr := net.JoinHostPort(addr.IP.String(), strconv.Itoa(addr.Port)) - conf.Node.HTTPAddr = httpAddr a.clientHTTPAddr = httpAddr @@ -392,6 +344,20 @@ func (a *Agent) setupServer() error { } a.server = server + // Resolve consul check addresses. Always use advertise address for services + httpCheckAddr, err := a.selectAddr(a.getHTTPAddr, !a.config.ChecksUseAdvertise) + if err != nil { + return err + } + rpcCheckAddr, err := a.selectAddr(a.getRPCAddr, !a.config.ChecksUseAdvertise) + if err != nil { + return err + } + serfCheckAddr, err := a.selectAddr(a.getSerfAddr, !a.config.ChecksUseAdvertise) + if err != nil { + return err + } + // Create the Nomad Server services for Consul // TODO re-introduce HTTP/S checks when Consul 0.7.1 comes out if a.config.Consul.AutoAdvertise { @@ -401,10 +367,11 @@ func (a *Agent) setupServer() error { Tags: []string{consul.ServiceTagHTTP}, Checks: []*structs.ServiceCheck{ &structs.ServiceCheck{ - Name: "Nomad Server HTTP Check", - Type: "tcp", - Interval: serverHttpCheckInterval, - Timeout: serverHttpCheckTimeout, + Name: "Nomad Server HTTP Check", + Type: "tcp", + Interval: serverHttpCheckInterval, + Timeout: serverHttpCheckTimeout, + PortLabel: httpCheckAddr, }, }, } @@ -414,10 +381,11 @@ func (a *Agent) setupServer() error { Tags: []string{consul.ServiceTagRPC}, Checks: []*structs.ServiceCheck{ &structs.ServiceCheck{ - Name: "Nomad Server RPC Check", - Type: "tcp", - Interval: serverRpcCheckInterval, - Timeout: serverRpcCheckTimeout, + Name: "Nomad Server RPC Check", + Type: "tcp", + Interval: serverRpcCheckInterval, + Timeout: serverRpcCheckTimeout, + PortLabel: rpcCheckAddr, }, }, } @@ -427,23 +395,15 @@ func (a *Agent) setupServer() error { Tags: []string{consul.ServiceTagSerf}, Checks: []*structs.ServiceCheck{ &structs.ServiceCheck{ - Name: "Nomad Server Serf Check", - Type: "tcp", - Interval: serverSerfCheckInterval, - Timeout: serverSerfCheckTimeout, + Name: "Nomad Server Serf Check", + Type: "tcp", + Interval: serverSerfCheckInterval, + Timeout: serverSerfCheckTimeout, + PortLabel: serfCheckAddr, }, }, } - // Resolve ServiceCheck addresses - if a.config.Addresses.HTTP != "" && a.config.Addresses.HTTP != "0.0.0.0" { - httpServ.Checks[0].PortLabel = net.JoinHostPort(a.config.Addresses.HTTP, strconv.Itoa(a.config.Ports.HTTP)) - } - if a.config.Addresses.RPC != "" && a.config.Addresses.RPC != "0.0.0.0" { - rpcServ.Checks[0].PortLabel = net.JoinHostPort(a.config.Addresses.RPC, strconv.Itoa(a.config.Ports.RPC)) - } - if a.config.Addresses.Serf != "" && a.config.Addresses.Serf != "0.0.0.0" { - serfServ.Checks[0].PortLabel = net.JoinHostPort(a.config.Addresses.Serf, strconv.Itoa(a.config.Ports.Serf)) - } + a.consulSyncer.SetServices(consul.ServerDomain, map[consul.ServiceKey]*structs.Service{ consul.GenerateServiceKey(httpServ): httpServ, consul.GenerateServiceKey(rpcServ): rpcServ, @@ -504,6 +464,12 @@ func (a *Agent) setupClient() error { } a.client = client + // Resolve the http check address + httpCheckAddr, err := a.selectAddr(a.getHTTPAddr, !a.config.ChecksUseAdvertise) + if err != nil { + return err + } + // Create the Nomad Client services for Consul // TODO think how we can re-introduce HTTP/S checks when Consul 0.7.1 comes // out @@ -514,16 +480,14 @@ func (a *Agent) setupClient() error { Tags: []string{consul.ServiceTagHTTP}, Checks: []*structs.ServiceCheck{ &structs.ServiceCheck{ - Name: "Nomad Client HTTP Check", - Type: "tcp", - Interval: clientHttpCheckInterval, - Timeout: clientHttpCheckTimeout, + Name: "Nomad Client HTTP Check", + Type: "tcp", + Interval: clientHttpCheckInterval, + Timeout: clientHttpCheckTimeout, + PortLabel: httpCheckAddr, }, }, } - if a.config.Addresses.HTTP != "" && a.config.Addresses.HTTP != "0.0.0.0" { - httpServ.Checks[0].PortLabel = net.JoinHostPort(a.config.Addresses.HTTP, strconv.Itoa(a.config.Ports.HTTP)) - } a.consulSyncer.SetServices(consul.ClientDomain, map[consul.ServiceKey]*structs.Service{ consul.GenerateServiceKey(httpServ): httpServ, }) @@ -532,6 +496,87 @@ func (a *Agent) setupClient() error { return nil } +// Defines the selector interface +type addrSelector func(bool) (*net.TCPAddr, error) + +// Choose the right address given a selector, and return it as a PortLabel +func (a *Agent) selectAddr(selector addrSelector, preferBind bool) (string, error) { + addr, err := selector(preferBind) + if err != nil { + return "", err + } + + if preferBind && strings.HasPrefix(addr.IP.String(), "0.0.0.0:") { + addr, err = selector(false) + if err != nil { + return "", err + } + } + + address := net.JoinHostPort(addr.IP.String(), strconv.Itoa(addr.Port)) + return address, nil +} + +// HTTP address selector +func (a *Agent) getHTTPAddr(returnBind bool) (*net.TCPAddr, error) { + var serverAddr string + if a.config.AdvertiseAddrs.HTTP != "" && !returnBind { + serverAddr = a.config.AdvertiseAddrs.HTTP + } else if a.config.Addresses.HTTP != "" { + serverAddr = net.JoinHostPort(a.config.Addresses.HTTP, strconv.Itoa(a.config.Ports.HTTP)) + } else if a.config.BindAddr != "" { + serverAddr = net.JoinHostPort(a.config.BindAddr, strconv.Itoa(a.config.Ports.HTTP)) + } else { + serverAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(a.config.Ports.HTTP)) + } + + addr, err := net.ResolveTCPAddr("tcp", serverAddr) + if err != nil { + return nil, fmt.Errorf("error resolving HTTP addr %+q: %v", serverAddr, err) + } + return addr, nil +} + +// RPC address selector +func (a *Agent) getRPCAddr(returnBind bool) (*net.TCPAddr, error) { + var serverAddr string + if a.config.AdvertiseAddrs.RPC != "" && !returnBind { + serverAddr = a.config.AdvertiseAddrs.RPC + } else if a.config.Addresses.RPC != "" { + serverAddr = net.JoinHostPort(a.config.Addresses.RPC, strconv.Itoa(a.config.Ports.RPC)) + } else if a.config.BindAddr != "" { + serverAddr = net.JoinHostPort(a.config.BindAddr, strconv.Itoa(a.config.Ports.RPC)) + } else { + serverAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(a.config.Ports.RPC)) + } + + addr, err := net.ResolveTCPAddr("tcp", serverAddr) + if err != nil { + return nil, fmt.Errorf("error resolving RPC addr %+q: %v", serverAddr, err) + } + return addr, nil +} + +// Serf address selector +func (a *Agent) getSerfAddr(returnBind bool) (*net.TCPAddr, error) { + var serverAddr string + if a.config.AdvertiseAddrs.Serf != "" && !returnBind { + serverAddr = a.config.AdvertiseAddrs.Serf + } else if a.config.Addresses.Serf != "" { + serverAddr = net.JoinHostPort(a.config.Addresses.Serf, strconv.Itoa(a.config.Ports.Serf)) + } else if a.config.BindAddr != "" { + serverAddr = net.JoinHostPort(a.config.BindAddr, strconv.Itoa(a.config.Ports.Serf)) + } else { + serverAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(a.config.Ports.Serf)) + } + + addr, err := net.ResolveTCPAddr("tcp", serverAddr) + if err != nil { + return nil, fmt.Errorf("error resolving Serf addr %+q: %v", serverAddr, err) + } + return addr, nil +} + // reservePortsForClient reserves a range of ports for the client to use when // it creates various plugins for log collection, executors, drivers, etc func (a *Agent) reservePortsForClient(conf *clientconfig.Config) error { diff --git a/command/agent/agent_test.go b/command/agent/agent_test.go index aeb445d0a..14d13c1c8 100644 --- a/command/agent/agent_test.go +++ b/command/agent/agent_test.go @@ -155,7 +155,9 @@ func TestAgent_ServerConfig(t *testing.T) { conf.Addresses.RPC = "127.0.0.2" conf.Addresses.Serf = "127.0.0.2" conf.Addresses.HTTP = "127.0.0.2" - conf.AdvertiseAddrs.HTTP = "" + conf.AdvertiseAddrs.HTTP = "10.0.0.1" + conf.AdvertiseAddrs.RPC = "" + conf.AdvertiseAddrs.Serf = "10.0.0.2" out, err = a.serverConfig() if err != nil { @@ -167,15 +169,20 @@ func TestAgent_ServerConfig(t *testing.T) { if addr := out.SerfConfig.MemberlistConfig.BindAddr; addr != "127.0.0.2" { t.Fatalf("expect 127.0.0.2, got: %s", addr) } - if addr := a.serverHTTPAddr; addr != "127.0.0.2:4646" { - t.Fatalf("expect 127.0.0.2:4646, got: %s", addr) + if addr := a.serverHTTPAddr; addr != "10.0.0.1:4646" { + t.Fatalf("expect 10.0.0.1:4646, got: %s", addr) } // NOTE: AdvertiseAddr > Addresses > BindAddr > Defaults if addr := a.serverRPCAddr; addr != "127.0.0.1:4001" { t.Fatalf("expect 127.0.0.1:4001, got: %s", addr) } - if addr := a.serverSerfAddr; addr != "127.0.0.1:4000" { - t.Fatalf("expect 127.0.0.1:4000, got: %s", addr) + if addr := a.serverSerfAddr; addr != "10.0.0.2:4000" { + t.Fatalf("expect 10.0.0.2:4000, got: %s", addr) + } + + // It correctly identifies the bind address when requested + if addr := a.selectAddr(a.getHTTPAddr, true); addr != "127.0.0.2:4646" { + t.Fatalf("expect 127.0.0.2:4646, got: %s", addr) } conf.Server.NodeGCThreshold = "42g" diff --git a/command/agent/config.go b/command/agent/config.go index 91e7f2018..be4459e33 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -51,6 +51,9 @@ type Config struct { // AdvertiseAddrs is used to control the addresses we advertise. AdvertiseAddrs *AdvertiseAddrs `mapstructure:"advertise"` + // Specifies that consul checks should use Advertise address instead of bind + ChecksUseAdvertise bool `mapstructure:"checks_use_advertise"` + // Client has our client related settings Client *ClientConfig `mapstructure:"client"` diff --git a/command/agent/http.go b/command/agent/http.go index 7b69ff902..229fe90e1 100644 --- a/command/agent/http.go +++ b/command/agent/http.go @@ -49,7 +49,11 @@ type HTTPServer struct { // NewHTTPServer starts new HTTP server over the agent func NewHTTPServer(agent *Agent, config *Config, logOutput io.Writer) (*HTTPServer, error) { // Start the listener - ln, err := config.Listener("tcp", config.Addresses.HTTP, config.Ports.HTTP) + lnAddr, err := agent.getHTTPAddr(true) + if err != nil { + return nil, err + } + ln, err := config.Listener("tcp", lnAddr.IP.String(), lnAddr.Port) if err != nil { return nil, fmt.Errorf("failed to start HTTP listener: %v", err) } diff --git a/website/source/docs/agent/config.html.md b/website/source/docs/agent/config.html.md index 8b6e79e1f..27d60f66d 100644 --- a/website/source/docs/agent/config.html.md +++ b/website/source/docs/agent/config.html.md @@ -176,6 +176,10 @@ nodes, unless otherwise specified: reachable from all server nodes. It is not required that clients can reach this address. +* `checks_use_advertise`: By default, Nomad will use the configured bind address + as the target for its consul checks. This boolean option allows you to request + that the advertise address be used instead. + * `consul`: The `consul` configuration block changes how Nomad interacts with Consul. Nomad can automatically advertise Nomad services via Consul, and can automatically bootstrap itself using Consul. For more details see the [`consul` From af3de22d4f6ca5645992753b2a3e8637038af388 Mon Sep 17 00:00:00 2001 From: Evan Gilman Date: Sat, 10 Sep 2016 10:53:53 -0700 Subject: [PATCH 4/8] Remove old address advertise config code --- command/agent/agent.go | 20 +++----------------- command/agent/agent_test.go | 2 +- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/command/agent/agent.go b/command/agent/agent.go index 05f777933..f09cacb32 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -134,23 +134,6 @@ func (a *Agent) serverConfig() (*nomad.Config, error) { conf.EnabledSchedulers = a.config.Server.EnabledSchedulers } - // Set up the advertise addrs - if addr := a.config.AdvertiseAddrs.Serf; addr != "" { - serfAddr, err := net.ResolveTCPAddr("tcp", addr) - if err != nil { - return nil, fmt.Errorf("error resolving serf advertise address: %s", err) - } - conf.SerfConfig.MemberlistConfig.AdvertiseAddr = serfAddr.IP.String() - conf.SerfConfig.MemberlistConfig.AdvertisePort = serfAddr.Port - } - if addr := a.config.AdvertiseAddrs.RPC; addr != "" { - rpcAddr, err := net.ResolveTCPAddr("tcp", addr) - if err != nil { - return nil, fmt.Errorf("error resolving rpc advertise address: %s", err) - } - conf.RPCAdvertise = rpcAddr - } - // Set up the bind addresses rpcAddr, err := a.getRPCAddr(true) if err != nil { @@ -181,6 +164,9 @@ func (a *Agent) serverConfig() (*nomad.Config, error) { a.serverHTTPAddr = net.JoinHostPort(httpAddr.IP.String(), strconv.Itoa(httpAddr.Port)) a.serverRPCAddr = net.JoinHostPort(rpcAddr.IP.String(), strconv.Itoa(rpcAddr.Port)) a.serverSerfAddr = net.JoinHostPort(serfAddr.IP.String(), strconv.Itoa(serfAddr.Port)) + conf.RPCAdvertise = rpcAddr + conf.SerfConfig.MemberlistConfig.AdvertiseAddr = serfAddr.IP.String() + conf.SerfConfig.MemberlistConfig.AdvertisePort = serfAddr.Port // Set up gc threshold and heartbeat grace period if gcThreshold := a.config.Server.NodeGCThreshold; gcThreshold != "" { diff --git a/command/agent/agent_test.go b/command/agent/agent_test.go index 14d13c1c8..5f24403cd 100644 --- a/command/agent/agent_test.go +++ b/command/agent/agent_test.go @@ -181,7 +181,7 @@ func TestAgent_ServerConfig(t *testing.T) { } // It correctly identifies the bind address when requested - if addr := a.selectAddr(a.getHTTPAddr, true); addr != "127.0.0.2:4646" { + if addr, err := a.selectAddr(a.getHTTPAddr, true); addr != "127.0.0.2:4646" || err != nil { t.Fatalf("expect 127.0.0.2:4646, got: %s", addr) } From 7511490c12fcf87799b7d820601a53413a49d8dd Mon Sep 17 00:00:00 2001 From: Evan Gilman Date: Sun, 11 Sep 2016 11:02:11 -0700 Subject: [PATCH 5/8] Add more address selector tests --- command/agent/agent.go | 2 +- command/agent/agent_test.go | 48 ++++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/command/agent/agent.go b/command/agent/agent.go index f09cacb32..5169ceffe 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -492,7 +492,7 @@ func (a *Agent) selectAddr(selector addrSelector, preferBind bool) (string, erro return "", err } - if preferBind && strings.HasPrefix(addr.IP.String(), "0.0.0.0:") { + if preferBind && addr.IP.String() == "0.0.0.0" { addr, err = selector(false) if err != nil { return "", err diff --git a/command/agent/agent_test.go b/command/agent/agent_test.go index 5f24403cd..e2b236b2a 100644 --- a/command/agent/agent_test.go +++ b/command/agent/agent_test.go @@ -98,7 +98,7 @@ func TestAgent_ServerConfig(t *testing.T) { // Returns error on bad serf addr conf.AdvertiseAddrs.Serf = "nope" _, err := a.serverConfig() - if err == nil || !strings.Contains(err.Error(), "serf advertise") { + if err == nil || !strings.Contains(err.Error(), "error resolving Serf addr") { t.Fatalf("expected serf address error, got: %#v", err) } conf.AdvertiseAddrs.Serf = "127.0.0.1:4000" @@ -106,7 +106,7 @@ func TestAgent_ServerConfig(t *testing.T) { // Returns error on bad rpc addr conf.AdvertiseAddrs.RPC = "nope" _, err = a.serverConfig() - if err == nil || !strings.Contains(err.Error(), "rpc advertise") { + if err == nil || !strings.Contains(err.Error(), "error resolving RPC addr") { t.Fatalf("expected rpc address error, got: %#v", err) } conf.AdvertiseAddrs.RPC = "127.0.0.1:4001" @@ -155,9 +155,9 @@ func TestAgent_ServerConfig(t *testing.T) { conf.Addresses.RPC = "127.0.0.2" conf.Addresses.Serf = "127.0.0.2" conf.Addresses.HTTP = "127.0.0.2" - conf.AdvertiseAddrs.HTTP = "10.0.0.1" + conf.AdvertiseAddrs.HTTP = "10.0.0.10:4646" conf.AdvertiseAddrs.RPC = "" - conf.AdvertiseAddrs.Serf = "10.0.0.2" + conf.AdvertiseAddrs.Serf = "10.0.0.12:4004" out, err = a.serverConfig() if err != nil { @@ -169,22 +169,48 @@ func TestAgent_ServerConfig(t *testing.T) { if addr := out.SerfConfig.MemberlistConfig.BindAddr; addr != "127.0.0.2" { t.Fatalf("expect 127.0.0.2, got: %s", addr) } - if addr := a.serverHTTPAddr; addr != "10.0.0.1:4646" { - t.Fatalf("expect 10.0.0.1:4646, got: %s", addr) + if addr := a.serverHTTPAddr; addr != "10.0.0.10:4646" { + t.Fatalf("expect 10.0.0.10:4646, got: %s", addr) } // NOTE: AdvertiseAddr > Addresses > BindAddr > Defaults - if addr := a.serverRPCAddr; addr != "127.0.0.1:4001" { - t.Fatalf("expect 127.0.0.1:4001, got: %s", addr) + if addr := a.serverRPCAddr; addr != "127.0.0.2:4003" { + t.Fatalf("expect 127.0.0.2:4003, got: %s", addr) } - if addr := a.serverSerfAddr; addr != "10.0.0.2:4000" { - t.Fatalf("expect 10.0.0.2:4000, got: %s", addr) + if addr := a.serverSerfAddr; addr != "10.0.0.12:4004" { + t.Fatalf("expect 10.0.0.12:4004, got: %s", addr) } - // It correctly identifies the bind address when requested + // It correctly identifies the bind and advertise address when requested if addr, err := a.selectAddr(a.getHTTPAddr, true); addr != "127.0.0.2:4646" || err != nil { t.Fatalf("expect 127.0.0.2:4646, got: %s", addr) } + if addr, err := a.selectAddr(a.getHTTPAddr, false); addr != "10.0.0.10:4646" || err != nil { + t.Fatalf("expect 10.0.0.10:4646, got: %s", addr) + } + + if addr, err := a.selectAddr(a.getRPCAddr, true); addr != "127.0.0.2:4003" || err != nil { + t.Fatalf("expect 127.0.0.2:4003, got: %s", addr) + } + + if addr, err := a.selectAddr(a.getRPCAddr, false); addr != "127.0.0.2:4003" || err != nil { + t.Fatalf("expect 127.0.0.2:4003, got: %s", addr) + } + + if addr, err := a.selectAddr(a.getSerfAddr, true); addr != "127.0.0.2:4004" || err != nil { + t.Fatalf("expect 127.0.0.2:4004, got: %s", addr) + } + + if addr, err := a.selectAddr(a.getSerfAddr, false); addr != "10.0.0.12:4004" || err != nil { + t.Fatalf("expect 10.0.0.12:4004, got: %s", addr) + } + + // selectAddr does not return 0.0.0.0 with preferBind + conf.Addresses.HTTP = "0.0.0.0" + if addr, err := a.selectAddr(a.getHTTPAddr, true); addr != "10.0.0.10:4646" || err != nil { + t.Fatalf("expect 10.0.0.10:4646, got: %s", addr) + } + conf.Server.NodeGCThreshold = "42g" out, err = a.serverConfig() if err == nil || !strings.Contains(err.Error(), "unknown unit") { From 59489e4e4f953d7ed78d2773618b7a887a9a2457 Mon Sep 17 00:00:00 2001 From: Evan Gilman Date: Sun, 11 Sep 2016 11:40:52 -0700 Subject: [PATCH 6/8] Never return 0.0.0.0 as a non-bind address --- command/agent/agent.go | 56 +++++++++++++++++++++++-------------- command/agent/agent_test.go | 17 +++++++++-- 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/command/agent/agent.go b/command/agent/agent.go index 5169ceffe..f18899418 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -486,6 +486,7 @@ func (a *Agent) setupClient() error { type addrSelector func(bool) (*net.TCPAddr, error) // Choose the right address given a selector, and return it as a PortLabel +// preferBind is a weak preference, and will skip 0.0.0.0 func (a *Agent) selectAddr(selector addrSelector, preferBind bool) (string, error) { addr, err := selector(preferBind) if err != nil { @@ -503,15 +504,22 @@ func (a *Agent) selectAddr(selector addrSelector, preferBind bool) (string, erro return address, nil } -// HTTP address selector +// Address selectors +// Resolve Bind address and Advertise address. Skip 0.0.0.0 unless +// we're looking for the Bind address, since that's the only time +// it's useful func (a *Agent) getHTTPAddr(returnBind bool) (*net.TCPAddr, error) { var serverAddr string - if a.config.AdvertiseAddrs.HTTP != "" && !returnBind { - serverAddr = a.config.AdvertiseAddrs.HTTP - } else if a.config.Addresses.HTTP != "" { - serverAddr = net.JoinHostPort(a.config.Addresses.HTTP, strconv.Itoa(a.config.Ports.HTTP)) - } else if a.config.BindAddr != "" { - serverAddr = net.JoinHostPort(a.config.BindAddr, strconv.Itoa(a.config.Ports.HTTP)) + advertAddr := a.config.AdvertiseAddrs.HTTP + bindAddr := a.config.Addresses.HTTP + globalBindAddr := a.config.BindAddr + + if advertAddr != "" && !returnBind { + serverAddr = advertAddr + } else if bindAddr != "" && !(bindAddr == "0.0.0.0" && !returnBind) { + serverAddr = net.JoinHostPort(bindAddr, strconv.Itoa(a.config.Ports.HTTP)) + } else if globalBindAddr != "" && !(globalBindAddr == "0.0.0.0" && !returnBind) { + serverAddr = net.JoinHostPort(globalBindAddr, strconv.Itoa(a.config.Ports.HTTP)) } else { serverAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(a.config.Ports.HTTP)) } @@ -523,15 +531,18 @@ func (a *Agent) getHTTPAddr(returnBind bool) (*net.TCPAddr, error) { return addr, nil } -// RPC address selector func (a *Agent) getRPCAddr(returnBind bool) (*net.TCPAddr, error) { var serverAddr string - if a.config.AdvertiseAddrs.RPC != "" && !returnBind { - serverAddr = a.config.AdvertiseAddrs.RPC - } else if a.config.Addresses.RPC != "" { - serverAddr = net.JoinHostPort(a.config.Addresses.RPC, strconv.Itoa(a.config.Ports.RPC)) - } else if a.config.BindAddr != "" { - serverAddr = net.JoinHostPort(a.config.BindAddr, strconv.Itoa(a.config.Ports.RPC)) + advertAddr := a.config.AdvertiseAddrs.RPC + bindAddr := a.config.Addresses.RPC + globalBindAddr := a.config.BindAddr + + if advertAddr != "" && !returnBind { + serverAddr = advertAddr + } else if bindAddr != "" && !(bindAddr == "0.0.0.0" && !returnBind) { + serverAddr = net.JoinHostPort(bindAddr, strconv.Itoa(a.config.Ports.RPC)) + } else if globalBindAddr != "" && !(globalBindAddr == "0.0.0.0" && !returnBind) { + serverAddr = net.JoinHostPort(globalBindAddr, strconv.Itoa(a.config.Ports.RPC)) } else { serverAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(a.config.Ports.RPC)) } @@ -543,15 +554,18 @@ func (a *Agent) getRPCAddr(returnBind bool) (*net.TCPAddr, error) { return addr, nil } -// Serf address selector func (a *Agent) getSerfAddr(returnBind bool) (*net.TCPAddr, error) { var serverAddr string - if a.config.AdvertiseAddrs.Serf != "" && !returnBind { - serverAddr = a.config.AdvertiseAddrs.Serf - } else if a.config.Addresses.Serf != "" { - serverAddr = net.JoinHostPort(a.config.Addresses.Serf, strconv.Itoa(a.config.Ports.Serf)) - } else if a.config.BindAddr != "" { - serverAddr = net.JoinHostPort(a.config.BindAddr, strconv.Itoa(a.config.Ports.Serf)) + advertAddr := a.config.AdvertiseAddrs.Serf + bindAddr := a.config.Addresses.Serf + globalBindAddr := a.config.BindAddr + + if advertAddr != "" && !returnBind { + serverAddr = advertAddr + } else if bindAddr != "" && !(bindAddr == "0.0.0.0" && !returnBind) { + serverAddr = net.JoinHostPort(bindAddr, strconv.Itoa(a.config.Ports.Serf)) + } else if globalBindAddr != "" && !(globalBindAddr == "0.0.0.0" && !returnBind) { + serverAddr = net.JoinHostPort(globalBindAddr, strconv.Itoa(a.config.Ports.Serf)) } else { serverAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(a.config.Ports.Serf)) } diff --git a/command/agent/agent_test.go b/command/agent/agent_test.go index e2b236b2a..3022df7c0 100644 --- a/command/agent/agent_test.go +++ b/command/agent/agent_test.go @@ -205,10 +205,21 @@ func TestAgent_ServerConfig(t *testing.T) { t.Fatalf("expect 10.0.0.12:4004, got: %s", addr) } - // selectAddr does not return 0.0.0.0 with preferBind + // We don't resolve 0.0.0.0 unless we're asking for bind conf.Addresses.HTTP = "0.0.0.0" - if addr, err := a.selectAddr(a.getHTTPAddr, true); addr != "10.0.0.10:4646" || err != nil { - t.Fatalf("expect 10.0.0.10:4646, got: %s", addr) + conf.AdvertiseAddrs.HTTP = "" + if addr, err := a.getHTTPAddr(false); addr.IP.String() != "127.0.0.3" || err != nil { + t.Fatalf("expect 127.0.0.3, got: %s", addr.IP.String()) + } + + // We still get 0.0.0.0 when explicitly asking for bind + if addr, err := a.getHTTPAddr(true); addr.IP.String() != "0.0.0.0" || err != nil { + t.Fatalf("expect 0.0.0.0, got: %s", addr.IP.String()) + } + + // selectAddr does not return 0.0.0.0 with preferBind + if addr, err := a.selectAddr(a.getHTTPAddr, true); addr != "127.0.0.3:4646" || err != nil { + t.Fatalf("expect 127.0.0.3:4646, got: %s", addr) } conf.Server.NodeGCThreshold = "42g" From ddf5fb82b5b937fbadb562f64c16c5a0b95a20c9 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Wed, 26 Oct 2016 12:58:36 -0700 Subject: [PATCH 7/8] Small cleanups --- command/agent/agent.go | 95 ++++++++++-------------- command/agent/config.go | 3 - nomad/structs/config/consul.go | 4 + website/source/docs/agent/config.html.md | 8 +- 4 files changed, 48 insertions(+), 62 deletions(-) diff --git a/command/agent/agent.go b/command/agent/agent.go index f18899418..6deeb2342 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -331,15 +331,15 @@ func (a *Agent) setupServer() error { a.server = server // Resolve consul check addresses. Always use advertise address for services - httpCheckAddr, err := a.selectAddr(a.getHTTPAddr, !a.config.ChecksUseAdvertise) + httpCheckAddr, err := a.selectAddr(a.getHTTPAddr, !a.config.Consul.ChecksUseAdvertise) if err != nil { return err } - rpcCheckAddr, err := a.selectAddr(a.getRPCAddr, !a.config.ChecksUseAdvertise) + rpcCheckAddr, err := a.selectAddr(a.getRPCAddr, !a.config.Consul.ChecksUseAdvertise) if err != nil { return err } - serfCheckAddr, err := a.selectAddr(a.getSerfAddr, !a.config.ChecksUseAdvertise) + serfCheckAddr, err := a.selectAddr(a.getSerfAddr, !a.config.Consul.ChecksUseAdvertise) if err != nil { return err } @@ -451,7 +451,7 @@ func (a *Agent) setupClient() error { a.client = client // Resolve the http check address - httpCheckAddr, err := a.selectAddr(a.getHTTPAddr, !a.config.ChecksUseAdvertise) + httpCheckAddr, err := a.selectAddr(a.getHTTPAddr, !a.config.Consul.ChecksUseAdvertise) if err != nil { return err } @@ -485,7 +485,7 @@ func (a *Agent) setupClient() error { // Defines the selector interface type addrSelector func(bool) (*net.TCPAddr, error) -// Choose the right address given a selector, and return it as a PortLabel +// selectAddr returns the right address given a selector, and return it as a PortLabel // preferBind is a weak preference, and will skip 0.0.0.0 func (a *Agent) selectAddr(selector addrSelector, preferBind bool) (string, error) { addr, err := selector(preferBind) @@ -504,75 +504,60 @@ func (a *Agent) selectAddr(selector addrSelector, preferBind bool) (string, erro return address, nil } -// Address selectors -// Resolve Bind address and Advertise address. Skip 0.0.0.0 unless -// we're looking for the Bind address, since that's the only time -// it's useful -func (a *Agent) getHTTPAddr(returnBind bool) (*net.TCPAddr, error) { - var serverAddr string +// getHTTPAddr returns the HTTP address to use based on the clients +// configuration. If bind is true, an address appropriate for binding is +// returned, otherwise an address for advertising is returned. Skip 0.0.0.0 +// unless returning a bind address, since that's the only time it's useful. +func (a *Agent) getHTTPAddr(bind bool) (*net.TCPAddr, error) { advertAddr := a.config.AdvertiseAddrs.HTTP bindAddr := a.config.Addresses.HTTP globalBindAddr := a.config.BindAddr - - if advertAddr != "" && !returnBind { - serverAddr = advertAddr - } else if bindAddr != "" && !(bindAddr == "0.0.0.0" && !returnBind) { - serverAddr = net.JoinHostPort(bindAddr, strconv.Itoa(a.config.Ports.HTTP)) - } else if globalBindAddr != "" && !(globalBindAddr == "0.0.0.0" && !returnBind) { - serverAddr = net.JoinHostPort(globalBindAddr, strconv.Itoa(a.config.Ports.HTTP)) - } else { - serverAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(a.config.Ports.HTTP)) - } - - addr, err := net.ResolveTCPAddr("tcp", serverAddr) - if err != nil { - return nil, fmt.Errorf("error resolving HTTP addr %+q: %v", serverAddr, err) - } - return addr, nil + port := a.config.Ports.HTTP + return pickAddress(bind, globalBindAddr, advertAddr, bindAddr, port, "HTTP") } -func (a *Agent) getRPCAddr(returnBind bool) (*net.TCPAddr, error) { - var serverAddr string +// getRPCAddr returns the HTTP address to use based on the clients +// configuration. If bind is true, an address appropriate for binding is +// returned, otherwise an address for advertising is returned. Skip 0.0.0.0 +// unless returning a bind address, since that's the only time it's useful. +func (a *Agent) getRPCAddr(bind bool) (*net.TCPAddr, error) { advertAddr := a.config.AdvertiseAddrs.RPC bindAddr := a.config.Addresses.RPC globalBindAddr := a.config.BindAddr - - if advertAddr != "" && !returnBind { - serverAddr = advertAddr - } else if bindAddr != "" && !(bindAddr == "0.0.0.0" && !returnBind) { - serverAddr = net.JoinHostPort(bindAddr, strconv.Itoa(a.config.Ports.RPC)) - } else if globalBindAddr != "" && !(globalBindAddr == "0.0.0.0" && !returnBind) { - serverAddr = net.JoinHostPort(globalBindAddr, strconv.Itoa(a.config.Ports.RPC)) - } else { - serverAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(a.config.Ports.RPC)) - } - - addr, err := net.ResolveTCPAddr("tcp", serverAddr) - if err != nil { - return nil, fmt.Errorf("error resolving RPC addr %+q: %v", serverAddr, err) - } - return addr, nil + port := a.config.Ports.RPC + return pickAddress(bind, globalBindAddr, advertAddr, bindAddr, port, "RPC") } -func (a *Agent) getSerfAddr(returnBind bool) (*net.TCPAddr, error) { - var serverAddr string +// getSerfAddr returns the Serf address to use based on the clients +// configuration. If bind is true, an address appropriate for binding is +// returned, otherwise an address for advertising is returned. Skip 0.0.0.0 +// unless returning a bind address, since that's the only time it's useful. +func (a *Agent) getSerfAddr(bind bool) (*net.TCPAddr, error) { advertAddr := a.config.AdvertiseAddrs.Serf bindAddr := a.config.Addresses.Serf globalBindAddr := a.config.BindAddr + port := a.config.Ports.Serf + return pickAddress(bind, globalBindAddr, advertAddr, bindAddr, port, "RPC") +} - if advertAddr != "" && !returnBind { - serverAddr = advertAddr - } else if bindAddr != "" && !(bindAddr == "0.0.0.0" && !returnBind) { - serverAddr = net.JoinHostPort(bindAddr, strconv.Itoa(a.config.Ports.Serf)) - } else if globalBindAddr != "" && !(globalBindAddr == "0.0.0.0" && !returnBind) { - serverAddr = net.JoinHostPort(globalBindAddr, strconv.Itoa(a.config.Ports.Serf)) +// pickAddress is a shared helper to pick the address to either bind to or +// advertise. +func pickAddress(bind bool, globalBindAddr, advertiseAddr, bindAddr string, port int, service string) (*net.TCPAddr, error) { + portConverted := strconv.Itoa(port) + var serverAddr string + if advertiseAddr != "" && !bind { + serverAddr = advertiseAddr + } else if bindAddr != "" && !(bindAddr == "0.0.0.0" && !bind) { + serverAddr = net.JoinHostPort(bindAddr, portConverted) + } else if globalBindAddr != "" && !(globalBindAddr == "0.0.0.0" && !bind) { + serverAddr = net.JoinHostPort(globalBindAddr, portConverted) } else { - serverAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(a.config.Ports.Serf)) + serverAddr = net.JoinHostPort("127.0.0.1", portConverted) } addr, err := net.ResolveTCPAddr("tcp", serverAddr) if err != nil { - return nil, fmt.Errorf("error resolving Serf addr %+q: %v", serverAddr, err) + return nil, fmt.Errorf("error resolving %s addr %+q: %v", service, serverAddr, err) } return addr, nil } diff --git a/command/agent/config.go b/command/agent/config.go index be4459e33..91e7f2018 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -51,9 +51,6 @@ type Config struct { // AdvertiseAddrs is used to control the addresses we advertise. AdvertiseAddrs *AdvertiseAddrs `mapstructure:"advertise"` - // Specifies that consul checks should use Advertise address instead of bind - ChecksUseAdvertise bool `mapstructure:"checks_use_advertise"` - // Client has our client related settings Client *ClientConfig `mapstructure:"client"` diff --git a/nomad/structs/config/consul.go b/nomad/structs/config/consul.go index 86d70bf47..d20e5e419 100644 --- a/nomad/structs/config/consul.go +++ b/nomad/structs/config/consul.go @@ -33,6 +33,10 @@ type ConsulConfig struct { // services with Consul. AutoAdvertise bool `mapstructure:"auto_advertise"` + // ChecksUseAdvertise specifies that Consul checks should use advertise + // address instead of bind address + ChecksUseAdvertise bool `mapstructure:"checks_use_advertise"` + // Addr is the address of the local Consul agent Addr string `mapstructure:"address"` diff --git a/website/source/docs/agent/config.html.md b/website/source/docs/agent/config.html.md index 27d60f66d..f0fe59f22 100644 --- a/website/source/docs/agent/config.html.md +++ b/website/source/docs/agent/config.html.md @@ -176,10 +176,6 @@ nodes, unless otherwise specified: reachable from all server nodes. It is not required that clients can reach this address. -* `checks_use_advertise`: By default, Nomad will use the configured bind address - as the target for its consul checks. This boolean option allows you to request - that the advertise address be used instead. - * `consul`: The `consul` configuration block changes how Nomad interacts with Consul. Nomad can automatically advertise Nomad services via Consul, and can automatically bootstrap itself using Consul. For more details see the [`consul` @@ -302,6 +298,10 @@ integration and are entirely optional. services, each tagged appropriately with either `http` or `rpc` tag. Nomad Servers also advertise a `serf` tagged service. Defaults to `true`. + * `checks_use_advertise`: By default, Nomad will use the configured bind + address as the target for its consul checks. This boolean option allows you + to request that the advertise address be used instead. + * `server_auto_join`: Servers will automatically discover and join other Nomad Servers by searching for the Consul service name defined in the `server_service_name` option. This search only happens if the Server does From c4d8d744c767f8fa3f273f07fa931545d2430a80 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Thu, 27 Oct 2016 11:29:12 -0700 Subject: [PATCH 8/8] Add to valid configs fields --- command/agent/config-test-fixtures/basic.hcl | 9 ++++--- command/agent/config_parse.go | 1 + command/agent/config_parse_test.go | 27 ++++++++++---------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/command/agent/config-test-fixtures/basic.hcl b/command/agent/config-test-fixtures/basic.hcl index f4d5bdef8..3301a837b 100644 --- a/command/agent/config-test-fixtures/basic.hcl +++ b/command/agent/config-test-fixtures/basic.hcl @@ -100,13 +100,14 @@ consul { token = "token1" auth = "username:pass" ssl = true - verify_ssl = false + verify_ssl = true ca_file = "/path/to/ca/file" cert_file = "/path/to/cert/file" key_file = "/path/to/key/file" - server_auto_join = false - client_auto_join = false - auto_advertise = false + server_auto_join = true + client_auto_join = true + auto_advertise = true + checks_use_advertise = true } vault { address = "127.0.0.1:9500" diff --git a/command/agent/config_parse.go b/command/agent/config_parse.go index 64f6cd8be..6f8bbc4a7 100644 --- a/command/agent/config_parse.go +++ b/command/agent/config_parse.go @@ -616,6 +616,7 @@ func parseConsulConfig(result **config.ConsulConfig, list *ast.ObjectList) error "auto_advertise", "ca_file", "cert_file", + "checks_use_advertise", "client_auto_join", "client_service_name", "key_file", diff --git a/command/agent/config_parse_test.go b/command/agent/config_parse_test.go index 14168ce8f..2ece10625 100644 --- a/command/agent/config_parse_test.go +++ b/command/agent/config_parse_test.go @@ -109,19 +109,20 @@ func TestConfig_Parse(t *testing.T) { Endpoint: "127.0.0.1:1234", }, Consul: &config.ConsulConfig{ - ServerServiceName: "nomad", - ClientServiceName: "nomad-client", - Addr: "127.0.0.1:9500", - Token: "token1", - Auth: "username:pass", - EnableSSL: true, - VerifySSL: false, - CAFile: "/path/to/ca/file", - CertFile: "/path/to/cert/file", - KeyFile: "/path/to/key/file", - ServerAutoJoin: false, - ClientAutoJoin: false, - AutoAdvertise: false, + ServerServiceName: "nomad", + ClientServiceName: "nomad-client", + Addr: "127.0.0.1:9500", + Token: "token1", + Auth: "username:pass", + EnableSSL: true, + VerifySSL: true, + CAFile: "/path/to/ca/file", + CertFile: "/path/to/cert/file", + KeyFile: "/path/to/key/file", + ServerAutoJoin: true, + ClientAutoJoin: true, + AutoAdvertise: true, + ChecksUseAdvertise: true, }, Vault: &config.VaultConfig{ Addr: "127.0.0.1:9500",