Skip to content

Commit d1c51d3

Browse files
Merge pull request #65 from lisongmin/support-dns-via-network-stanza
support config dns via network stanza
2 parents f6de0b4 + e0abb30 commit d1c51d3

File tree

6 files changed

+526
-23
lines changed

6 files changed

+526
-23
lines changed

containerd/driver.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/hashicorp/nomad/client/stats"
3232
"github.com/hashicorp/nomad/client/taskenv"
3333
"github.com/hashicorp/nomad/drivers/shared/eventer"
34+
"github.com/hashicorp/nomad/drivers/shared/resolvconf"
3435
"github.com/hashicorp/nomad/plugins/base"
3536
"github.com/hashicorp/nomad/plugins/drivers"
3637
"github.com/hashicorp/nomad/plugins/shared/hclspec"
@@ -229,7 +230,7 @@ func NewPlugin(logger log.Logger) drivers.DriverPlugin {
229230
}
230231
}
231232

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

244245
tc.Mounts = append(tc.Mounts, hm)
245246
}
247+
248+
if cfg.DNS != nil {
249+
dnsMount, err := resolvconf.GenerateDNSMount(cfg.TaskDir().Dir, cfg.DNS)
250+
if err != nil {
251+
return fmt.Errorf("failed to build mount for resolv.conf: %v", err)
252+
}
253+
tc.HostDNS = false
254+
tc.Mounts = append(tc.Mounts, Mount{
255+
Type: "bind",
256+
Target: dnsMount.TaskPath,
257+
Source: dnsMount.HostPath,
258+
Options: []string{"bind", "ro"},
259+
})
260+
}
261+
return nil
246262
}
247263

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

364-
driverConfig.setVolumeMounts(cfg)
380+
if err := driverConfig.setVolumeMounts(cfg); err != nil {
381+
return nil, nil, err
382+
}
365383

366384
d.logger.Info("starting task", "driver_cfg", hclog.Fmt("%+v", driverConfig))
367385
handle := drivers.NewTaskHandle(taskHandleVersion)

example/dns.nomad

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
job "dns" {
3+
datacenters = ["dc1"]
4+
5+
group "dns-group" {
6+
7+
network {
8+
dns {
9+
servers = ["127.0.0.1", "127.0.0.2"]
10+
searches = ["internal.corp"]
11+
options = ["ndots:2"]
12+
}
13+
}
14+
15+
task "dns-task" {
16+
driver = "containerd-driver"
17+
config {
18+
image = "docker.io/library/ubuntu:16.04"
19+
command = "sleep"
20+
args = ["600s"]
21+
}
22+
23+
resources {
24+
cpu = 500
25+
memory = 256
26+
}
27+
}
28+
}
29+
}

go.mod

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,29 @@ require (
1818
github.com/coreos/go-iptables v0.4.3 // indirect
1919
github.com/coreos/go-semver v0.3.0 // indirect
2020
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
21-
github.com/cyphar/filepath-securejoin v0.2.2 // indirect
22-
github.com/docker/cli v0.0.0-20191202230238-13fb276442f5 // indirect
23-
github.com/docker/docker v1.13.1 // indirect
2421
github.com/docker/docker-credential-helpers v0.6.3 // indirect
2522
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
2623
github.com/docker/go-metrics v0.0.1 // indirect
2724
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
28-
github.com/fsouza/go-dockerclient v1.6.0 // indirect
2925
github.com/gogo/googleapis v1.4.0 // indirect
3026
github.com/google/uuid v1.1.2 // indirect
31-
github.com/hashicorp/consul v1.6.2 // indirect
32-
github.com/hashicorp/consul-template v0.23.0
27+
github.com/gorhill/cronexpr v0.0.0-20180427100037-88b0669f7d75 // indirect
28+
github.com/hashicorp/consul-template v0.25.1
3329
github.com/hashicorp/go-envparse v0.0.0-20190703193109-150b3a2a4611 // indirect
34-
github.com/hashicorp/go-getter v1.4.0 // indirect
35-
github.com/hashicorp/go-hclog v0.10.0
36-
github.com/hashicorp/go-plugin v1.0.1
30+
github.com/hashicorp/go-hclog v0.12.0
31+
github.com/hashicorp/go-plugin v1.0.2-0.20191004171845-809113480b55
3732
github.com/hashicorp/go-uuid v1.0.1
3833
github.com/hashicorp/hcl2 v0.0.0-20191002203319-fb75b3253c80 // indirect
39-
github.com/hashicorp/nomad v0.10.1
40-
github.com/hashicorp/nomad/api v0.0.0-20191203164002-b31573ae7206 // indirect
34+
github.com/hashicorp/nomad v1.0.2
4135
github.com/mitchellh/go-ps v0.0.0-20190716172923-621e5597135b // indirect
42-
github.com/mrunalp/fileutils v0.0.0-20171103030105-7d4729fb3618 // indirect
43-
github.com/opencontainers/runc v1.0.0-rc8.0.20190611121236-6cc515888830 // indirect
44-
github.com/opencontainers/runtime-spec v1.0.2
45-
github.com/opencontainers/selinux v1.3.1 // indirect
46-
github.com/seccomp/libseccomp-golang v0.9.1 // indirect
47-
github.com/shirou/gopsutil v2.19.11+incompatible // indirect
36+
github.com/opencontainers/runtime-spec v1.0.3-0.20200728170252-4d89ac9fbff6
4837
github.com/spf13/cobra v1.1.1
4938
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2 // indirect
5039
github.com/ugorji/go v1.1.7 // indirect
5140
github.com/vbatts/tar-split v0.11.1 // indirect
52-
github.com/zclconf/go-cty v1.1.1 // indirect
5341
go4.org v0.0.0-20191010144846-132d2879e1e9 // indirect
5442
google.golang.org/grpc v1.32.0 // indirect
43+
istio.io/gogo-genproto v0.0.0-20190124151557-6d926a6e6feb // indirect
5544
)
5645

5746
// use lower-case sirupsen

0 commit comments

Comments
 (0)