diff --git a/command/agent/command.go b/command/agent/command.go index 768d337c3..7ef886fdf 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -53,7 +53,7 @@ func (c *Command) readConfig() *Config { var cmdConfig Config var configFiles []string var retryInterval string - var retryWanInterval string + var retryIntervalWan string cmdFlags := flag.NewFlagSet("agent", flag.ContinueOnError) cmdFlags.Usage = func() { c.Ui.Output(c.Help()) } @@ -84,7 +84,7 @@ func (c *Command) readConfig() *Config { "enable re-joining after a previous leave") cmdFlags.Var((*AppendSliceValue)(&cmdConfig.StartJoin), "join", "address of agent to join on startup") - cmdFlags.Var((*AppendSliceValue)(&cmdConfig.StartWanJoin), "join-wan", + cmdFlags.Var((*AppendSliceValue)(&cmdConfig.StartJoinWan), "join-wan", "address of agent to join -wan on startup") cmdFlags.Var((*AppendSliceValue)(&cmdConfig.RetryJoin), "retry-join", "address of agent to join on startup with retry") @@ -92,11 +92,11 @@ func (c *Command) readConfig() *Config { "number of retries for joining") cmdFlags.StringVar(&retryInterval, "retry-interval", "", "interval between join attempts") - cmdFlags.Var((*AppendSliceValue)(&cmdConfig.RetryWanJoin), "retry-wan-join", + cmdFlags.Var((*AppendSliceValue)(&cmdConfig.RetryJoinWan), "retry-join-wan", "address of agent to join -wan on startup with retry") - cmdFlags.IntVar(&cmdConfig.RetryWanMaxAttempts, "retry-wan-max", 0, + cmdFlags.IntVar(&cmdConfig.RetryMaxAttemptsWan, "retry-max-wan", 0, "number of retries for joining -wan") - cmdFlags.StringVar(&retryWanInterval, "retry-wan-interval", "", + cmdFlags.StringVar(&retryIntervalWan, "retry-interval-wan", "", "interval between join -wan attempts") if err := cmdFlags.Parse(c.args); err != nil { @@ -112,13 +112,13 @@ func (c *Command) readConfig() *Config { cmdConfig.RetryInterval = dur } - if retryWanInterval != "" { - dur, err := time.ParseDuration(retryWanInterval) + if retryIntervalWan != "" { + dur, err := time.ParseDuration(retryIntervalWan) if err != nil { c.Ui.Error(fmt.Sprintf("Error: %s", err)) return nil } - cmdConfig.RetryWanInterval = dur + cmdConfig.RetryIntervalWan = dur } config := DefaultConfig() @@ -387,14 +387,14 @@ func (c *Command) startupJoin(config *Config) error { return nil } -// startupWanJoin is invoked to handle any joins -wan specified to take place at start time -func (c *Command) startupWanJoin(config *Config) error { - if len(config.StartWanJoin) == 0 { +// startupJoinWan is invoked to handle any joins -wan specified to take place at start time +func (c *Command) startupJoinWan(config *Config) error { + if len(config.StartJoinWan) == 0 { return nil } c.Ui.Output("Joining -wan cluster...") - n, err := c.agent.JoinWAN(config.StartWanJoin) + n, err := c.agent.JoinWAN(config.StartJoinWan) if err != nil { return err } @@ -434,10 +434,10 @@ func (c *Command) retryJoin(config *Config, errCh chan<- struct{}) { } } -// retryWanJoin is used to handle retrying a join -wan until it succeeds or all +// retryJoinWan is used to handle retrying a join -wan until it succeeds or all // retries are exhausted. -func (c *Command) retryWanJoin(config *Config, errCh chan<- struct{}) { - if len(config.RetryWanJoin) == 0 { +func (c *Command) retryJoinWan(config *Config, errCh chan<- struct{}) { + if len(config.RetryJoinWan) == 0 { return } @@ -446,22 +446,22 @@ func (c *Command) retryWanJoin(config *Config, errCh chan<- struct{}) { attempt := 0 for { - n, err := c.agent.JoinWAN(config.RetryWanJoin) + n, err := c.agent.JoinWAN(config.RetryJoinWan) if err == nil { logger.Printf("[INFO] agent: Join -wan completed. Synced with %d initial agents", n) return } attempt++ - if config.RetryWanMaxAttempts > 0 && attempt > config.RetryWanMaxAttempts { + if config.RetryMaxAttemptsWan > 0 && attempt > config.RetryMaxAttemptsWan { logger.Printf("[ERROR] agent: max join -wan retry exhausted, exiting") close(errCh) return } logger.Printf("[WARN] agent: Join -wan failed: %v, retrying in %v", err, - config.RetryWanInterval) - time.Sleep(config.RetryWanInterval) + config.RetryIntervalWan) + time.Sleep(config.RetryIntervalWan) } } @@ -548,7 +548,7 @@ func (c *Command) Run(args []string) int { } // Join startup nodes if specified - if err := c.startupWanJoin(config); err != nil { + if err := c.startupJoinWan(config); err != nil { c.Ui.Error(err.Error()) return 1 } @@ -615,14 +615,14 @@ func (c *Command) Run(args []string) int { // Start retry -wan join process errWanCh := make(chan struct{}) - go c.retryWanJoin(config, errWanCh) + go c.retryJoinWan(config, errWanCh) // Wait for exit return c.handleSignals(config, errCh, errWanCh) } // handleSignals blocks until we get an exit-causing signal -func (c *Command) handleSignals(config *Config, retryJoin <-chan struct{}, retryWanJoin <-chan struct{}) int { +func (c *Command) handleSignals(config *Config, retryJoin <-chan struct{}, retryJoinWan <-chan struct{}) int { signalCh := make(chan os.Signal, 4) signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP) @@ -638,7 +638,7 @@ WAIT: sig = os.Interrupt case <-retryJoin: return 1 - case <-retryWanJoin: + case <-retryJoinWan: return 1 case <-c.agent.ShutdownCh(): // Agent is already shutdown! @@ -805,10 +805,10 @@ Options: -retry-interval=30s Time to wait between join attempts. -retry-max=0 Maximum number of join attempts. Defaults to 0, which will retry indefinitely. - -retry-wan-join=1.2.3.4 Address of an agent to join -wan at start time with + -retry-join-wan=1.2.3.4 Address of an agent to join -wan at start time with retries enabled. Can be specified multiple times. - -retry-wan-interval=30s Time to wait between join -wan attempts. - -retry-wan-max=0 Maximum number of join -wan attempts. Defaults to 0, which + -retry-interval-wan=30s Time to wait between join -wan attempts. + -retry-max-wan=0 Maximum number of join -wan attempts. Defaults to 0, which will retry indefinitely. -log-level=info Log level of the agent. -node=hostname Name of this node. Must be unique in the cluster diff --git a/command/agent/command_test.go b/command/agent/command_test.go index e2dd634d5..bd7f29a17 100644 --- a/command/agent/command_test.go +++ b/command/agent/command_test.go @@ -121,7 +121,7 @@ func TestRetryJoinFail(t *testing.T) { t.Fatalf("bad: %d", code) } } -func TestRetryWanJoin(t *testing.T) { +func TestRetryJoinWan(t *testing.T) { dir, agent := makeAgent(t, nextConfig()) defer os.RemoveAll(dir) defer agent.Shutdown() @@ -154,7 +154,7 @@ func TestRetryWanJoin(t *testing.T) { args := []string{ "-data-dir", tmpDir, "-node", fmt.Sprintf(`"%s"`, conf2.NodeName), - "-retry-wan-join", serfAddr, + "-retry-join-wan", serfAddr, "-retry-interval", "1s", } @@ -176,7 +176,7 @@ func TestRetryWanJoin(t *testing.T) { }) } -func TestRetryWanJoinFail(t *testing.T) { +func TestRetryJoinWanFail(t *testing.T) { conf := nextConfig() tmpDir, err := ioutil.TempDir("", "consul") if err != nil { @@ -196,7 +196,7 @@ func TestRetryWanJoinFail(t *testing.T) { args := []string{ "-data-dir", tmpDir, - "-retry-wan-join", serfAddr, + "-retry-join-wan", serfAddr, "-retry-max", "1", } diff --git a/command/agent/config.go b/command/agent/config.go index ddff17164..c995cbe56 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -194,10 +194,10 @@ type Config struct { // addresses, then the agent will error and exit. StartJoin []string `mapstructure:"start_join"` - // StartWanJoin is a list of addresses to attempt to join -wan when the + // StartJoinWan is a list of addresses to attempt to join -wan when the // agent starts. If Serf is unable to communicate with any of these // addresses, then the agent will error and exit. - StartWanJoin []string `mapstructure:"start_wan_join"` + StartJoinWan []string `mapstructure:"start_join_wan"` // RetryJoin is a list of addresses to join with retry enabled. RetryJoin []string `mapstructure:"retry_join"` @@ -213,19 +213,19 @@ type Config struct { RetryInterval time.Duration `mapstructure:"-" json:"-"` RetryIntervalRaw string `mapstructure:"retry_interval"` - // RetryWanJoin is a list of addresses to join -wan with retry enabled. - RetryWanJoin []string `mapstructure:"retry_wan_join"` + // RetryJoinWan is a list of addresses to join -wan with retry enabled. + RetryJoinWan []string `mapstructure:"retry_join_wan"` - // RetryWanMaxAttempts specifies the maximum number of times to retry joining a + // RetryMaxAttemptsWan specifies the maximum number of times to retry joining a // -wan host on startup. This is useful for cases where we know the node will be // online eventually. - RetryWanMaxAttempts int `mapstructure:"retry_wan_max"` + RetryMaxAttemptsWan int `mapstructure:"retry_max_wan"` - // RetryWanInterval specifies the amount of time to wait in between join + // RetryIntervalWan specifies the amount of time to wait in between join // -wan attempts on agent start. The minimum allowed value is 1 second and // the default is 30s. - RetryWanInterval time.Duration `mapstructure:"-" json:"-"` - RetryWanIntervalRaw string `mapstructure:"retry_wan_interval"` + RetryIntervalWan time.Duration `mapstructure:"-" json:"-"` + RetryIntervalWanRaw string `mapstructure:"retry_interval_wan"` // UiDir is the directory containing the Web UI resources. // If provided, the UI endpoints will be enabled. @@ -367,7 +367,7 @@ func DefaultConfig() *Config { ACLDownPolicy: "extend-cache", ACLDefaultPolicy: "allow", RetryInterval: 30 * time.Second, - RetryWanInterval: 30 * time.Second, + RetryIntervalWan: 30 * time.Second, } } @@ -525,12 +525,12 @@ func DecodeConfig(r io.Reader) (*Config, error) { result.RetryInterval = dur } - if raw := result.RetryWanIntervalRaw; raw != "" { + if raw := result.RetryIntervalWanRaw; raw != "" { dur, err := time.ParseDuration(raw) if err != nil { - return nil, fmt.Errorf("RetryWanInterval invalid: %v", err) + return nil, fmt.Errorf("RetryIntervalWan invalid: %v", err) } - result.RetryWanInterval = dur + result.RetryIntervalWan = dur } // Merge the single recursor @@ -778,11 +778,11 @@ func MergeConfig(a, b *Config) *Config { if b.RetryInterval != 0 { result.RetryInterval = b.RetryInterval } - if b.RetryWanMaxAttempts != 0 { - result.RetryWanMaxAttempts = b.RetryWanMaxAttempts + if b.RetryMaxAttemptsWan != 0 { + result.RetryMaxAttemptsWan = b.RetryMaxAttemptsWan } - if b.RetryWanInterval != 0 { - result.RetryWanInterval = b.RetryWanInterval + if b.RetryIntervalWan != 0 { + result.RetryIntervalWan = b.RetryIntervalWan } if b.DNSConfig.NodeTTL != 0 { result.DNSConfig.NodeTTL = b.DNSConfig.NodeTTL @@ -851,9 +851,9 @@ func MergeConfig(a, b *Config) *Config { result.StartJoin = append(result.StartJoin, b.StartJoin...) // Copy the start join addresses - result.StartWanJoin = make([]string, 0, len(a.StartWanJoin)+len(b.StartWanJoin)) - result.StartWanJoin = append(result.StartWanJoin, a.StartWanJoin...) - result.StartWanJoin = append(result.StartWanJoin, b.StartWanJoin...) + result.StartJoinWan = make([]string, 0, len(a.StartJoinWan)+len(b.StartJoinWan)) + result.StartJoinWan = append(result.StartJoinWan, a.StartJoinWan...) + result.StartJoinWan = append(result.StartJoinWan, b.StartJoinWan...) // Copy the retry join addresses result.RetryJoin = make([]string, 0, len(a.RetryJoin)+len(b.RetryJoin)) @@ -861,9 +861,9 @@ func MergeConfig(a, b *Config) *Config { result.RetryJoin = append(result.RetryJoin, b.RetryJoin...) // Copy the retry join -wan addresses - result.RetryWanJoin = make([]string, 0, len(a.RetryWanJoin)+len(b.RetryWanJoin)) - result.RetryWanJoin = append(result.RetryWanJoin, a.RetryWanJoin...) - result.RetryWanJoin = append(result.RetryWanJoin, b.RetryWanJoin...) + result.RetryJoinWan = make([]string, 0, len(a.RetryJoinWan)+len(b.RetryJoinWan)) + result.RetryJoinWan = append(result.RetryJoinWan, a.RetryJoinWan...) + result.RetryJoinWan = append(result.RetryJoinWan, b.RetryJoinWan...) return &result } diff --git a/command/agent/config_test.go b/command/agent/config_test.go index 420c6c4a6..9197447d9 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -274,20 +274,20 @@ func TestDecodeConfig(t *testing.T) { t.Fatalf("bad: %#v", config) } - // Start Wan join - input = `{"start_wan_join": ["1.1.1.1", "2.2.2.2"]}` + // Start Join wan + input = `{"start_join_wan": ["1.1.1.1", "2.2.2.2"]}` config, err = DecodeConfig(bytes.NewReader([]byte(input))) if err != nil { t.Fatalf("err: %s", err) } - if len(config.StartWanJoin) != 2 { + if len(config.StartJoinWan) != 2 { t.Fatalf("bad: %#v", config) } - if config.StartWanJoin[0] != "1.1.1.1" { + if config.StartJoinWan[0] != "1.1.1.1" { t.Fatalf("bad: %#v", config) } - if config.StartWanJoin[1] != "2.2.2.2" { + if config.StartJoinWan[1] != "2.2.2.2" { t.Fatalf("bad: %#v", config) } @@ -333,45 +333,45 @@ func TestDecodeConfig(t *testing.T) { t.Fatalf("bad: %#v", config) } - // Retry WAN join - input = `{"retry_wan_join": ["1.1.1.1", "2.2.2.2"]}` + // Retry Join wan + input = `{"retry_join_wan": ["1.1.1.1", "2.2.2.2"]}` config, err = DecodeConfig(bytes.NewReader([]byte(input))) if err != nil { t.Fatalf("err: %s", err) } - if len(config.RetryWanJoin) != 2 { + if len(config.RetryJoinWan) != 2 { t.Fatalf("bad: %#v", config) } - if config.RetryWanJoin[0] != "1.1.1.1" { + if config.RetryJoinWan[0] != "1.1.1.1" { t.Fatalf("bad: %#v", config) } - if config.RetryWanJoin[1] != "2.2.2.2" { + if config.RetryJoinWan[1] != "2.2.2.2" { t.Fatalf("bad: %#v", config) } - // Retry WAN interval - input = `{"retry_wan_interval": "10s"}` + // Retry Interval wan + input = `{"retry_interval_wan": "10s"}` config, err = DecodeConfig(bytes.NewReader([]byte(input))) if err != nil { t.Fatalf("err: %s", err) } - if config.RetryWanIntervalRaw != "10s" { + if config.RetryIntervalWanRaw != "10s" { t.Fatalf("bad: %#v", config) } - if config.RetryWanInterval.String() != "10s" { + if config.RetryIntervalWan.String() != "10s" { t.Fatalf("bad: %#v", config) } - // Retry WAN Max - input = `{"retry_wan_max": 3}` + // Retry Max wan + input = `{"retry_max_wan": 3}` config, err = DecodeConfig(bytes.NewReader([]byte(input))) if err != nil { t.Fatalf("err: %s", err) } - if config.RetryWanMaxAttempts != 3 { + if config.RetryMaxAttemptsWan != 3 { t.Fatalf("bad: %#v", config) } @@ -919,16 +919,16 @@ func TestMergeConfig(t *testing.T) { Checks: []*CheckDefinition{nil}, Services: []*ServiceDefinition{nil}, StartJoin: []string{"1.1.1.1"}, - StartWanJoin: []string{"1.1.1.1"}, + StartJoinWan: []string{"1.1.1.1"}, UiDir: "/opt/consul-ui", EnableSyslog: true, RejoinAfterLeave: true, RetryJoin: []string{"1.1.1.1"}, RetryIntervalRaw: "10s", RetryInterval: 10 * time.Second, - RetryWanJoin: []string{"1.1.1.1"}, - RetryWanIntervalRaw: "10s", - RetryWanInterval: 10 * time.Second, + RetryJoinWan: []string{"1.1.1.1"}, + RetryIntervalWanRaw: "10s", + RetryIntervalWan: 10 * time.Second, CheckUpdateInterval: 8 * time.Minute, CheckUpdateIntervalRaw: "8m", ACLToken: "1234", diff --git a/website/source/docs/agent/options.html.markdown b/website/source/docs/agent/options.html.markdown index bf817f085..51e346ad2 100644 --- a/website/source/docs/agent/options.html.markdown +++ b/website/source/docs/agent/options.html.markdown @@ -110,13 +110,13 @@ The options below are all specified on the command-line. unable to join with any of the specified addresses, agent startup will fail. By default, the agent won't join -wan any nodes when it starts up. -* `-retry-wan-join` - Similar to `retry-join`, but allows retrying a wan join if the first +* `-retry-join-wan` - Similar to `retry-join`, but allows retrying a wan join if the first attempt fails. This is useful for cases where we know the address will become available eventually. -* `-retry-wan-interval` - Time to wait between join -wan attempts. Defaults to 30s. +* `-retry-interval-wan` - Time to wait between join -wan attempts. Defaults to 30s. -* `-retry-wan-max` - The maximum number of join -wan attempts to be made before exiting +* `-retry-max-wan` - The maximum number of join -wan attempts to be made before exiting with return code 1. By default, this is set to 0, which will continue to retry the join -wan indefinitely. @@ -354,11 +354,11 @@ definitions support being updated during a reload. * `retry_interval` - Equivalent to the `-retry-interval` command-line flag. -* `retry_wan_join` - Equivalent to the `-retry-wan-join` command-line flag. Takes a list - of addresses to attempt joining to WAN every `retry_wan_interval` until at least one +* `retry_join_wan` - Equivalent to the `-retry-join-wan` command-line flag. Takes a list + of addresses to attempt joining to WAN every `retry_interval_wan` until at least one join -wan works. -* `retry_wan_interval` - Equivalent to the `-retry-wan-interval` command-line flag. +* `retry_interval_wan` - Equivalent to the `-retry-interval-wan` command-line flag. * `server` - Equivalent to the `-server` command-line flag. @@ -374,7 +374,7 @@ definitions support being updated during a reload. * `start_join` - An array of strings specifying addresses of nodes to join upon startup. -* `start_wan_join` - An array of strings specifying addresses of WAN nodes to +* `start_join_wan` - An array of strings specifying addresses of WAN nodes to join -wan upon startup. * `statsd_addr` - This provides the address of a statsd instance. If provided