Skip to content

Commit

Permalink
Issue #56 Plumb through Nomad network -> dns to podman (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
towe75 authored Mar 22, 2021
1 parent e9a9fe2 commit a50f006
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

```
Expand Down
1 change: 0 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
14 changes: 9 additions & 5 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,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 != "" {
Expand Down
19 changes: 13 additions & 6 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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")

}

Expand Down

0 comments on commit a50f006

Please sign in to comment.