From 76a071e797cd75415b8fadc4dd5bfad1ef4d25b5 Mon Sep 17 00:00:00 2001 From: Dao Thanh Tung Date: Tue, 6 Jun 2023 07:31:19 +0800 Subject: [PATCH] Add check for missing `path` in client `host_volume` config (#17393) --- .changelog/17393.txt | 3 +++ command/agent/command.go | 7 ++++++ command/agent/command_test.go | 42 +++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 .changelog/17393.txt diff --git a/.changelog/17393.txt b/.changelog/17393.txt new file mode 100644 index 00000000000..f83d9e542ad --- /dev/null +++ b/.changelog/17393.txt @@ -0,0 +1,3 @@ +```release-note:improvement +cli: Add check for missing host volume `path` in `nomad config validate` command +``` diff --git a/command/agent/command.go b/command/agent/command.go index 3b58dc77c62..a9d275ca08e 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -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 diff --git a/command/agent/command_test.go b/command/agent/command_test.go index 3e96f399d0a..d8f9b6cfa96 100644 --- a/command/agent/command_test.go +++ b/command/agent/command_test.go @@ -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 {