From 131d5493c54fc5b45bde144b0fad73a611a13c84 Mon Sep 17 00:00:00 2001 From: Karan Sharma Date: Thu, 12 May 2022 13:36:19 +0530 Subject: [PATCH] feat: Warn if bootstrap_expect is even number --- command/agent/command.go | 3 +++ command/agent/command_test.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/command/agent/command.go b/command/agent/command.go index 74cbb7ef0127..d2b91904fed1 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -431,6 +431,9 @@ func (c *Command) IsValidConfig(config, cmdConfig *Config) bool { if config.Server.Enabled && config.Server.BootstrapExpect == 1 { c.Ui.Error("WARNING: Bootstrap mode enabled! Potentially unsafe operation.") } + if config.Server.Enabled && config.Server.BootstrapExpect%2 == 0 { + c.Ui.Error("WARNING: Number of bootstrap servers should ideally be set to an odd number.") + } } // ProtocolVersion has never been used. Warn if it is set as someone diff --git a/command/agent/command_test.go b/command/agent/command_test.go index ae6ed0185261..8703b52c65dc 100644 --- a/command/agent/command_test.go +++ b/command/agent/command_test.go @@ -47,6 +47,10 @@ func TestCommand_Args(t *testing.T) { []string{"-data-dir=" + tmpDir, "-server", "-bootstrap-expect=1"}, "WARNING: Bootstrap mode enabled!", }, + { + []string{"-data-dir=" + tmpDir, "-server", "-bootstrap-expect=2"}, + "Number of bootstrap servers should ideally be set to an odd number", + }, { []string{"-server"}, "Must specify \"data_dir\" config option or \"data-dir\" CLI flag",