ensure default value of 30s is set for server_join stanza

This commit is contained in:
Chelsea Holland Komlo
2018-05-29 15:12:08 -04:00
committed by Alex Dadgar
parent 3d12b3fdf2
commit 4b20a698ac
4 changed files with 20 additions and 7 deletions

View File

@@ -591,6 +591,10 @@ func (c *Command) Run(args []string) int {
}
if config.Client.Enabled && config.Client.ServerJoin != nil {
// COMPAT: Remove in 0.10 set the default RetryInterval value, as the
// ServerJoin stanza is not part of a default config for an agent.
config.Client.ServerJoin.RetryInterval = time.Duration(30) * time.Second
joiner := retryJoiner{
discover: &discover.Discover{},
errCh: c.retryJoinErrCh,

View File

@@ -1116,6 +1116,9 @@ func (a *ServerConfig) Merge(b *ServerConfig) *ServerConfig {
result.EncryptKey = b.EncryptKey
}
if b.ServerJoin != nil {
// // COMPAT: Remove in 0.10 - ServerJoin is not defined by default on an
// agent config, this should be eventually moved to DefaultConfig
result.ServerJoin = getDefaultServerJoin()
result.ServerJoin = result.ServerJoin.Merge(b.ServerJoin)
}
@@ -1135,6 +1138,12 @@ func (a *ServerConfig) Merge(b *ServerConfig) *ServerConfig {
return &result
}
func getDefaultServerJoin() *ServerJoin {
return &ServerJoin{
RetryInterval: time.Duration(30) * time.Second,
}
}
// Merge is used to merge two client configs together
func (a *ClientConfig) Merge(b *ClientConfig) *ClientConfig {
result := *a
@@ -1226,7 +1235,10 @@ func (a *ClientConfig) Merge(b *ClientConfig) *ClientConfig {
}
if b.ServerJoin != nil {
result.ServerJoin = b.ServerJoin
// // COMPAT: Remove in 0.10 - ServerJoin is not defined by default on an
// agent config, this should be eventually moved to DefaultConfig
result.ServerJoin = getDefaultServerJoin()
result.ServerJoin = result.ServerJoin.Merge(b.ServerJoin)
}
return &result

View File

@@ -69,11 +69,8 @@ func (r *retryJoiner) Validate(config *Config) error {
if config.Server.RetryMaxAttempts != 0 {
return fmt.Errorf("server_join and retry_max cannot both be defined; try defining only server_join")
}
if config.Server.RetryInterval != "0" && config.Server.RetryInterval != "" {
// 30s is the default value that is set, ignore if this is the case
if config.Server.RetryInterval != "30s" {
return fmt.Errorf("server_join and retry_interval cannot both be defined; prefer setting the server_join parameter")
}
if config.Server.RetryInterval != "30s" {
return fmt.Errorf("server_join and retry_interval cannot both be defined; prefer setting the server_join parameter")
}
if len(config.Server.ServerJoin.RetryJoin) != 0 && len(config.Server.ServerJoin.StartJoin) != 0 {

View File

@@ -339,7 +339,7 @@ func TestRetryJoin_Validate(t *testing.T) {
},
StartJoin: []string{},
RetryMaxAttempts: 0,
RetryInterval: "0",
RetryInterval: "30s",
RetryJoin: []string{},
},
},