-
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 parsing of client configuration from the commandline #191
Changes from 1 commit
c84fd2b
6c9732c
15a854b
e9254c5
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 |
---|---|---|
|
@@ -70,6 +70,18 @@ func (c *Command) readConfig() *Config { | |
// Server-only options | ||
flags.IntVar(&cmdConfig.Server.BootstrapExpect, "bootstrap-expect", 0, "") | ||
|
||
// Client-only options | ||
flags.StringVar(&cmdConfig.Client.StateDir, "state-dir", "", "") | ||
flags.StringVar(&cmdConfig.Client.AllocDir, "alloc-dir", "", "") | ||
flags.StringVar(&cmdConfig.Client.NodeID, "node-id", "", "") | ||
flags.StringVar(&cmdConfig.Client.NodeClass, "node-class", "", "") | ||
|
||
var servers string | ||
flags.StringVar(&servers, "servers", "", "") | ||
|
||
var meta []string | ||
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. So far we have been putting all of the type declarations at the top so that we don't have to break up these blocks. |
||
flags.Var((*sliceflag.StringFlag)(&meta), "meta", "") | ||
|
||
// General options | ||
flags.Var((*sliceflag.StringFlag)(&configPath), "config", "config") | ||
flags.StringVar(&cmdConfig.BindAddr, "bind", "", "") | ||
|
@@ -88,6 +100,25 @@ func (c *Command) readConfig() *Config { | |
return nil | ||
} | ||
|
||
// Split the servers. | ||
if servers != "" { | ||
cmdConfig.Client.Servers = strings.Split(servers, ",") | ||
} | ||
|
||
// Parse the meta flags. | ||
if len(meta) != 0 { | ||
cmdConfig.Client.Meta = make(map[string]string) | ||
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. You can specify the map length here since we already know it to save a few allocations. |
||
for _, kv := range meta { | ||
parts := strings.Split(kv, "=") | ||
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. We can use |
||
if len(parts) != 2 { | ||
c.Ui.Error(fmt.Sprintf("Error parsing Client.Meta value: %v", kv)) | ||
return nil | ||
} | ||
|
||
cmdConfig.Client.Meta[parts[0]] = parts[1] | ||
} | ||
} | ||
|
||
// Load the configuration | ||
var config *Config | ||
if dev { | ||
|
@@ -134,10 +165,26 @@ func (c *Command) readConfig() *Config { | |
return config | ||
} | ||
|
||
// Check that we have a data-dir | ||
if config.DataDir == "" { | ||
// Check for valid modes. | ||
if config.Server.Enabled && config.Client.Enabled { | ||
c.Ui.Error("To run both as a server and client, use -dev mode.") | ||
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. Do these need to be mutually exclusive? I've used this mode a few times before to see how the client behaves and persists data in a bare minimum set-up. If there's a reason we should actually enforce this then this looks good. 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. I guess that is true. If you wanted to "dev" mode with persistence you could enable both. I will update. |
||
return nil | ||
} else if !(config.Server.Enabled || config.Client.Enabled) { | ||
c.Ui.Error("Must specify either server, client or dev mode for the agent.") | ||
return nil | ||
} | ||
|
||
// Ensure that we have the directories we neet to run. | ||
if config.Server.Enabled && config.DataDir == "" { | ||
c.Ui.Error("Must specify data directory") | ||
return nil | ||
} else if config.Client.Enabled && config.DataDir == "" { | ||
// The config is valid if the top-level data-dir is set or if both | ||
// alloc-dir and state-dir are set. | ||
if config.Client.AllocDir == "" || config.Client.StateDir == "" { | ||
c.Ui.Error("Must specify both the state and alloc dir if data-dir is omitted.") | ||
return nil | ||
} | ||
} | ||
|
||
// Check the bootstrap flags | ||
|
@@ -588,9 +635,35 @@ Server Options: | |
Client Options: | ||
|
||
-client | ||
Enable client mode for the agent. Client mode enables a given node | ||
to be evaluated for allocations. If client mode is not enabled, | ||
no work will be scheduled to the agent. | ||
Enable client mode for the agent. Client mode enables a given node to be | ||
evaluated for allocations. If client mode is not enabled, no work will be | ||
scheduled to the agent. | ||
|
||
-state-dir | ||
The directory used to store state and other persistent data. If not | ||
specified a subdirectory under the "-data-dir" will be used. | ||
|
||
-alloc-dir | ||
The directory used to store allocation data such as downloaded artificats as | ||
well as data produced by tasks. If not specified, a subdirectory under the | ||
"-data-dir" will be used. | ||
|
||
-servers | ||
A list of known server addresses to connect to given as "host:port" and | ||
delimited by commas. | ||
|
||
-node-id | ||
A unique identifier for the node to use. If not provided, a UUID is | ||
generated. | ||
|
||
-node-class | ||
Mark this node as a member of a node-class. This can be used to label | ||
similiar node types. | ||
|
||
-meta | ||
User specified metadata to associated with the node. Each instance of -meta | ||
parses a single KEY=VALUE pair. Repeat the meta flag for each key/value pair | ||
to be added. | ||
|
||
Atlas Options: | ||
|
||
|
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.
Hmm... I see why you did this, as we already have a
-server
arg. It would be nice if we could think of a reasonable name for a flag that you could specify multiple times, but for my lack of creativity this should suffice.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.
Yeah I couldn't think of anything else either.