plugin dir parsing

This commit is contained in:
Alex Dadgar 2018-08-30 13:43:09 -07:00
parent bff1669ee4
commit c0de218747
8 changed files with 34 additions and 7 deletions

View File

@ -87,6 +87,9 @@ func NewAgent(config *Config, logOutput io.Writer, inmem *metrics.InmemSink) (*A
if err := a.setupConsul(config.Consul); err != nil {
return nil, fmt.Errorf("Failed to initialize Consul client: %v", err)
}
// TODO setup plugin loader
if err := a.setupServer(); err != nil {
return nil, err
}

View File

@ -105,6 +105,7 @@ func (c *Command) readConfig() *Config {
flags.StringVar(&cmdConfig.BindAddr, "bind", "", "")
flags.StringVar(&cmdConfig.Region, "region", "", "")
flags.StringVar(&cmdConfig.DataDir, "data-dir", "", "")
flags.StringVar(&cmdConfig.PluginDir, "plugin-dir", "", "")
flags.StringVar(&cmdConfig.Datacenter, "dc", "", "")
flags.StringVar(&cmdConfig.LogLevel, "log-level", "", "")
flags.StringVar(&cmdConfig.NodeName, "node", "", "")
@ -265,6 +266,12 @@ func (c *Command) readConfig() *Config {
}
}
// Default the plugin directory to be under that of the data directory if it
// isn't explicitly specified.
if config.PluginDir == "" && config.DataDir != "" {
config.PluginDir = filepath.Join(config.DataDir, "plugins")
}
if dev {
// Skip validation for dev mode
return config
@ -289,9 +296,10 @@ func (c *Command) readConfig() *Config {
// Verify the paths are absolute.
dirs := map[string]string{
"data-dir": config.DataDir,
"alloc-dir": config.Client.AllocDir,
"state-dir": config.Client.StateDir,
"data-dir": config.DataDir,
"plugin-dir": config.PluginDir,
"alloc-dir": config.Client.AllocDir,
"state-dir": config.Client.StateDir,
}
for k, dir := range dirs {
if dir == "" {
@ -304,7 +312,7 @@ func (c *Command) readConfig() *Config {
}
}
// Ensure that we have the directories we neet to run.
// Ensure that we have the directories we need to run.
if config.Server.Enabled && config.DataDir == "" {
c.Ui.Error("Must specify data directory")
return nil
@ -313,8 +321,8 @@ func (c *Command) readConfig() *Config {
// 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.Enabled && config.DataDir == "" {
if config.Client.AllocDir == "" || config.Client.StateDir == "" {
c.Ui.Error("Must specify both the state and alloc dir if data-dir is omitted.")
if config.Client.AllocDir == "" || config.Client.StateDir == "" || config.PluginDir == "" {
c.Ui.Error("Must specify the state, alloc dir, and plugin dir if data-dir is omitted.")
return nil
}
}
@ -1012,6 +1020,10 @@ General Options (clients and servers):
downloaded artifacts used by drivers. On server nodes, the data
dir is also used to store the replicated log.
-plugin-dir=<path>
The plugin directory is used to discover Nomad plugins. If not specified,
the plugin directory defaults to be that of <data-dir>/plugins/.
-dc=<datacenter>
The name of the datacenter this Nomad agent is a member of. By
default this is set to "dc1".

View File

@ -46,7 +46,7 @@ func TestCommand_Args(t *testing.T) {
},
{
[]string{"-client", "-alloc-dir="},
"Must specify both the state and alloc dir if data-dir is omitted.",
"Must specify the state, alloc dir, and plugin dir if data-dir is omitted.",
},
}
for _, tc := range tcases {

View File

@ -2,6 +2,7 @@ region = "foobar"
datacenter = "dc2"
name = "my-web"
data_dir = "/tmp/nomad"
plugin_dir = "/tmp/nomad-plugins"
log_level = "ERR"
bind_addr = "192.168.0.1"
enable_debug = true

View File

@ -37,6 +37,9 @@ type Config struct {
// DataDir is the directory to store our state in
DataDir string `mapstructure:"data_dir"`
// PluginDir is the directory to lookup plugins.
PluginDir string `mapstructure:"plugin_dir"`
// LogLevel is the level of the logs to putout
LogLevel string `mapstructure:"log_level"`
@ -737,6 +740,9 @@ func (c *Config) Merge(b *Config) *Config {
if b.DataDir != "" {
result.DataDir = b.DataDir
}
if b.PluginDir != "" {
result.PluginDir = b.PluginDir
}
if b.LogLevel != "" {
result.LogLevel = b.LogLevel
}

View File

@ -78,6 +78,7 @@ func parseConfig(result *Config, list *ast.ObjectList) error {
"datacenter",
"name",
"data_dir",
"plugin_dir",
"log_level",
"bind_addr",
"enable_debug",

View File

@ -24,6 +24,7 @@ func TestConfig_Parse(t *testing.T) {
Datacenter: "dc2",
NodeName: "my-web",
DataDir: "/tmp/nomad",
PluginDir: "/tmp/nomad-plugins",
LogLevel: "ERR",
BindAddr: "192.168.0.1",
EnableDebug: true,
@ -245,6 +246,7 @@ func TestConfig_Parse(t *testing.T) {
Datacenter: "",
NodeName: "",
DataDir: "",
PluginDir: "",
LogLevel: "",
BindAddr: "",
EnableDebug: false,

View File

@ -45,6 +45,7 @@ func TestConfig_Merge(t *testing.T) {
Datacenter: "dc1",
NodeName: "node1",
DataDir: "/tmp/dir1",
PluginDir: "/tmp/pluginDir1",
LogLevel: "INFO",
EnableDebug: false,
LeaveOnInt: false,
@ -191,6 +192,7 @@ func TestConfig_Merge(t *testing.T) {
Datacenter: "dc2",
NodeName: "node2",
DataDir: "/tmp/dir2",
PluginDir: "/tmp/pluginDir2",
LogLevel: "DEBUG",
EnableDebug: true,
LeaveOnInt: true,