Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #56 Plumb through Nomad network -> dns to podman #78

Merged
merged 1 commit into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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 != "" {
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