agent: Adding atlas_join configuration

This commit is contained in:
Armon Dadgar 2015-02-04 18:45:08 -08:00
parent 32aaee5185
commit 85a47ba584
4 changed files with 16 additions and 3 deletions

View File

@ -80,6 +80,7 @@ func (c *Command) readConfig() *Config {
cmdFlags.StringVar(&cmdConfig.AtlasCluster, "atlas-cluster", "", "cluster name in Atlas") cmdFlags.StringVar(&cmdConfig.AtlasCluster, "atlas-cluster", "", "cluster name in Atlas")
cmdFlags.StringVar(&cmdConfig.AtlasToken, "atlas-token", "", "authentication token for 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") cmdFlags.IntVar(&cmdConfig.Protocol, "protocol", -1, "protocol version")
@ -842,6 +843,7 @@ Options:
-advertise=addr Sets the advertise address to use -advertise=addr Sets the advertise address to use
-atlas-cluster=org/name Sets the Atlas cluster name, enables SCADA. -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 -atlas-token=token Provides the Atlas API token
-bootstrap Sets server to bootstrap mode -bootstrap Sets server to bootstrap mode
-bind=0.0.0.0 Sets the bind address for cluster communication -bind=0.0.0.0 Sets the bind address for cluster communication

View File

@ -331,6 +331,10 @@ type Config struct {
// to reduce the Atlas privileges to below that of the ACLToken. // to reduce the Atlas privileges to below that of the ACLToken.
AtlasACLToken string `mapstructure:"atlas_acl_token"` 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 // AEInterval controls the anti-entropy interval. This is how often
// the agent attempts to reconcile it's local state with the server' // the agent attempts to reconcile it's local state with the server'
// representation of our state. Defaults to every 60s. // representation of our state. Defaults to every 60s.
@ -963,6 +967,9 @@ func MergeConfig(a, b *Config) *Config {
if b.AtlasACLToken != "" { if b.AtlasACLToken != "" {
result.AtlasACLToken = b.AtlasACLToken result.AtlasACLToken = b.AtlasACLToken
} }
if b.AtlasJoin {
result.AtlasJoin = true
}
if len(b.HTTPAPIResponseHeaders) != 0 { if len(b.HTTPAPIResponseHeaders) != 0 {
if result.HTTPAPIResponseHeaders == nil { if result.HTTPAPIResponseHeaders == nil {

View File

@ -635,7 +635,7 @@ func TestDecodeConfig(t *testing.T) {
} }
// Atlas configs // 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))) config, err = DecodeConfig(bytes.NewReader([]byte(input)))
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
@ -650,6 +650,9 @@ func TestDecodeConfig(t *testing.T) {
if config.AtlasACLToken != "123456789" { if config.AtlasACLToken != "123456789" {
t.Fatalf("bad: %#v", config) t.Fatalf("bad: %#v", config)
} }
if !config.AtlasJoin {
t.Fatalf("bad: %#v", config)
}
} }
func TestDecodeConfig_invalidKeys(t *testing.T) { func TestDecodeConfig_invalidKeys(t *testing.T) {
@ -1116,6 +1119,7 @@ func TestMergeConfig(t *testing.T) {
AtlasCluster: "hashicorp/prod", AtlasCluster: "hashicorp/prod",
AtlasToken: "123456789", AtlasToken: "123456789",
AtlasACLToken: "abcdefgh", AtlasACLToken: "abcdefgh",
AtlasJoin: true,
} }
c := MergeConfig(a, b) c := MergeConfig(a, b)

View File

@ -36,7 +36,7 @@ func makeHTTPServerWithConfig(t *testing.T, cb func(c *Config)) (string, *HTTPSe
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
conf.UiDir = uiDir conf.UiDir = uiDir
servers, err := NewHTTPServers(agent, conf, agent.logOutput) servers, err := NewHTTPServers(agent, conf, nil, agent.logOutput)
if err != nil { if err != nil {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
@ -146,7 +146,7 @@ func TestHTTPServer_UnixSocket_FileExists(t *testing.T) {
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
// Try to start the server with the same path anyways. // 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) t.Fatalf("err: %s", err)
} }