diff --git a/command/agent/command.go b/command/agent/command.go index 76c7a09440..2f64782061 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -80,6 +80,7 @@ func (c *Command) readConfig() *Config { cmdFlags.StringVar(&cmdConfig.AtlasCluster, "atlas-cluster", "", "cluster name in Atlas") cmdFlags.StringVar(&cmdConfig.AtlasToken, "atlas-token", "", "authentication token for Atlas") + cmdFlags.BoolVar(&cmdConfig.AtlasJoin, "atlas-join", false, "auto-join with Atlas") cmdFlags.IntVar(&cmdConfig.Protocol, "protocol", -1, "protocol version") @@ -842,6 +843,7 @@ Options: -advertise=addr Sets the advertise address to use -atlas-cluster=org/name Sets the Atlas cluster name, enables SCADA. + -atlas-join Enables auto-joining the Atlas cluster -atlas-token=token Provides the Atlas API token -bootstrap Sets server to bootstrap mode -bind=0.0.0.0 Sets the bind address for cluster communication diff --git a/command/agent/config.go b/command/agent/config.go index d1cc57655c..f3c237dcbb 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -331,6 +331,10 @@ type Config struct { // to reduce the Atlas privileges to below that of the ACLToken. AtlasACLToken string `mapstructure:"atlas_acl_token"` + // AtlasJoin controls if Atlas will attempt to auto-join the node + // to it's cluster. Requires Atlas integration. + AtlasJoin bool `mapstructure:"atlas_join"` + // AEInterval controls the anti-entropy interval. This is how often // the agent attempts to reconcile it's local state with the server' // representation of our state. Defaults to every 60s. @@ -963,6 +967,9 @@ func MergeConfig(a, b *Config) *Config { if b.AtlasACLToken != "" { result.AtlasACLToken = b.AtlasACLToken } + if b.AtlasJoin { + result.AtlasJoin = true + } if len(b.HTTPAPIResponseHeaders) != 0 { if result.HTTPAPIResponseHeaders == nil { diff --git a/command/agent/config_test.go b/command/agent/config_test.go index 3aaef21890..5e7f254ed0 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -635,7 +635,7 @@ func TestDecodeConfig(t *testing.T) { } // Atlas configs - input = `{"atlas_cluster": "hashicorp/prod", "atlas_token": "abcdefg", "atlas_acl_token": "123456789"}` + input = `{"atlas_cluster": "hashicorp/prod", "atlas_token": "abcdefg", "atlas_acl_token": "123456789", "atlas_join": true}` config, err = DecodeConfig(bytes.NewReader([]byte(input))) if err != nil { t.Fatalf("err: %s", err) @@ -650,6 +650,9 @@ func TestDecodeConfig(t *testing.T) { if config.AtlasACLToken != "123456789" { t.Fatalf("bad: %#v", config) } + if !config.AtlasJoin { + t.Fatalf("bad: %#v", config) + } } func TestDecodeConfig_invalidKeys(t *testing.T) { @@ -1116,6 +1119,7 @@ func TestMergeConfig(t *testing.T) { AtlasCluster: "hashicorp/prod", AtlasToken: "123456789", AtlasACLToken: "abcdefgh", + AtlasJoin: true, } c := MergeConfig(a, b) diff --git a/command/agent/http_test.go b/command/agent/http_test.go index 19e8f95af9..ae0ef64de0 100644 --- a/command/agent/http_test.go +++ b/command/agent/http_test.go @@ -36,7 +36,7 @@ func makeHTTPServerWithConfig(t *testing.T, cb func(c *Config)) (string, *HTTPSe t.Fatalf("err: %v", err) } conf.UiDir = uiDir - servers, err := NewHTTPServers(agent, conf, agent.logOutput) + servers, err := NewHTTPServers(agent, conf, nil, agent.logOutput) if err != nil { t.Fatalf("err: %v", err) } @@ -146,7 +146,7 @@ func TestHTTPServer_UnixSocket_FileExists(t *testing.T) { defer os.RemoveAll(dir) // Try to start the server with the same path anyways. - if _, err := NewHTTPServers(agent, conf, agent.logOutput); err != nil { + if _, err := NewHTTPServers(agent, conf, nil, agent.logOutput); err != nil { t.Fatalf("err: %s", err) }