Skip to content

Commit

Permalink
config: Ability to configure dns server list (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
towe75 authored Jul 31, 2020
1 parent 7ff3b5f commit 49d9894
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

FEATURES:

* config: Ability to configure dns server list

## 0.1.0

FEATURES:
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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"`
}
1 change: 1 addition & 0 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
52 changes: 52 additions & 0 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 49d9894

Please sign in to comment.