Merge pull request #2992 from decoomanj/master

Added dnsoptions to the docker driver
This commit is contained in:
Alex Dadgar 2017-08-11 10:12:36 -07:00 committed by GitHub
commit 2fdfd9af4a
3 changed files with 14 additions and 1 deletions

View File

@ -153,6 +153,7 @@ type DockerDriverConfig struct {
Privileged bool `mapstructure:"privileged"` // Flag to run the container in privileged mode
DNSServers []string `mapstructure:"dns_servers"` // DNS Server for containers
DNSSearchDomains []string `mapstructure:"dns_search_domains"` // DNS Search domains for containers
DNSOptions []string `mapstructure:"dns_options"` // DNS Options
ExtraHosts []string `mapstructure:"extra_hosts"` // Add host to /etc/hosts (host:IP)
Hostname string `mapstructure:"hostname"` // Hostname for containers
LabelsRaw []map[string]string `mapstructure:"labels"` //
@ -205,6 +206,7 @@ func NewDockerDriverConfig(task *structs.Task, env *env.TaskEnv) (*DockerDriverC
dconf.VolumeDriver = env.ReplaceEnv(dconf.VolumeDriver)
dconf.DNSServers = env.ParseAndReplace(dconf.DNSServers)
dconf.DNSSearchDomains = env.ParseAndReplace(dconf.DNSSearchDomains)
dconf.DNSOptions = env.ParseAndReplace(dconf.DNSOptions)
dconf.ExtraHosts = env.ParseAndReplace(dconf.ExtraHosts)
dconf.MacAddress = env.ReplaceEnv(dconf.MacAddress)
dconf.SecurityOpt = env.ParseAndReplace(dconf.SecurityOpt)
@ -409,6 +411,9 @@ func (d *DockerDriver) Validate(config map[string]interface{}) error {
"dns_servers": &fields.FieldSchema{
Type: fields.TypeArray,
},
"dns_options": &fields.FieldSchema{
Type: fields.TypeArray,
},
"dns_search_domains": &fields.FieldSchema{
Type: fields.TypeArray,
},
@ -937,6 +942,7 @@ func (d *DockerDriver) createContainerConfig(ctx *ExecContext, task *structs.Tas
// set DNS search domains and extra hosts
hostConfig.DNSSearch = driverConfig.DNSSearchDomains
hostConfig.DNSOptions = driverConfig.DNSOptions
hostConfig.ExtraHosts = driverConfig.ExtraHosts
hostConfig.IpcMode = driverConfig.IpcMode

View File

@ -861,6 +861,7 @@ func TestDockerDriver_DNS(t *testing.T) {
task, _, _ := dockerTask()
task.Config["dns_servers"] = []string{"8.8.8.8", "8.8.4.4"}
task.Config["dns_search_domains"] = []string{"example.com", "example.org", "example.net"}
task.Config["dns_options"] = []string{"ndots:1"}
client, handle, cleanup := dockerSetup(t, task)
defer cleanup()
@ -877,7 +878,11 @@ func TestDockerDriver_DNS(t *testing.T) {
}
if !reflect.DeepEqual(task.Config["dns_search_domains"], container.HostConfig.DNSSearch) {
t.Errorf("DNS Servers don't match.\nExpected:\n%s\nGot:\n%s\n", task.Config["dns_search_domains"], container.HostConfig.DNSSearch)
t.Errorf("DNS Search Domains don't match.\nExpected:\n%s\nGot:\n%s\n", task.Config["dns_search_domains"], container.HostConfig.DNSSearch)
}
if !reflect.DeepEqual(task.Config["dns_options"], container.HostConfig.DNSOptions) {
t.Errorf("DNS Options don't match.\nExpected:\n%s\nGot:\n%s\n", task.Config["dns_options"], container.HostConfig.DNSOptions)
}
}

View File

@ -78,6 +78,8 @@ The `docker` driver supports the following configuration in the job spec. Only
* `dns_search_domains` - (Optional) A list of DNS search domains for the container
to use.
* `dns_options` - (Optional) A list of DNS options for the container to use.
* `dns_servers` - (Optional) A list of DNS servers for the container to use
(e.g. ["8.8.8.8", "8.8.4.4"]). Requires Docker v1.10 or greater.