diff --git a/client/config/config.go b/client/config/config.go index 65b4affd3..6cdb11de3 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -134,7 +134,7 @@ func DefaultConfig() *Config { ConsulConfig: &config.ConsulConfig{ ServerServiceName: "nomad", ClientServiceName: "nomad-client", - AutoRegister: true, + AutoAdvertise: true, Timeout: 5 * time.Second, }, LogOutput: os.Stderr, diff --git a/command/agent/agent.go b/command/agent/agent.go index d2359fedb..d85f40e35 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -76,7 +76,7 @@ func NewAgent(config *Config, logOutput io.Writer) (*Agent, error) { // The Nomad Agent runs the consul.Syncer regardless of whether or not the // Agent is running in Client or Server mode (or both), and regardless of - // the consul.auto_register parameter. The Client and Server both reuse the + // the consul.auto_advertise parameter. The Client and Server both reuse the // same consul.Syncer instance. This Syncer task periodically executes // callbacks that update Consul. The reason the Syncer is always running is // because one of the callbacks is attempts to self-bootstrap Nomad using @@ -230,6 +230,12 @@ func (a *Agent) serverConfig() (*nomad.Config, error) { conf.HeartbeatGrace = dur } + if a.config.Consul.AutoAdvertise && a.config.Consul.ServerServiceName == "" { + return nil, fmt.Errorf("server_service_name must be set when auto_advertise is enabled") + } + + // conf.ConsulConfig = a.config.Consul + return conf, nil } @@ -333,6 +339,10 @@ func (a *Agent) clientConfig() (*clientconfig.Config, error) { conf.Version = fmt.Sprintf("%s%s", a.config.Version, a.config.VersionPrerelease) conf.Revision = a.config.Revision + if a.config.Consul.AutoAdvertise && a.config.Consul.ClientServiceName == "" { + return nil, fmt.Errorf("client_service_name must be set when auto_advertise is enabled") + } + conf.ConsulConfig = a.config.Consul conf.StatsCollectionInterval = a.config.Client.StatsConfig.collectionInterval @@ -360,7 +370,7 @@ func (a *Agent) setupServer() error { a.server = server // Create the Nomad Server services for Consul - if a.config.Consul.AutoRegister && a.config.Consul.ServerServiceName != "" { + if a.config.Consul.AutoAdvertise { httpServ := &structs.Service{ Name: a.config.Consul.ServerServiceName, PortLabel: a.serverHTTPAddr, @@ -413,7 +423,7 @@ func (a *Agent) setupClient() error { a.client = client // Create the Nomad Client services for Consul - if a.config.Consul.AutoRegister && a.config.Consul.ClientServiceName != "" { + if a.config.Consul.AutoAdvertise { httpServ := &structs.Service{ Name: a.config.Consul.ClientServiceName, PortLabel: a.clientHTTPAddr, diff --git a/command/agent/config.go b/command/agent/config.go index 091e37684..59259f7e2 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -362,7 +362,7 @@ func DevConfig() *Config { conf.DevMode = true conf.EnableDebug = true conf.DisableAnonymousSignature = true - conf.Consul.AutoRegister = true + conf.Consul.AutoAdvertise = true if runtime.GOOS == "darwin" { conf.Client.NetworkInterface = "lo0" } else if runtime.GOOS == "linux" { @@ -393,7 +393,7 @@ func DefaultConfig() *Config { Consul: &config.ConsulConfig{ ServerServiceName: "nomad", ClientServiceName: "nomad-client", - AutoRegister: true, + AutoAdvertise: true, Timeout: 5 * time.Second, }, Client: &ClientConfig{ diff --git a/command/agent/config_parse.go b/command/agent/config_parse.go index 873752c01..f62cca373 100644 --- a/command/agent/config_parse.go +++ b/command/agent/config_parse.go @@ -600,7 +600,7 @@ func parseConsulConfig(result **config.ConsulConfig, list *ast.ObjectList) error valid := []string{ "address", "auth", - "auto_register", + "auto_advertise", "ca_file", "cert_file", "client_auto_join", diff --git a/nomad/structs/config/consul.go b/nomad/structs/config/consul.go index cccb91903..c83eae7aa 100644 --- a/nomad/structs/config/consul.go +++ b/nomad/structs/config/consul.go @@ -24,9 +24,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"` + // AutoAdvertise determines if this Nomad Agent will advertise its + // services via Consul. When true, Nomad Agent will register + // services with Consul. + AutoAdvertise bool `mapstructure:"auto_advertise"` // Addr is the address of the local Consul agent Addr string `mapstructure:"address"` @@ -76,8 +77,8 @@ func (a *ConsulConfig) Merge(b *ConsulConfig) *ConsulConfig { if b.ClientServiceName != "" { result.ClientServiceName = b.ClientServiceName } - if b.AutoRegister { - result.AutoRegister = true + if b.AutoAdvertise { + result.AutoAdvertise = true } if b.Addr != "" { result.Addr = b.Addr