Add check for missing `path` in client `host_volume` config (#17393)

This commit is contained in:
Dao Thanh Tung 2023-06-06 07:31:19 +08:00 committed by GitHub
parent 2d16ec6c6f
commit 7c7f2d00bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 0 deletions

3
.changelog/17393.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
cli: Add check for missing host volume `path` in `nomad config validate` command
```

View File

@ -393,6 +393,13 @@ func (c *Command) IsValidConfig(config, cmdConfig *Config) bool {
} }
} }
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 { 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)) c.Ui.Error(fmt.Sprintf("Invalid dynamic port range: min_dynamic_port=%d", config.Client.MinDynamicPort))
return false return false

View File

@ -430,6 +430,48 @@ func TestIsValidConfig(t *testing.T) {
}, },
err: "client.artifact block invalid: http_read_timeout must be > 0", 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 { for _, tc := range cases {