-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add go-discover support to Nomad clients #4277
Changes from 20 commits
1a854c4
f68a040
02b89ae
0770f03
b4a0f2c
98f2947
ef90b44
023cc2c
e93dc53
58a6131
02a64d0
fa1d2de
94cf42e
236ac65
3d12b3f
4b20a69
907def0
13f8e91
2dde49e
92096d6
84b4e2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,9 +63,11 @@ func (c *Command) readConfig() *Config { | |
Client: &ClientConfig{}, | ||
Consul: &config.ConsulConfig{}, | ||
Ports: &Ports{}, | ||
Server: &ServerConfig{}, | ||
Vault: &config.VaultConfig{}, | ||
ACL: &ACLConfig{}, | ||
Server: &ServerConfig{ | ||
ServerJoin: &ServerJoin{}, | ||
}, | ||
Vault: &config.VaultConfig{}, | ||
ACL: &ACLConfig{}, | ||
} | ||
|
||
flags := flag.NewFlagSet("agent", flag.ContinueOnError) | ||
|
@@ -78,13 +80,16 @@ func (c *Command) readConfig() *Config { | |
|
||
// Server-only options | ||
flags.IntVar(&cmdConfig.Server.BootstrapExpect, "bootstrap-expect", 0, "") | ||
flags.BoolVar(&cmdConfig.Server.RejoinAfterLeave, "rejoin", false, "") | ||
flags.Var((*flaghelper.StringFlag)(&cmdConfig.Server.StartJoin), "join", "") | ||
flags.Var((*flaghelper.StringFlag)(&cmdConfig.Server.RetryJoin), "retry-join", "") | ||
flags.IntVar(&cmdConfig.Server.RetryMaxAttempts, "retry-max", 0, "") | ||
flags.StringVar(&cmdConfig.Server.RetryInterval, "retry-interval", "", "") | ||
flags.StringVar(&cmdConfig.Server.EncryptKey, "encrypt", "", "gossip encryption key") | ||
flags.IntVar(&cmdConfig.Server.RaftProtocol, "raft-protocol", 0, "") | ||
flags.BoolVar(&cmdConfig.Server.RejoinAfterLeave, "rejoin", false, "") | ||
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.Var((flaghelper.FuncDurationVar)(func(d time.Duration) error { | ||
cmdConfig.Server.ServerJoin.RetryInterval = d | ||
return nil | ||
}), "retry-interval", "") | ||
|
||
// Client-only options | ||
flags.StringVar(&cmdConfig.Client.StateDir, "state-dir", "", "") | ||
|
@@ -267,14 +272,6 @@ func (c *Command) readConfig() *Config { | |
} | ||
} | ||
|
||
// Parse the RetryInterval. | ||
dur, err := time.ParseDuration(config.Server.RetryInterval) | ||
if err != nil { | ||
c.Ui.Error(fmt.Sprintf("Error parsing retry interval: %s", err)) | ||
return nil | ||
} | ||
config.Server.retryInterval = dur | ||
|
||
// Check that the server is running in at least one mode. | ||
if !(config.Server.Enabled || config.Client.Enabled) { | ||
c.Ui.Error("Must specify either server, client or dev mode for the agent.") | ||
|
@@ -547,20 +544,89 @@ func (c *Command) Run(args []string) int { | |
logGate.Flush() | ||
|
||
// Start retry join process | ||
c.retryJoinErrCh = make(chan struct{}) | ||
|
||
joiner := retryJoiner{ | ||
join: c.agent.server.Join, | ||
discover: &discover.Discover{}, | ||
errCh: c.retryJoinErrCh, | ||
logger: c.agent.logger, | ||
if err := c.handleRetryJoin(config); err != nil { | ||
c.Ui.Error(err.Error()) | ||
return 1 | ||
} | ||
go joiner.RetryJoin(config) | ||
|
||
// Wait for exit | ||
return c.handleSignals() | ||
} | ||
|
||
// handleRetryJoin is used to start retry joining if it is configured. | ||
func (c *Command) handleRetryJoin(config *Config) error { | ||
c.retryJoinErrCh = make(chan struct{}) | ||
|
||
if config.Server.Enabled && len(config.Server.RetryJoin) != 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure there is verification that:
|
||
joiner := retryJoiner{ | ||
discover: &discover.Discover{}, | ||
errCh: c.retryJoinErrCh, | ||
logger: c.agent.logger, | ||
serverJoin: c.agent.server.Join, | ||
serverEnabled: true, | ||
} | ||
|
||
if err := joiner.Validate(config); err != nil { | ||
return err | ||
} | ||
|
||
// Remove the duplicate fields | ||
if len(config.Server.RetryJoin) != 0 { | ||
config.Server.ServerJoin.RetryJoin = config.Server.RetryJoin | ||
config.Server.RetryJoin = nil | ||
} | ||
if config.Server.RetryMaxAttempts != 0 { | ||
config.Server.ServerJoin.RetryMaxAttempts = config.Server.RetryMaxAttempts | ||
config.Server.RetryMaxAttempts = 0 | ||
} | ||
if config.Server.RetryInterval != 0 { | ||
config.Server.ServerJoin.RetryInterval = config.Server.RetryInterval | ||
config.Server.RetryInterval = 0 | ||
} | ||
|
||
c.agent.logger.Printf("[WARN] agent: Using deprecated retry_join fields. Upgrade configuration to use server_join") | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like only one of the two (either config.Server.RetryJoin or config.Server.RetryJoin) should be set? If both are set it should fail validation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in adding a |
||
if config.Server.Enabled && | ||
config.Server.ServerJoin != nil && | ||
len(config.Server.ServerJoin.RetryJoin) != 0 { | ||
|
||
joiner := retryJoiner{ | ||
discover: &discover.Discover{}, | ||
errCh: c.retryJoinErrCh, | ||
logger: c.agent.logger, | ||
serverJoin: c.agent.server.Join, | ||
serverEnabled: true, | ||
} | ||
|
||
if err := joiner.Validate(config); err != nil { | ||
return err | ||
} | ||
|
||
go joiner.RetryJoin(config.Server.ServerJoin) | ||
} | ||
|
||
if config.Client.Enabled && | ||
config.Client.ServerJoin != nil && | ||
len(config.Client.ServerJoin.RetryJoin) != 0 { | ||
joiner := retryJoiner{ | ||
discover: &discover.Discover{}, | ||
errCh: c.retryJoinErrCh, | ||
logger: c.agent.logger, | ||
clientJoin: c.agent.client.SetServers, | ||
clientEnabled: true, | ||
} | ||
|
||
if err := joiner.Validate(config); err != nil { | ||
return err | ||
} | ||
|
||
go joiner.RetryJoin(config.Client.ServerJoin) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// handleSignals blocks until we get an exit-causing signal | ||
func (c *Command) handleSignals() int { | ||
signalCh := make(chan os.Signal, 4) | ||
|
@@ -831,12 +897,34 @@ func (c *Command) setupTelemetry(config *Config) (*metrics.InmemSink, error) { | |
} | ||
|
||
func (c *Command) startupJoin(config *Config) error { | ||
if len(config.Server.StartJoin) == 0 || !config.Server.Enabled { | ||
// Nothing to do | ||
if !config.Server.Enabled { | ||
return nil | ||
} | ||
|
||
// Validate both old and new aren't being set | ||
old := len(config.Server.StartJoin) | ||
var new int | ||
if config.Server.ServerJoin != nil { | ||
new = len(config.Server.ServerJoin.StartJoin) | ||
} | ||
if old != 0 && new != 0 { | ||
return fmt.Errorf("server_join and start_join cannot both be defined; prefer setting the server_join stanza") | ||
} | ||
|
||
// Nothing to do | ||
if old+new == 0 { | ||
return nil | ||
} | ||
|
||
// Combine the lists and join | ||
joining := config.Server.StartJoin | ||
if new != 0 { | ||
joining = append(joining, config.Server.ServerJoin.StartJoin...) | ||
} | ||
|
||
c.Ui.Output("Joining cluster...") | ||
n, err := c.agent.server.Join(config.Server.StartJoin) | ||
n, err := c.agent.server.Join(joining) | ||
if err != nil { | ||
return err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why SetServers changed to return the number of endpoints if its not being used here where its called
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We decided to change this so it has the same interface as
Join
for servers, as we both use them as handles toRetryJoiner
.