Remove duplication of Dns in config merging.

Fixes #4714
Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)
This commit is contained in:
LK4D4 2014-03-19 21:01:20 +04:00
parent 47470d299d
commit 48cb2f0317
2 changed files with 10 additions and 3 deletions

View File

@ -231,7 +231,7 @@ func TestMerge(t *testing.T) {
volumesUser := make(map[string]struct{})
volumesUser["/test3"] = struct{}{}
configUser := &Config{
Dns: []string{"3.3.3.3"},
Dns: []string{"2.2.2.2", "3.3.3.3"},
PortSpecs: []string{"3333:2222", "3333:3333"},
Env: []string{"VAR2=3", "VAR3=3"},
Volumes: volumesUser,

View File

@ -97,8 +97,15 @@ func Merge(userConf, imageConf *Config) error {
if userConf.Dns == nil || len(userConf.Dns) == 0 {
userConf.Dns = imageConf.Dns
} else {
//duplicates aren't an issue here
userConf.Dns = append(userConf.Dns, imageConf.Dns...)
dnsSet := make(map[string]struct{}, len(userConf.Dns))
for _, dns := range userConf.Dns {
dnsSet[dns] = struct{}{}
}
for _, dns := range imageConf.Dns {
if _, exists := dnsSet[dns]; !exists {
userConf.Dns = append(userConf.Dns, dns)
}
}
}
if userConf.Entrypoint == nil || len(userConf.Entrypoint) == 0 {
userConf.Entrypoint = imageConf.Entrypoint