Merge pull request #32059 from seriousben/support-dns-stack-file

add support for dns nameservers and search domains in stack files
This commit is contained in:
Vincent Demeester 2017-04-11 21:32:52 +02:00 committed by GitHub
commit c3cf029a49
3 changed files with 55 additions and 2 deletions

View File

@ -93,6 +93,11 @@ func convertService(
return swarm.ServiceSpec{}, err return swarm.ServiceSpec{}, err
} }
dnsConfig, err := convertDNSConfig(service.DNS, service.DNSSearch)
if err != nil {
return swarm.ServiceSpec{}, err
}
var logDriver *swarm.Driver var logDriver *swarm.Driver
if service.Logging != nil { if service.Logging != nil {
logDriver = &swarm.Driver{ logDriver = &swarm.Driver{
@ -113,6 +118,7 @@ func convertService(
Args: service.Command, Args: service.Command,
Hostname: service.Hostname, Hostname: service.Hostname,
Hosts: sortStrings(convertExtraHosts(service.ExtraHosts)), Hosts: sortStrings(convertExtraHosts(service.ExtraHosts)),
DNSConfig: dnsConfig,
Healthcheck: healthcheck, Healthcheck: healthcheck,
Env: sortStrings(convertEnvironment(service.Environment)), Env: sortStrings(convertEnvironment(service.Environment)),
Labels: AddStackLabel(namespace, service.Labels), Labels: AddStackLabel(namespace, service.Labels),
@ -446,3 +452,13 @@ func convertDeployMode(mode string, replicas *uint64) (swarm.ServiceMode, error)
} }
return serviceMode, nil return serviceMode, nil
} }
func convertDNSConfig(DNS []string, DNSSearch []string) (*swarm.DNSConfig, error) {
if DNS != nil || DNSSearch != nil {
return &swarm.DNSConfig{
Nameservers: DNS,
Search: DNSSearch,
}, nil
}
return nil, nil
}

View File

@ -277,3 +277,42 @@ func (s byTargetSort) Less(i, j int) bool {
func (s byTargetSort) Swap(i, j int) { func (s byTargetSort) Swap(i, j int) {
s[i], s[j] = s[j], s[i] s[i], s[j] = s[j], s[i]
} }
func TestConvertDNSConfigEmpty(t *testing.T) {
dnsConfig, err := convertDNSConfig(nil, nil)
assert.NilError(t, err)
assert.Equal(t, dnsConfig, (*swarm.DNSConfig)(nil))
}
var (
nameservers = []string{"8.8.8.8", "9.9.9.9"}
search = []string{"dc1.example.com", "dc2.example.com"}
)
func TestConvertDNSConfigAll(t *testing.T) {
dnsConfig, err := convertDNSConfig(nameservers, search)
assert.NilError(t, err)
assert.DeepEqual(t, dnsConfig, &swarm.DNSConfig{
Nameservers: nameservers,
Search: search,
})
}
func TestConvertDNSConfigNameservers(t *testing.T) {
dnsConfig, err := convertDNSConfig(nameservers, nil)
assert.NilError(t, err)
assert.DeepEqual(t, dnsConfig, &swarm.DNSConfig{
Nameservers: nameservers,
Search: nil,
})
}
func TestConvertDNSConfigSearch(t *testing.T) {
dnsConfig, err := convertDNSConfig(nil, search)
assert.NilError(t, err)
assert.DeepEqual(t, dnsConfig, &swarm.DNSConfig{
Nameservers: nil,
Search: search,
})
}

View File

@ -11,8 +11,6 @@ var UnsupportedProperties = []string{
"cap_drop", "cap_drop",
"cgroup_parent", "cgroup_parent",
"devices", "devices",
"dns",
"dns_search",
"domainname", "domainname",
"external_links", "external_links",
"ipc", "ipc",