diff --git a/command/agent/config.go b/command/agent/config.go index 2e560ac423d..5f0e20b1d70 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -270,9 +270,6 @@ type ClientConfig struct { // available to jobs running on this node. HostVolumes []*structs.ClientHostVolumeConfig `hcl:"host_volume"` - // ExtraKeysHCL is used by hcl to surface unexpected keys - ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"` - // CNIPath is the path to search for CNI plugins, multiple paths can be // specified colon delimited CNIPath string `hcl:"cni_path"` @@ -285,6 +282,9 @@ type ClientConfig struct { // creating allocations with bridge networking mode. This range is local to // the host BridgeNetworkSubnet string `hcl:"bridge_network_subnet"` + + // ExtraKeysHCL is used by hcl to surface unexpected keys + ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"` } // ClientTemplateConfig is configuration on the client specific to template @@ -1480,6 +1480,16 @@ func (a *ClientConfig) Merge(b *ClientConfig) *ClientConfig { result.HostVolumes = structs.HostVolumeSliceMerge(a.HostVolumes, b.HostVolumes) } + if b.CNIPath != "" { + result.CNIPath = b.CNIPath + } + if b.BridgeNetworkName != "" { + result.BridgeNetworkName = b.BridgeNetworkName + } + if b.BridgeNetworkSubnet != "" { + result.BridgeNetworkSubnet = b.BridgeNetworkSubnet + } + return &result } diff --git a/command/agent/config_parse_test.go b/command/agent/config_parse_test.go index 3ce17332432..eb9691ef1a6 100644 --- a/command/agent/config_parse_test.go +++ b/command/agent/config_parse_test.go @@ -86,6 +86,9 @@ var basicConfig = &Config{ HostVolumes: []*structs.ClientHostVolumeConfig{ {Name: "tmp", Path: "/tmp"}, }, + CNIPath: "/tmp/cni_path", + BridgeNetworkName: "custom_bridge_name", + BridgeNetworkSubnet: "custom_bridge_subnet", }, Server: &ServerConfig{ Enabled: true, @@ -369,6 +372,29 @@ var nonoptConfig = &Config{ Sentinel: nil, } +func TestConfig_ParseMerge(t *testing.T) { + t.Parallel() + + path, err := filepath.Abs(filepath.Join(".", "testdata", "basic.hcl")) + require.NoError(t, err) + + actual, err := ParseConfigFile(path) + require.NoError(t, err) + + require.Equal(t, basicConfig.Client, actual.Client) + + oldDefault := &Config{ + Consul: config.DefaultConsulConfig(), + Vault: config.DefaultVaultConfig(), + Autopilot: config.DefaultAutopilotConfig(), + Client: &ClientConfig{}, + Server: &ServerConfig{}, + } + merged := oldDefault.Merge(actual) + require.Equal(t, basicConfig.Client, merged.Client) + +} + func TestConfig_Parse(t *testing.T) { t.Parallel() diff --git a/command/agent/testdata/basic.hcl b/command/agent/testdata/basic.hcl index 43b481ee9d1..a3d3bcb9eb3 100644 --- a/command/agent/testdata/basic.hcl +++ b/command/agent/testdata/basic.hcl @@ -95,6 +95,10 @@ client { host_volume "tmp" { path = "/tmp" } + + cni_path = "/tmp/cni_path" + bridge_network_name = "custom_bridge_name" + bridge_network_subnet = "custom_bridge_subnet" } server { diff --git a/command/agent/testdata/basic.json b/command/agent/testdata/basic.json index b7575f02eb4..7048d681eba 100644 --- a/command/agent/testdata/basic.json +++ b/command/agent/testdata/basic.json @@ -36,6 +36,8 @@ "client": [ { "alloc_dir": "/tmp/alloc", + "bridge_network_name": "custom_bridge_name", + "bridge_network_subnet": "custom_bridge_subnet", "chroot_env": [ { "/opt/myapp/bin": "/bin", @@ -44,6 +46,7 @@ ], "client_max_port": 2000, "client_min_port": 1000, + "cni_path": "/tmp/cni_path", "cpu_total_compute": 4444, "disable_remote_exec": true, "enabled": true,