Remove duplication of Dns in config merging.
This commit is contained in:
Michael Crosby 2014-03-21 17:08:06 -07:00
Родитель 97e5295f43 48cb2f0317
Коммит 5294bf7e67
2 изменённых файлов: 10 добавлений и 3 удалений

Просмотреть файл

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

Просмотреть файл

@ -97,8 +97,15 @@ func Merge(userConf, imageConf *Config) error {
if userConf.Dns == nil || len(userConf.Dns) == 0 { if userConf.Dns == nil || len(userConf.Dns) == 0 {
userConf.Dns = imageConf.Dns userConf.Dns = imageConf.Dns
} else { } else {
//duplicates aren't an issue here dnsSet := make(map[string]struct{}, len(userConf.Dns))
userConf.Dns = append(userConf.Dns, imageConf.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.DnsSearch == nil || len(userConf.DnsSearch) == 0 { if userConf.DnsSearch == nil || len(userConf.DnsSearch) == 0 {
userConf.DnsSearch = imageConf.DnsSearch userConf.DnsSearch = imageConf.DnsSearch