From 1ac3798ae0d26a60fd4502d7559671d0b7926e42 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Thu, 22 Mar 2018 13:53:08 -0700 Subject: [PATCH] Allow separate enterprise config overlay --- command/agent/command.go | 7 ++++++- command/agent/config.go | 15 ++++++++------- command/agent/config_oss.go | 8 ++++++++ command/agent/config_parse_test.go | 2 +- command/agent/config_test.go | 5 +++-- 5 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 command/agent/config_oss.go diff --git a/command/agent/command.go b/command/agent/command.go index 91c44f8c4..b440a4e5d 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -198,6 +198,10 @@ func (c *Command) readConfig() *Config { } else { config = DefaultConfig() } + + // Merge in the enterprise overlay + config.Merge(DefaultEntConfig()) + for _, path := range configPath { current, err := LoadConfig(path) if err != nil { @@ -383,7 +387,7 @@ func (c *Command) setupAgent(config *Config, logOutput io.Writer, inmem *metrics c.httpServer = http // Setup update checking - if !config.DisableUpdateCheck { + if config.DisableUpdateCheck != nil && *config.DisableUpdateCheck { version := config.Version.Version if config.Version.VersionPrerelease != "" { version += fmt.Sprintf("-%s", config.Version.VersionPrerelease) @@ -405,6 +409,7 @@ func (c *Command) setupAgent(config *Config, logOutput io.Writer, inmem *metrics c.checkpointResults(checkpoint.Check(updateParams)) }() } + return nil } diff --git a/command/agent/config.go b/command/agent/config.go index 62ad22c7d..732f2b3ef 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -87,7 +87,7 @@ type Config struct { // DisableUpdateCheck is used to disable the periodic update // and security bulletin checking. - DisableUpdateCheck bool `mapstructure:"disable_update_check"` + DisableUpdateCheck *bool `mapstructure:"disable_update_check"` // DisableAnonymousSignature is used to disable setting the // anonymous signature when doing the update check and looking @@ -616,10 +616,11 @@ func DefaultConfig() *Config { CollectionInterval: "1s", collectionInterval: 1 * time.Second, }, - TLSConfig: &config.TLSConfig{}, - Sentinel: &config.SentinelConfig{}, - Version: version.GetVersion(), - Autopilot: config.DefaultAutopilotConfig(), + TLSConfig: &config.TLSConfig{}, + Sentinel: &config.SentinelConfig{}, + Version: version.GetVersion(), + Autopilot: config.DefaultAutopilotConfig(), + DisableUpdateCheck: helper.BoolToPtr(false), } } @@ -685,8 +686,8 @@ func (c *Config) Merge(b *Config) *Config { if b.SyslogFacility != "" { result.SyslogFacility = b.SyslogFacility } - if b.DisableUpdateCheck { - result.DisableUpdateCheck = true + if b.DisableUpdateCheck != nil { + result.DisableUpdateCheck = helper.BoolToPtr(*b.DisableUpdateCheck) } if b.DisableAnonymousSignature { result.DisableAnonymousSignature = true diff --git a/command/agent/config_oss.go b/command/agent/config_oss.go new file mode 100644 index 000000000..2766b56e0 --- /dev/null +++ b/command/agent/config_oss.go @@ -0,0 +1,8 @@ +// +build !pro,!ent + +package agent + +// DefaultEntConfig is an empty config in open source +func DefaultEntConfig() *Config { + return &Config{} +} diff --git a/command/agent/config_parse_test.go b/command/agent/config_parse_test.go index 5441e0cbc..78c0790c4 100644 --- a/command/agent/config_parse_test.go +++ b/command/agent/config_parse_test.go @@ -131,7 +131,7 @@ func TestConfig_Parse(t *testing.T) { LeaveOnTerm: true, EnableSyslog: true, SyslogFacility: "LOCAL1", - DisableUpdateCheck: true, + DisableUpdateCheck: helper.BoolToPtr(true), DisableAnonymousSignature: true, Consul: &config.ConsulConfig{ ServerServiceName: "nomad", diff --git a/command/agent/config_test.go b/command/agent/config_test.go index 35a6b59e2..6593853dc 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -11,6 +11,7 @@ import ( "time" "github.com/hashicorp/consul/lib/freeport" + "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/nomad/structs/config" ) @@ -49,7 +50,7 @@ func TestConfig_Merge(t *testing.T) { LeaveOnTerm: false, EnableSyslog: false, SyslogFacility: "local0.info", - DisableUpdateCheck: false, + DisableUpdateCheck: helper.BoolToPtr(false), DisableAnonymousSignature: false, BindAddr: "127.0.0.1", Telemetry: &Telemetry{ @@ -185,7 +186,7 @@ func TestConfig_Merge(t *testing.T) { LeaveOnTerm: true, EnableSyslog: true, SyslogFacility: "local0.debug", - DisableUpdateCheck: true, + DisableUpdateCheck: helper.BoolToPtr(true), DisableAnonymousSignature: true, BindAddr: "127.0.0.2", Telemetry: &Telemetry{