Remove duplication of Dns in config merging.
| ... | ... |
@@ -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 |