From df9d2561324656a68640ec35dfad2c25c8576f72 Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Fri, 13 May 2016 10:19:49 -0700 Subject: [PATCH] Making Nomad register services with consul in dev mode --- client/consul/sync.go | 3 ++- command/agent/agent.go | 3 ++- command/agent/config.go | 9 +++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/client/consul/sync.go b/client/consul/sync.go index e6d857eb1..99255624a 100644 --- a/client/consul/sync.go +++ b/client/consul/sync.go @@ -411,7 +411,8 @@ func (c *ConsulService) performSync() error { func (c *ConsulService) filterConsulServices(srvcs map[string]*consul.AgentService) map[string]*consul.AgentService { nomadServices := make(map[string]*consul.AgentService) for _, srv := range srvcs { - if strings.HasPrefix(srv.ID, structs.NomadConsulPrefix) { + if strings.HasPrefix(srv.ID, structs.NomadConsulPrefix) && + !strings.HasPrefix(srv.ID, fmt.Sprintf("%s-%s", structs.NomadConsulPrefix, "agent")) { nomadServices[srv.ID] = srv } } diff --git a/command/agent/agent.go b/command/agent/agent.go index 31a7f5acd..d2aab1c1b 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -69,7 +69,8 @@ func NewAgent(config *Config, logOutput io.Writer) (*Agent, error) { } if err := a.syncAgentServicesWithConsul(a.serverHTTPAddr, a.clientHTTPAddr); err != nil { a.logger.Printf("[ERR] agent: unable to sync agent services with consul: %v", err) - } else { + } + if a.consulService != nil { go a.consulService.PeriodicSync() } return a, nil diff --git a/command/agent/config.go b/command/agent/config.go index c58345b5c..7a0a47cba 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -140,6 +140,10 @@ type ConsulConfig struct { // clients with Consul ClientServiceName string `mapstructure:"client_service_name"` + // AutoRegister determines if Nomad will register the Nomad client and + // server agents with Consul + AutoRegister bool `mapstructure:"auto_register"` + // Addr is the address of the local Consul agent Addr string `mapstructure:"addr"` @@ -419,6 +423,11 @@ func DefaultConfig() *Config { Addresses: &Addresses{}, AdvertiseAddrs: &AdvertiseAddrs{}, Atlas: &AtlasConfig{}, + ConsulConfig: &ConsulConfig{ + ServerServiceName: "nomad-server", + ClientServiceName: "nomad-client", + AutoRegister: true, + }, Client: &ClientConfig{ Enabled: false, NetworkSpeed: 100,