Browse code

Merge pull request #4775 from LK4D4/remove_duplicate_dns_#4714

Remove duplication of Dns in config merging.

Michael Crosby authored on 2014/03/22 09:08:06
Showing 2 changed files
... ...
@@ -247,7 +247,7 @@ func TestMerge(t *testing.T) {
247 247
 	volumesUser := make(map[string]struct{})
248 248
 	volumesUser["/test3"] = struct{}{}
249 249
 	configUser := &Config{
250
-		Dns:       []string{"3.3.3.3"},
250
+		Dns:       []string{"2.2.2.2", "3.3.3.3"},
251 251
 		PortSpecs: []string{"3333:2222", "3333:3333"},
252 252
 		Env:       []string{"VAR2=3", "VAR3=3"},
253 253
 		Volumes:   volumesUser,
... ...
@@ -97,8 +97,15 @@ func Merge(userConf, imageConf *Config) error {
97 97
 	if userConf.Dns == nil || len(userConf.Dns) == 0 {
98 98
 		userConf.Dns = imageConf.Dns
99 99
 	} else {
100
-		//duplicates aren't an issue here
101
-		userConf.Dns = append(userConf.Dns, imageConf.Dns...)
100
+		dnsSet := make(map[string]struct{}, len(userConf.Dns))
101
+		for _, dns := range userConf.Dns {
102
+			dnsSet[dns] = struct{}{}
103
+		}
104
+		for _, dns := range imageConf.Dns {
105
+			if _, exists := dnsSet[dns]; !exists {
106
+				userConf.Dns = append(userConf.Dns, dns)
107
+			}
108
+		}
102 109
 	}
103 110
 	if userConf.DnsSearch == nil || len(userConf.DnsSearch) == 0 {
104 111
 		userConf.DnsSearch = imageConf.DnsSearch