From 95eefbaf650a223018ba0d8929dc2336b9b5284d Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Fri, 31 Jul 2020 02:42:33 -0400 Subject: [PATCH] config: Ability to configure dns server list --- CHANGELOG.md | 6 ++++++ README.md | 10 ++++++++++ config.go | 2 ++ driver.go | 1 + driver_test.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67dbc95e..b23b8633 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## Unreleased + +FEATURES: + +* config: Ability to configure dns server list + ## 0.1.0 FEATURES: diff --git a/README.md b/README.md index e29ef2be..e86b15ff 100644 --- a/README.md +++ b/README.md @@ -269,6 +269,16 @@ config { } ``` +* **dns** - (Optional) A list of dns servers. Replaces the default from podman binary and containers.conf. + +``` +config { + dns = [ + "1.1.1.1" + ] +} +``` + ## Example job ``` diff --git a/config.go b/config.go index 75590caa..1ab01c0f 100644 --- a/config.go +++ b/config.go @@ -59,6 +59,7 @@ var ( "command": hclspec.NewAttr("command", "string", false), "cap_add": hclspec.NewAttr("cap_add", "list(string)", false), "cap_drop": hclspec.NewAttr("cap_drop", "list(string)", false), + "dns": hclspec.NewAttr("dns", "list(string)", false), "entrypoint": hclspec.NewAttr("entrypoint", "string", false), "working_dir": hclspec.NewAttr("working_dir", "string", false), "hostname": hclspec.NewAttr("hostname", "string", false), @@ -113,4 +114,5 @@ type TaskConfig struct { Volumes []string `codec:"volumes"` CapAdd []string `codec:"cap_add"` CapDrop []string `codec:"cap_drop"` + Dns []string `codec:"dns"` } diff --git a/driver.go b/driver.go index dc390a11..db0e7124 100644 --- a/driver.go +++ b/driver.go @@ -433,6 +433,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive CpuShares: &cpuShares, CapAdd: &driverConfig.CapAdd, CapDrop: &driverConfig.CapDrop, + Dns: &driverConfig.Dns, LogOpt: &logOpts, Hostname: &driverConfig.Hostname, Init: &driverConfig.Init, diff --git a/driver_test.go b/driver_test.go index d6d8d0b2..1c96d0c7 100644 --- a/driver_test.go +++ b/driver_test.go @@ -916,6 +916,58 @@ func TestPodmanDriver_Caps(t *testing.T) { require.NotContains(t, inspectData.EffectiveCaps, "CAP_MKNOD") } +// check dns server configuration +func TestPodmanDriver_Dns(t *testing.T) { + if !tu.IsCI() { + t.Parallel() + } + + taskCfg := newTaskConfig("", []string{ + "cat", + "/etc/resolv.conf", + }) + // config { + // dns = [ + // "1.1.1.1" + // ] + // } + taskCfg.Dns = []string{"1.1.1.1"} + + task := &drivers.TaskConfig{ + ID: uuid.Generate(), + Name: "dns", + AllocID: uuid.Generate(), + Resources: createBasicResources(), + } + require.NoError(t, task.EncodeConcreteDriverConfig(&taskCfg)) + + d := podmanDriverHarness(t, nil) + cleanup := d.MkAllocDir(task, true) + defer cleanup() + + _, _, err := d.StartTask(task) + require.NoError(t, err) + + defer d.DestroyTask(task.ID, true) + + // Attempt to wait + waitCh, err := d.WaitTask(context.Background(), task.ID) + require.NoError(t, err) + + select { + case res := <-waitCh: + // should have a exitcode=0 result + require.True(t, res.Successful()) + case <-time.After(time.Duration(tu.TestMultiplier()*2) * time.Second): + t.Fatalf("Container did not exit in time") + } + + // see if stdout was populated with the correct output + tasklog := readLogfile(t, task) + require.Contains(t, tasklog, "nameserver 1.1.1.1") + +} + // TestPodmanDriver_NetworkMode asserts we can specify different network modes // Default podman cni subnet 10.88.0.0/16 func TestPodmanDriver_NetworkMode(t *testing.T) {