From 56cb33808390083a380df4b13f7269e001cd2c7b Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Sun, 21 Mar 2021 10:56:25 +0100 Subject: [PATCH] Issue #56 Plumb through Nomad network -> dns to podman --- README.md | 11 +---------- config.go | 1 - driver.go | 14 +++++++++----- driver_test.go | 19 +++++++++++++------ 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index b01de37c..439a94fe 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ this plugin to Nomad! * Set username or UID used for the specified command within the container (podman --user option). * Fine tune memory usage: standard [Nomad memory resource](https://www.nomadproject.io/docs/job-specification/resources.html#memory) plus additional driver specific swap, swappiness and reservation parameters, OOM handling * Supports rootless containers with cgroup V2 +* Set DNS servers, searchlist and options via [Nomad dns parameters](https://www.nomadproject.io/docs/job-specification/network#dns-parameters) ## Building The Driver from source @@ -267,16 +268,6 @@ config { } ``` -* **dns** - (Optional) A list of dns servers. Replaces the default from podman binary and containers.conf. - -``` -config { - dns = [ - "1.1.1.1" - ] -} -``` - * **sysctl** - (Optional) A key-value map of sysctl configurations to set to the containers on start. ``` diff --git a/config.go b/config.go index 7810a7a0..b5ef1b60 100644 --- a/config.go +++ b/config.go @@ -90,7 +90,6 @@ type TaskConfig struct { Volumes []string `codec:"volumes"` CapAdd []string `codec:"cap_add"` CapDrop []string `codec:"cap_drop"` - Dns []string `codec:"dns"` Command string `codec:"command"` Entrypoint string `codec:"entrypoint"` WorkingDir string `codec:"working_dir"` diff --git a/driver.go b/driver.go index 72027929..daccbb69 100644 --- a/driver.go +++ b/driver.go @@ -417,12 +417,16 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive createOpts.ContainerSecurityConfig.User = cfg.User // Network config options - for _, strdns := range driverConfig.Dns { - ipdns := net.ParseIP(strdns) - if ipdns == nil { - return nil, nil, fmt.Errorf("Invald dns server address") + if cfg.DNS != nil { + for _, strdns := range cfg.DNS.Servers { + ipdns := net.ParseIP(strdns) + if ipdns == nil { + return nil, nil, fmt.Errorf("Invald dns server address") + } + createOpts.ContainerNetworkConfig.DNSServers = append(createOpts.ContainerNetworkConfig.DNSServers, ipdns) } - createOpts.ContainerNetworkConfig.DNSServers = append(createOpts.ContainerNetworkConfig.DNSServers, ipdns) + createOpts.ContainerNetworkConfig.DNSSearch = append(createOpts.ContainerNetworkConfig.DNSSearch, cfg.DNS.Searches...) + createOpts.ContainerNetworkConfig.DNSOptions = append(createOpts.ContainerNetworkConfig.DNSOptions, cfg.DNS.Options...) } // Configure network if cfg.NetworkIsolation != nil && cfg.NetworkIsolation.Path != "" { diff --git a/driver_test.go b/driver_test.go index 68b11c0a..b94b304e 100644 --- a/driver_test.go +++ b/driver_test.go @@ -1150,18 +1150,23 @@ func TestPodmanDriver_Dns(t *testing.T) { "-c", "sleep 1; cat /etc/resolv.conf", }) - // config { - // dns = [ - // "1.1.1.1" - // ] + // network { + // dns { + // servers = ["1.1.1.1"] + // searches = ["internal.corp"] + // options = ["ndots:2"] + // } // } - taskCfg.Dns = []string{"1.1.1.1"} - task := &drivers.TaskConfig{ ID: uuid.Generate(), Name: "dns", AllocID: uuid.Generate(), Resources: createBasicResources(), + DNS: &drivers.DNSConfig{ + Servers: []string{"1.1.1.1"}, + Searches: []string{"internal.corp"}, + Options: []string{"ndots:2"}, + }, } require.NoError(t, task.EncodeConcreteDriverConfig(&taskCfg)) @@ -1189,6 +1194,8 @@ func TestPodmanDriver_Dns(t *testing.T) { // see if stdout was populated with the correct output tasklog := readLogfile(t, task) require.Contains(t, tasklog, "nameserver 1.1.1.1") + require.Contains(t, tasklog, "search internal.corp") + require.Contains(t, tasklog, "options ndots:2") }