From e7e6df394f5d417f01611cb21c7b123d94ea67c5 Mon Sep 17 00:00:00 2001 From: Drew Bailey <2614075+drewbailey@users.noreply.github.com> Date: Fri, 2 Oct 2020 15:04:05 -0400 Subject: [PATCH] wire up enable_event_publisher --- command/agent/agent.go | 3 +++ command/agent/agent_test.go | 2 ++ command/agent/command.go | 1 + command/agent/config.go | 13 +++++++++++-- command/agent/config_parse_test.go | 1 + command/agent/testdata/basic.hcl | 1 + command/agent/testdata/basic.json | 1 + 7 files changed, 20 insertions(+), 2 deletions(-) diff --git a/command/agent/agent.go b/command/agent/agent.go index 016b77d16..16f3c20d5 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -243,6 +243,9 @@ func convertServerConfig(agentConfig *Config) (*nomad.Config, error) { if agentConfig.Server.UpgradeVersion != "" { conf.UpgradeVersion = agentConfig.Server.UpgradeVersion } + if agentConfig.Server.EnableEventPublisher { + conf.EnableEventPublisher = agentConfig.Server.EnableEventPublisher + } if agentConfig.Autopilot != nil { if agentConfig.Autopilot.CleanupDeadServers != nil { conf.AutopilotConfig.CleanupDeadServers = *agentConfig.Autopilot.CleanupDeadServers diff --git a/command/agent/agent_test.go b/command/agent/agent_test.go index d9290bc59..1ac900444 100644 --- a/command/agent/agent_test.go +++ b/command/agent/agent_test.go @@ -57,6 +57,8 @@ func TestAgent_ServerConfig(t *testing.T) { out, err := a.serverConfig() require.NoError(t, err) + require.True(t, out.EnableEventPublisher) + serfAddr := out.SerfConfig.MemberlistConfig.AdvertiseAddr require.Equal(t, "127.0.0.1", serfAddr) diff --git a/command/agent/command.go b/command/agent/command.go index 0ed3ff338..199f47133 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -94,6 +94,7 @@ func (c *Command) readConfig() *Config { flags.Var((*flaghelper.StringFlag)(&cmdConfig.Server.ServerJoin.StartJoin), "join", "") flags.Var((*flaghelper.StringFlag)(&cmdConfig.Server.ServerJoin.RetryJoin), "retry-join", "") flags.IntVar(&cmdConfig.Server.ServerJoin.RetryMaxAttempts, "retry-max", 0, "") + flags.BoolVar(&cmdConfig.Server.EnableEventPublisher, "event-publisher", false, "") flags.Var((flaghelper.FuncDurationVar)(func(d time.Duration) error { cmdConfig.Server.ServerJoin.RetryInterval = d return nil diff --git a/command/agent/config.go b/command/agent/config.go index 5fd3d9487..392eaf7b1 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -484,6 +484,10 @@ type ServerConfig struct { // This value is ignored. DefaultSchedulerConfig *structs.SchedulerConfiguration `hcl:"default_scheduler_config"` + // EnableEventPublisher configures whether this server's state store + // will generate events for its event stream. + EnableEventPublisher bool `hcl:"enable_event_publisher"` + // ExtraKeysHCL is used by hcl to surface unexpected keys ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"` } @@ -874,8 +878,9 @@ func DefaultConfig() *Config { BindWildcardDefaultHostNetwork: true, }, Server: &ServerConfig{ - Enabled: false, - StartJoin: []string{}, + Enabled: false, + EnableEventPublisher: true, + StartJoin: []string{}, ServerJoin: &ServerJoin{ RetryJoin: []string{}, RetryInterval: 30 * time.Second, @@ -1399,6 +1404,10 @@ func (a *ServerConfig) Merge(b *ServerConfig) *ServerConfig { result.ServerJoin = result.ServerJoin.Merge(b.ServerJoin) } + if b.EnableEventPublisher { + result.EnableEventPublisher = true + } + if b.DefaultSchedulerConfig != nil { c := *b.DefaultSchedulerConfig result.DefaultSchedulerConfig = &c diff --git a/command/agent/config_parse_test.go b/command/agent/config_parse_test.go index 91108710c..a288b5f80 100644 --- a/command/agent/config_parse_test.go +++ b/command/agent/config_parse_test.go @@ -122,6 +122,7 @@ var basicConfig = &Config{ RedundancyZone: "foo", UpgradeVersion: "0.8.0", EncryptKey: "abc", + EnableEventPublisher: true, ServerJoin: &ServerJoin{ RetryJoin: []string{"1.1.1.1", "2.2.2.2"}, RetryInterval: time.Duration(15) * time.Second, diff --git a/command/agent/testdata/basic.hcl b/command/agent/testdata/basic.hcl index 43499861f..36a420551 100644 --- a/command/agent/testdata/basic.hcl +++ b/command/agent/testdata/basic.hcl @@ -130,6 +130,7 @@ server { upgrade_version = "0.8.0" encrypt = "abc" raft_multiplier = 4 + enable_event_publisher = true server_join { retry_join = ["1.1.1.1", "2.2.2.2"] diff --git a/command/agent/testdata/basic.json b/command/agent/testdata/basic.json index e97f4d3f0..5aa897d73 100644 --- a/command/agent/testdata/basic.json +++ b/command/agent/testdata/basic.json @@ -261,6 +261,7 @@ "data_dir": "/tmp/data", "deployment_gc_threshold": "12h", "enabled": true, + "enable_event_publisher": true, "enabled_schedulers": [ "test" ],