Adding support for dns in stack files

Signed-off-by: Benjamin Boudreau <boudreau.benjamin@gmail.com>
This commit is contained in:
Benjamin Boudreau 2017-03-23 19:38:17 -04:00
parent 8a16f32da7
commit 2e126a52f2
3 changed files with 55 additions and 2 deletions

View File

@ -93,6 +93,11 @@ func convertService(
return swarm.ServiceSpec{}, err
}
dnsConfig, err := convertDNSConfig(service.DNS, service.DNSSearch)
if err != nil {
return swarm.ServiceSpec{}, err
}
var logDriver *swarm.Driver
if service.Logging != nil {
logDriver = &swarm.Driver{
@ -113,6 +118,7 @@ func convertService(
Args: service.Command,
Hostname: service.Hostname,
Hosts: sortStrings(convertExtraHosts(service.ExtraHosts)),
DNSConfig: dnsConfig,
Healthcheck: healthcheck,
Env: sortStrings(convertEnvironment(service.Environment)),
Labels: AddStackLabel(namespace, service.Labels),
@ -425,3 +431,13 @@ func convertDeployMode(mode string, replicas *uint64) (swarm.ServiceMode, error)
}
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) {
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",
"cgroup_parent",
"devices",
"dns",
"dns_search",
"domainname",
"external_links",
"ipc",