Advertise the server's RPC endpoint, not its HTTP endpoint.

Rename c.serverRpcAddr to serverRpcAddr.  This will be broken out
into in additional set of services in a subsequent commit.
This commit is contained in:
Sean Chittenden 2016-05-27 00:42:31 -07:00
parent dc78baedfd
commit ac7881226c
No known key found for this signature in database
GPG Key ID: 4EBC9DC16C2E5E16
2 changed files with 16 additions and 11 deletions

View File

@ -38,7 +38,7 @@ type Agent struct {
// consulSyncer registers the Nomad agent with the Consul Agent // consulSyncer registers the Nomad agent with the Consul Agent
consulSyncer *consul.Syncer consulSyncer *consul.Syncer
serverHttpAddr string serverRpcAddr string
clientHttpAddr string clientHttpAddr string
server *nomad.Server server *nomad.Server
@ -166,15 +166,20 @@ func (a *Agent) serverConfig() (*nomad.Config, error) {
conf.SerfConfig.MemberlistConfig.BindPort = port conf.SerfConfig.MemberlistConfig.BindPort = port
} }
if a.config.AdvertiseAddrs.HTTP != "" { if a.config.AdvertiseAddrs.RPC != "" {
a.serverHttpAddr = a.config.AdvertiseAddrs.HTTP a.serverRpcAddr = a.config.AdvertiseAddrs.RPC
} else if a.config.Addresses.HTTP != "" { } else if a.config.Addresses.RPC != "" {
a.serverHttpAddr = fmt.Sprintf("%v:%v", a.config.Addresses.HTTP, a.config.Ports.HTTP) a.serverRpcAddr = fmt.Sprintf("%v:%v", a.config.Addresses.RPC, a.config.Ports.RPC)
} else if a.config.BindAddr != "" { } else if a.config.BindAddr != "" {
a.serverHttpAddr = fmt.Sprintf("%v:%v", a.config.BindAddr, a.config.Ports.HTTP) a.serverRpcAddr = fmt.Sprintf("%v:%v", a.config.BindAddr, a.config.Ports.RPC)
} else { } else {
a.serverHttpAddr = fmt.Sprintf("%v:%v", "127.0.0.1", a.config.Ports.HTTP) a.serverRpcAddr = fmt.Sprintf("%v:%v", "127.0.0.1", a.config.Ports.RPC)
} }
addr, err := net.ResolveTCPAddr("tcp", a.serverRpcAddr)
if err != nil {
return nil, fmt.Errorf("error resolving RPC addr %q: %v:", a.serverRpcAddr, err)
}
a.serverRpcAddr = fmt.Sprintf("%s:%d", addr.IP.String(), addr.Port)
if gcThreshold := a.config.Server.NodeGCThreshold; gcThreshold != "" { if gcThreshold := a.config.Server.NodeGCThreshold; gcThreshold != "" {
dur, err := time.ParseDuration(gcThreshold) dur, err := time.ParseDuration(gcThreshold)
@ -530,7 +535,7 @@ func (a *Agent) syncAgentServicesWithConsul() error {
if a.server != nil && a.config.Consul.ServerServiceName != "" { if a.server != nil && a.config.Consul.ServerServiceName != "" {
serverService := &structs.Service{ serverService := &structs.Service{
Name: a.config.Consul.ServerServiceName, Name: a.config.Consul.ServerServiceName,
PortLabel: a.serverHttpAddr, PortLabel: a.serverRpcAddr,
} }
services = append(services, serverService) services = append(services, serverService)
a.consulSyncer.SetServiceIdentifier("agent-server") a.consulSyncer.SetServiceIdentifier("agent-server")

View File

@ -119,7 +119,7 @@ func TestAgent_ServerConfig(t *testing.T) {
if addr := out.RPCAdvertise; addr.IP.String() != "127.0.0.1" || addr.Port != 4001 { if addr := out.RPCAdvertise; addr.IP.String() != "127.0.0.1" || addr.Port != 4001 {
t.Fatalf("bad rpc advertise addr: %#v", addr) t.Fatalf("bad rpc advertise addr: %#v", addr)
} }
if addr := a.serverHttpAddr; addr != "10.10.11.1:4005" { if addr := a.serverRpcAddr; addr != "10.10.11.1:4005" {
t.Fatalf("expect 10.11.11.1:4005, got: %v", addr) t.Fatalf("expect 10.11.11.1:4005, got: %v", addr)
} }
@ -155,7 +155,7 @@ func TestAgent_ServerConfig(t *testing.T) {
if addr := out.SerfConfig.MemberlistConfig.BindAddr; addr != "127.0.0.2" { if addr := out.SerfConfig.MemberlistConfig.BindAddr; addr != "127.0.0.2" {
t.Fatalf("expect 127.0.0.2, got: %s", addr) t.Fatalf("expect 127.0.0.2, got: %s", addr)
} }
if addr := a.serverHttpAddr; addr != "127.0.0.2:4646" { if addr := a.serverRpcAddr; addr != "127.0.0.2:4646" {
t.Fatalf("expect 127.0.0.3:4646, got: %s", addr) t.Fatalf("expect 127.0.0.3:4646, got: %s", addr)
} }
@ -195,7 +195,7 @@ func TestAgent_ServerConfig(t *testing.T) {
if addr := out.SerfConfig.MemberlistConfig.BindAddr; addr != "127.0.0.3" { if addr := out.SerfConfig.MemberlistConfig.BindAddr; addr != "127.0.0.3" {
t.Fatalf("expect 127.0.0.3, got: %s", addr) t.Fatalf("expect 127.0.0.3, got: %s", addr)
} }
if addr := a.serverHttpAddr; addr != "127.0.0.3:4646" { if addr := a.serverRpcAddr; addr != "127.0.0.3:4646" {
t.Fatalf("expect 127.0.0.3:4646, got: %s", addr) t.Fatalf("expect 127.0.0.3:4646, got: %s", addr)
} }