diff --git a/command/agent/agent.go b/command/agent/agent.go index 04f0955a4f0b..e9cde06a82ae 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -438,7 +438,9 @@ func convertServerConfig(agentConfig *Config) (*nomad.Config, error) { // Set plan rejection tracker configuration. if planRejectConf := agentConfig.Server.PlanRejectionTracker; planRejectConf != nil { - conf.NodePlanRejectionEnabled = planRejectConf.Enabled + if planRejectConf.Enabled != nil { + conf.NodePlanRejectionEnabled = *planRejectConf.Enabled + } conf.NodePlanRejectionThreshold = planRejectConf.NodeThreshold if planRejectConf.NodeWindow == 0 { diff --git a/command/agent/agent_test.go b/command/agent/agent_test.go index 7b75766ab80d..d04ffeffd02c 100644 --- a/command/agent/agent_test.go +++ b/command/agent/agent_test.go @@ -386,12 +386,12 @@ func TestAgent_ServerConfig_PlanRejectionTracker(t *testing.T) { { name: "valid config", trackerConfig: &PlanRejectionTracker{ - Enabled: true, + Enabled: helper.BoolToPtr(true), NodeThreshold: 123, NodeWindow: 17 * time.Minute, }, expectedConfig: &PlanRejectionTracker{ - Enabled: true, + Enabled: helper.BoolToPtr(true), NodeThreshold: 123, NodeWindow: 17 * time.Minute, }, diff --git a/command/agent/config.go b/command/agent/config.go index 816f0ab4bde6..e84472bf7096 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -556,7 +556,7 @@ type RaftBoltConfig struct { // tracker. type PlanRejectionTracker struct { // Enabled controls if the plan rejection tracker is active or not. - Enabled bool `hcl:"enabled"` + Enabled *bool `hcl:"enabled"` // NodeThreshold is the number of times a node can have plan rejections // before it is marked as ineligible. @@ -582,8 +582,8 @@ func (p *PlanRejectionTracker) Merge(b *PlanRejectionTracker) *PlanRejectionTrac return &result } - if b.Enabled { - result.Enabled = true + if b.Enabled != nil { + result.Enabled = b.Enabled } if b.NodeThreshold != 0 { @@ -1037,6 +1037,7 @@ func DefaultConfig() *Config { RaftProtocol: 3, StartJoin: []string{}, PlanRejectionTracker: &PlanRejectionTracker{ + Enabled: helper.BoolToPtr(false), NodeThreshold: 100, NodeWindow: 5 * time.Minute, }, diff --git a/command/agent/config_parse_test.go b/command/agent/config_parse_test.go index c203178a49c9..5000aef76b21 100644 --- a/command/agent/config_parse_test.go +++ b/command/agent/config_parse_test.go @@ -127,7 +127,7 @@ var basicConfig = &Config{ EnableEventBroker: helper.BoolToPtr(false), EventBufferSize: helper.IntToPtr(200), PlanRejectionTracker: &PlanRejectionTracker{ - Enabled: true, + Enabled: helper.BoolToPtr(true), NodeThreshold: 100, NodeWindow: 41 * time.Minute, NodeWindowHCL: "41m", diff --git a/command/agent/config_test.go b/command/agent/config_test.go index 6710ac5c03f4..2e98438f382a 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -149,7 +149,7 @@ func TestConfig_Merge(t *testing.T) { EnableEventBroker: helper.BoolToPtr(false), EventBufferSize: helper.IntToPtr(0), PlanRejectionTracker: &PlanRejectionTracker{ - Enabled: true, + Enabled: helper.BoolToPtr(true), NodeThreshold: 100, NodeWindow: 11 * time.Minute, }, @@ -349,7 +349,7 @@ func TestConfig_Merge(t *testing.T) { EnableEventBroker: helper.BoolToPtr(true), EventBufferSize: helper.IntToPtr(100), PlanRejectionTracker: &PlanRejectionTracker{ - Enabled: true, + Enabled: helper.BoolToPtr(true), NodeThreshold: 100, NodeWindow: 11 * time.Minute, },