Skip to content

Commit

Permalink
support config dns via network stanza
Browse files Browse the repository at this point in the history
  • Loading branch information
lisongmin committed Jan 24, 2021
1 parent 6650170 commit 00e68df
Show file tree
Hide file tree
Showing 6 changed files with 517 additions and 24 deletions.
22 changes: 20 additions & 2 deletions containerd/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/hashicorp/nomad/client/stats"
"github.com/hashicorp/nomad/client/taskenv"
"github.com/hashicorp/nomad/drivers/shared/eventer"
"github.com/hashicorp/nomad/drivers/shared/resolvconf"
"github.com/hashicorp/nomad/plugins/base"
"github.com/hashicorp/nomad/plugins/drivers"
"github.com/hashicorp/nomad/plugins/shared/hclspec"
Expand Down Expand Up @@ -229,7 +230,7 @@ func NewPlugin(logger log.Logger) drivers.DriverPlugin {
}
}

func (tc *TaskConfig) setVolumeMounts(cfg *drivers.TaskConfig) {
func (tc *TaskConfig) setVolumeMounts(cfg *drivers.TaskConfig) error {
for _, m := range cfg.Mounts {
hm := Mount{
Type: "bind",
Expand All @@ -243,6 +244,21 @@ func (tc *TaskConfig) setVolumeMounts(cfg *drivers.TaskConfig) {

tc.Mounts = append(tc.Mounts, hm)
}

if cfg.DNS != nil {
dnsMount, err := resolvconf.GenerateDNSMount(cfg.TaskDir().Dir, cfg.DNS)
if err != nil {
return fmt.Errorf("failed to build mount for resolv.conf: %v", err)
}
tc.HostDNS = false
tc.Mounts = append(tc.Mounts, Mount{
Type: "bind",
Target: dnsMount.TaskPath,
Source: dnsMount.HostPath,
Options: []string{"bind", "ro"},
})
}
return nil
}

// PluginInfo returns information describing the plugin.
Expand Down Expand Up @@ -361,7 +377,9 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
return nil, nil, fmt.Errorf("host_network and bridge network mode are mutually exclusive, and only one of them should be set")
}

driverConfig.setVolumeMounts(cfg)
if err := driverConfig.setVolumeMounts(cfg); err != nil {
return nil, nil, err
}

d.logger.Info("starting task", "driver_cfg", hclog.Fmt("%+v", driverConfig))
handle := drivers.NewTaskHandle(taskHandleVersion)
Expand Down
27 changes: 27 additions & 0 deletions example/dns.nomad
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

job "dns" {
datacenters = ["dc1"]

group "dns-group" {

network {
dns {
servers = ["127.0.0.1", "127.0.0.2"]
}
}

task "dns-task" {
driver = "containerd-driver"
config {
image = "docker.io/library/ubuntu:16.04"
command = "sleep"
args = ["600s"]
}

resources {
cpu = 500
memory = 256
}
}
}
}
25 changes: 7 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,29 @@ require (
github.com/coreos/go-iptables v0.4.3 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/cyphar/filepath-securejoin v0.2.2 // indirect
github.com/docker/cli v0.0.0-20191202230238-13fb276442f5 // indirect
github.com/docker/docker v1.13.1 // indirect
github.com/docker/docker-credential-helpers v0.6.3 // indirect
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
github.com/fsouza/go-dockerclient v1.6.0 // indirect
github.com/gogo/googleapis v1.4.0 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/hashicorp/consul v1.6.2 // indirect
github.com/hashicorp/consul-template v0.23.0
github.com/gorhill/cronexpr v0.0.0-20180427100037-88b0669f7d75 // indirect
github.com/hashicorp/consul-template v0.25.1
github.com/hashicorp/go-envparse v0.0.0-20190703193109-150b3a2a4611 // indirect
github.com/hashicorp/go-getter v1.4.0 // indirect
github.com/hashicorp/go-hclog v0.10.0
github.com/hashicorp/go-plugin v1.0.1
github.com/hashicorp/go-hclog v0.12.0
github.com/hashicorp/go-plugin v1.0.2-0.20191004171845-809113480b55
github.com/hashicorp/go-uuid v1.0.1
github.com/hashicorp/hcl2 v0.0.0-20191002203319-fb75b3253c80 // indirect
github.com/hashicorp/nomad v0.10.1
github.com/hashicorp/nomad/api v0.0.0-20191203164002-b31573ae7206 // indirect
github.com/hashicorp/nomad v1.0.2
github.com/mitchellh/go-ps v0.0.0-20190716172923-621e5597135b // indirect
github.com/mrunalp/fileutils v0.0.0-20171103030105-7d4729fb3618 // indirect
github.com/opencontainers/runc v1.0.0-rc8.0.20190611121236-6cc515888830 // indirect
github.com/opencontainers/runtime-spec v1.0.2
github.com/opencontainers/selinux v1.3.1 // indirect
github.com/seccomp/libseccomp-golang v0.9.1 // indirect
github.com/shirou/gopsutil v2.19.11+incompatible // indirect
github.com/opencontainers/runtime-spec v1.0.3-0.20200728170252-4d89ac9fbff6
github.com/spf13/cobra v1.1.1
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2 // indirect
github.com/ugorji/go v1.1.7 // indirect
github.com/vbatts/tar-split v0.11.1 // indirect
github.com/zclconf/go-cty v1.1.1 // indirect
go4.org v0.0.0-20191010144846-132d2879e1e9 // indirect
google.golang.org/grpc v1.32.0 // indirect
istio.io/gogo-genproto v0.0.0-20190124151557-6d926a6e6feb // indirect
)

// use lower-case sirupsen
Expand Down
Loading

0 comments on commit 00e68df

Please sign in to comment.