Merge pull request #1279 from hashicorp/b-rename-reg-to-advertise

Disambiguate `auto_join` from `auto_register`, rename `auto_register` to `auto_advertise`.
This commit is contained in:
Sean Chittenden 2016-06-14 13:09:25 -07:00 committed by GitHub
commit bdbbf2cd2c
5 changed files with 23 additions and 12 deletions

View file

@ -134,7 +134,7 @@ func DefaultConfig() *Config {
ConsulConfig: &config.ConsulConfig{ ConsulConfig: &config.ConsulConfig{
ServerServiceName: "nomad", ServerServiceName: "nomad",
ClientServiceName: "nomad-client", ClientServiceName: "nomad-client",
AutoRegister: true, AutoAdvertise: true,
Timeout: 5 * time.Second, Timeout: 5 * time.Second,
}, },
LogOutput: os.Stderr, LogOutput: os.Stderr,

View file

@ -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 // 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 // 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 // same consul.Syncer instance. This Syncer task periodically executes
// callbacks that update Consul. The reason the Syncer is always running is // callbacks that update Consul. The reason the Syncer is always running is
// because one of the callbacks is attempts to self-bootstrap Nomad using // 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 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 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.Version = fmt.Sprintf("%s%s", a.config.Version, a.config.VersionPrerelease)
conf.Revision = a.config.Revision 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.ConsulConfig = a.config.Consul
conf.StatsCollectionInterval = a.config.Client.StatsConfig.collectionInterval conf.StatsCollectionInterval = a.config.Client.StatsConfig.collectionInterval
@ -360,7 +370,7 @@ func (a *Agent) setupServer() error {
a.server = server a.server = server
// Create the Nomad Server services for Consul // Create the Nomad Server services for Consul
if a.config.Consul.AutoRegister && a.config.Consul.ServerServiceName != "" { if a.config.Consul.AutoAdvertise {
httpServ := &structs.Service{ httpServ := &structs.Service{
Name: a.config.Consul.ServerServiceName, Name: a.config.Consul.ServerServiceName,
PortLabel: a.serverHTTPAddr, PortLabel: a.serverHTTPAddr,
@ -413,7 +423,7 @@ func (a *Agent) setupClient() error {
a.client = client a.client = client
// Create the Nomad Client services for Consul // Create the Nomad Client services for Consul
if a.config.Consul.AutoRegister && a.config.Consul.ClientServiceName != "" { if a.config.Consul.AutoAdvertise {
httpServ := &structs.Service{ httpServ := &structs.Service{
Name: a.config.Consul.ClientServiceName, Name: a.config.Consul.ClientServiceName,
PortLabel: a.clientHTTPAddr, PortLabel: a.clientHTTPAddr,

View file

@ -362,7 +362,7 @@ func DevConfig() *Config {
conf.DevMode = true conf.DevMode = true
conf.EnableDebug = true conf.EnableDebug = true
conf.DisableAnonymousSignature = true conf.DisableAnonymousSignature = true
conf.Consul.AutoRegister = true conf.Consul.AutoAdvertise = true
if runtime.GOOS == "darwin" { if runtime.GOOS == "darwin" {
conf.Client.NetworkInterface = "lo0" conf.Client.NetworkInterface = "lo0"
} else if runtime.GOOS == "linux" { } else if runtime.GOOS == "linux" {
@ -393,7 +393,7 @@ func DefaultConfig() *Config {
Consul: &config.ConsulConfig{ Consul: &config.ConsulConfig{
ServerServiceName: "nomad", ServerServiceName: "nomad",
ClientServiceName: "nomad-client", ClientServiceName: "nomad-client",
AutoRegister: true, AutoAdvertise: true,
Timeout: 5 * time.Second, Timeout: 5 * time.Second,
}, },
Client: &ClientConfig{ Client: &ClientConfig{

View file

@ -600,7 +600,7 @@ func parseConsulConfig(result **config.ConsulConfig, list *ast.ObjectList) error
valid := []string{ valid := []string{
"address", "address",
"auth", "auth",
"auto_register", "auto_advertise",
"ca_file", "ca_file",
"cert_file", "cert_file",
"client_auto_join", "client_auto_join",

View file

@ -24,9 +24,10 @@ type ConsulConfig struct {
// clients with Consul // clients with Consul
ClientServiceName string `mapstructure:"client_service_name"` ClientServiceName string `mapstructure:"client_service_name"`
// AutoRegister determines if Nomad will register the Nomad client and // AutoAdvertise determines if this Nomad Agent will advertise its
// server agents with Consul // services via Consul. When true, Nomad Agent will register
AutoRegister bool `mapstructure:"auto_register"` // services with Consul.
AutoAdvertise bool `mapstructure:"auto_advertise"`
// Addr is the address of the local Consul agent // Addr is the address of the local Consul agent
Addr string `mapstructure:"address"` Addr string `mapstructure:"address"`
@ -76,8 +77,8 @@ func (a *ConsulConfig) Merge(b *ConsulConfig) *ConsulConfig {
if b.ClientServiceName != "" { if b.ClientServiceName != "" {
result.ClientServiceName = b.ClientServiceName result.ClientServiceName = b.ClientServiceName
} }
if b.AutoRegister { if b.AutoAdvertise {
result.AutoRegister = true result.AutoAdvertise = true
} }
if b.Addr != "" { if b.Addr != "" {
result.Addr = b.Addr result.Addr = b.Addr