Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use bind address for consul checks (solves #1574) #1600

Closed
wants to merge 8 commits into from
13 changes: 13 additions & 0 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,16 @@ func (a *Agent) setupServer() error {
},
},
}
// Resolve ServiceCheck addresses
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you pull these into three methods, getHTTPAddr(preferBind bool), getRPCAddr(preferBind bool) and getSerfAddr(preferBind bool) and use those methods for the service and check.

https://github.com/hashicorp/nomad/blob/master/command/agent/agent.go#L175-L188

Then add a config option to the Consul config checks_use_advertise bool. This will default to false, but if people want the checks to use the advertise they can set it to true.

Please add tests and documentation to the website

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,
Expand Down Expand Up @@ -471,6 +481,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,
})
Expand Down