Skip to content

Commit

Permalink
Merge pull request #7237 from hashicorp/b-config-cnipath-parsing
Browse files Browse the repository at this point in the history
Honor CNI and bridge related config fields
  • Loading branch information
Mahmood Ali authored Mar 3, 2020
2 parents e702212 + 56e8ee1 commit e31695b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
16 changes: 13 additions & 3 deletions command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
26 changes: 26 additions & 0 deletions command/agent/config_parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()

Expand Down
4 changes: 4 additions & 0 deletions command/agent/testdata/basic.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions command/agent/testdata/basic.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down

0 comments on commit e31695b

Please sign in to comment.