mirror of https://github.com/docker/cli.git
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:
commit
c3cf029a49
|
@ -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
|
||||||
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -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",
|
||||||
|
|
Loading…
Reference in New Issue