Skip to content

Commit

Permalink
Add check for missing path in client host_volume config (#17393)
Browse files Browse the repository at this point in the history
  • Loading branch information
dttung2905 authored and lgfa29 committed Jun 5, 2023
1 parent 3dc76fe commit 76a071e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/17393.txt
@@ -0,0 +1,3 @@
```release-note:improvement
cli: Add check for missing host volume `path` in `nomad config validate` command
```
7 changes: 7 additions & 0 deletions command/agent/command.go
Expand Up @@ -376,6 +376,13 @@ func (c *Command) IsValidConfig(config, cmdConfig *Config) bool {
return false
}

for _, volumeConfig := range config.Client.HostVolumes {
if volumeConfig.Path == "" {
c.Ui.Error("Missing path in host_volume config")
return false
}
}

if config.Client.MinDynamicPort < 0 || config.Client.MinDynamicPort > structs.MaxValidPort {
c.Ui.Error(fmt.Sprintf("Invalid dynamic port range: min_dynamic_port=%d", config.Client.MinDynamicPort))
return false
Expand Down
42 changes: 42 additions & 0 deletions command/agent/command_test.go
Expand Up @@ -403,6 +403,48 @@ func TestIsValidConfig(t *testing.T) {
},
err: "client.artifact block invalid: http_read_timeout must be > 0",
},
{
name: "BadHostVolumeConfig",
conf: Config{
DataDir: "/tmp",
Client: &ClientConfig{
Enabled: true,
HostVolumes: []*structs.ClientHostVolumeConfig{
{
Name: "test",
ReadOnly: true,
},
{
Name: "test",
ReadOnly: true,
Path: "/random/path",
},
},
},
},
err: "Missing path in host_volume config",
},
{
name: "ValidHostVolumeConfig",
conf: Config{
DataDir: "/tmp",
Client: &ClientConfig{
Enabled: true,
HostVolumes: []*structs.ClientHostVolumeConfig{
{
Name: "test",
ReadOnly: true,
Path: "/random/path1",
},
{
Name: "test",
ReadOnly: true,
Path: "/random/path2",
},
},
},
},
},
}

for _, tc := range cases {
Expand Down

0 comments on commit 76a071e

Please sign in to comment.