diff --git a/command/agent/agent.go b/command/agent/agent.go index 75ff489ecc..0d8cecfdf8 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -175,8 +175,8 @@ func (a *Agent) consulConfig() *consul.Config { if a.config.RejoinAfterLeave { base.RejoinAfterLeave = true } - if a.config.Expect != 0 { - base.Expect = a.config.Expect + if a.config.BootstrapExpect != 0 { + base.BootstrapExpect = a.config.BootstrapExpect } if a.config.Protocol > 0 { base.ProtocolVersion = uint8(a.config.Protocol) diff --git a/command/agent/command.go b/command/agent/command.go index 25e04dc44d..f1f7b0d0bf 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -63,7 +63,7 @@ func (c *Command) readConfig() *Config { cmdFlags.BoolVar(&cmdConfig.Server, "server", false, "run agent as server") cmdFlags.BoolVar(&cmdConfig.Bootstrap, "bootstrap", false, "enable server bootstrap mode") - cmdFlags.IntVar(&cmdConfig.Expect, "expect", 0, "enable automatic bootstrap via expect mode") + cmdFlags.IntVar(&cmdConfig.BootstrapExpect, "bootstrap-expect", 0, "enable automatic bootstrap via expect mode") cmdFlags.StringVar(&cmdConfig.ClientAddr, "client", "", "address to bind client listeners to (DNS, HTTP, RPC)") cmdFlags.StringVar(&cmdConfig.BindAddr, "bind", "", "address to bind server listeners to") @@ -130,27 +130,24 @@ func (c *Command) readConfig() *Config { } // Expect can only work when acting as a server - if config.Expect != 0 && !config.Server { + if config.BootstrapExpect != 0 && !config.Server { c.Ui.Error("Expect mode cannot be enabled when server mode is not enabled") return nil } // Expect & Bootstrap are mutually exclusive - if config.Expect != 0 && config.Bootstrap { + if config.BootstrapExpect != 0 && config.Bootstrap { c.Ui.Error("Bootstrap cannot be provided with an expected server count") return nil } // Warn if we are in expect mode - if config.Expect != 0 { - if config.Expect == 1 { - // just use bootstrap mode - c.Ui.Error("WARNING: Expect Mode is specified as 1; this is the same as Bootstrap mode.") - config.Expect = 0 - config.Bootstrap = true - } else { - c.Ui.Error(fmt.Sprintf("WARNING: Expect Mode enabled, looking for %v servers!", config.Expect)) - } + if config.BootstrapExpect == 1 { + c.Ui.Error("WARNING: BootstrapExpect Mode is specified as 1; this is the same as Bootstrap mode.") + config.BootstrapExpect = 0 + config.Bootstrap = true + } else if config.BootstrapExpect > 0 { + c.Ui.Error(fmt.Sprintf("WARNING: Expect Mode enabled, expecting %d servers", config.BootstrapExpect)) } // Warn if we are in bootstrap mode diff --git a/command/agent/config.go b/command/agent/config.go index c3631429a8..f08d545b18 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -65,9 +65,9 @@ type Config struct { // permits that node to elect itself leader Bootstrap bool `mapstructure:"bootstrap"` - // Expect tries to automatically bootstrap the Consul cluster, + // BootstrapExpect tries to automatically bootstrap the Consul cluster, // by witholding peers until enough servers join. - Expect int `mapstructure:"expect"` + BootstrapExpect int `mapstructure:"bootstrap_expect"` // Server controls if this agent acts like a Consul server, // or merely as a client. Servers have more state, take part @@ -223,14 +223,14 @@ type dirEnts []os.FileInfo // DefaultConfig is used to return a sane default configuration func DefaultConfig() *Config { return &Config{ - Bootstrap: false, - Expect: 0, - Server: false, - Datacenter: consul.DefaultDC, - Domain: "consul.", - LogLevel: "INFO", - ClientAddr: "127.0.0.1", - BindAddr: "0.0.0.0", + Bootstrap: false, + BootstrapExpect: 0, + Server: false, + Datacenter: consul.DefaultDC, + Domain: "consul.", + LogLevel: "INFO", + ClientAddr: "127.0.0.1", + BindAddr: "0.0.0.0", Ports: PortConfig{ DNS: 8600, HTTP: 8500, @@ -455,8 +455,8 @@ func MergeConfig(a, b *Config) *Config { if b.Bootstrap { result.Bootstrap = true } - if b.Expect != 0 { - result.Expect = b.Expect + if b.BootstrapExpect != 0 { + result.BootstrapExpect = b.BootstrapExpect } if b.Datacenter != "" { result.Datacenter = b.Datacenter diff --git a/command/agent/config_test.go b/command/agent/config_test.go index 0225630d08..0c6db15e1c 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -94,7 +94,7 @@ func TestDecodeConfig(t *testing.T) { } // Expect bootstrap - input = `{"server": true, "expect": 3}` + input = `{"server": true, "bootstrap_expect": 3}` config, err = DecodeConfig(bytes.NewReader([]byte(input))) if err != nil { t.Fatalf("err: %s", err) @@ -104,7 +104,7 @@ func TestDecodeConfig(t *testing.T) { t.Fatalf("bad: %#v", config) } - if config.Expect != 3 { + if config.BootstrapExpect != 3 { t.Fatalf("bad: %#v", config) } @@ -441,7 +441,7 @@ func TestDecodeConfig_Check(t *testing.T) { func TestMergeConfig(t *testing.T) { a := &Config{ Bootstrap: false, - Expect: 0, + BootstrapExpect: 0, Datacenter: "dc1", DataDir: "/tmp/foo", DNSRecursor: "127.0.0.1:1001", @@ -459,11 +459,11 @@ func TestMergeConfig(t *testing.T) { } b := &Config{ - Bootstrap: true, - Expect: 3, - Datacenter: "dc2", - DataDir: "/tmp/bar", - DNSRecursor: "127.0.0.2:1001", + Bootstrap: true, + BootstrapExpect: 3, + Datacenter: "dc2", + DataDir: "/tmp/bar", + DNSRecursor: "127.0.0.2:1001", DNSConfig: DNSConfig{ NodeTTL: 10 * time.Second, ServiceTTL: map[string]time.Duration{ diff --git a/consul/config.go b/consul/config.go index ae6c482823..fe4bf60010 100644 --- a/consul/config.go +++ b/consul/config.go @@ -44,10 +44,10 @@ type Config struct { // other nodes being present Bootstrap bool - // Expect mode is used to automatically bring up a collection of + // BootstrapExpect mode is used to automatically bring up a collection of // Consul servers. This can be used to automatically bring up a collection // of nodes. - Expect int + BootstrapExpect int // Datacenter is the datacenter this Consul server represents Datacenter string diff --git a/consul/serf.go b/consul/serf.go index e31abef1a8..37aae27257 100644 --- a/consul/serf.go +++ b/consul/serf.go @@ -153,7 +153,7 @@ func (s *Server) nodeJoin(me serf.MemberEvent, wan bool) { } // If we still expecting to bootstrap, may need to handle this - if s.config.Expect != 0 { + if s.config.BootstrapExpect != 0 { s.maybeBootstrap() } } @@ -170,7 +170,7 @@ func (s *Server) maybeBootstrap() { // Bootstrap can only be done if there are no committed logs, // remove our expectations of bootstrapping if index != 0 { - s.config.Expect = 0 + s.config.BootstrapExpect = 0 return } @@ -186,7 +186,7 @@ func (s *Server) maybeBootstrap() { s.logger.Printf("[ERR] consul: Member %v has a conflicting datacenter, ignoring", member) continue } - if p.Expect != 0 && p.Expect != s.config.Expect { + if p.Expect != 0 && p.Expect != s.config.BootstrapExpect { s.logger.Printf("[ERR] consul: Member %v has a conflicting expect value. All nodes should expect the same number.", member) return } @@ -198,7 +198,7 @@ func (s *Server) maybeBootstrap() { } // Skip if we haven't met the minimum expect count - if len(addrs) < s.config.Expect { + if len(addrs) < s.config.BootstrapExpect { return } @@ -209,7 +209,7 @@ func (s *Server) maybeBootstrap() { } // Bootstrapping comlete, don't enter this again - s.config.Expect = 0 + s.config.BootstrapExpect = 0 } // nodeFailed is used to handle fail events on both the serf clustes diff --git a/consul/server.go b/consul/server.go index d126e2343e..5f2a7635e5 100644 --- a/consul/server.go +++ b/consul/server.go @@ -234,8 +234,8 @@ func (s *Server) setupSerf(conf *serf.Config, ch chan serf.Event, path string, w if s.config.Bootstrap { conf.Tags["bootstrap"] = "1" } - if s.config.Expect != 0 { - conf.Tags["expect"] = fmt.Sprintf("%d", s.config.Expect) + if s.config.BootstrapExpect != 0 { + conf.Tags["expect"] = fmt.Sprintf("%d", s.config.BootstrapExpect) } conf.MemberlistConfig.LogOutput = s.config.LogOutput conf.LogOutput = s.config.LogOutput diff --git a/consul/server_test.go b/consul/server_test.go index 9ad01b4aee..70aa5811f6 100644 --- a/consul/server_test.go +++ b/consul/server_test.go @@ -93,7 +93,7 @@ func testServerDCExpect(t *testing.T, dc string, expect int) (string, *Server) { dir, config := testServerConfig(t, name) config.Datacenter = dc config.Bootstrap = false - config.Expect = expect + config.BootstrapExpect = expect server, err := NewServer(config) if err != nil { t.Fatalf("err: %v", err)