Skip to content

Commit

Permalink
Merge pull request rancher#62 from janeczku/fix-duplicate-ip
Browse files Browse the repository at this point in the history
Fixes duplicate IP records issue for services without exposed ports
  • Loading branch information
janeczku authored Mar 1, 2017
2 parents 72feb46 + 211b5ca commit 4264044
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,33 +130,37 @@ func (m *MetadataClient) getContainersDnsRecords(dnsEntries map[string]utils.Dns

fqdn := utils.FqdnFromTemplate(config.NameTemplate, container.ServiceName, container.StackName,
m.EnvironmentName, config.RootDomainName)
records := []string{ip}
dnsEntry := utils.DnsRecord{fqdn, records, "A", config.TTL}

addToDnsEntries(dnsEntry, dnsEntries)
addToDnsEntries(fqdn, ip, dnsEntries)
ourFqdns[fqdn] = struct{}{}
}
}

if len(ourFqdns) > 0 {
fqdn := utils.StateFqdn(m.EnvironmentUUID, config.RootDomainName)
stateRec := utils.StateRecord(fqdn, config.TTL, ourFqdns)
addToDnsEntries(stateRec, dnsEntries)
stateFqdn := utils.StateFqdn(m.EnvironmentUUID, config.RootDomainName)
stateRec := utils.StateRecord(stateFqdn, config.TTL, ourFqdns)
dnsEntries[stateFqdn] = stateRec
}

return nil
}

func addToDnsEntries(dnsEntry utils.DnsRecord, dnsEntries map[string]utils.DnsRecord) {
func addToDnsEntries(fqdn, ip string, dnsEntries map[string]utils.DnsRecord) {
var records []string
if _, ok := dnsEntries[dnsEntry.Fqdn]; !ok {
records = dnsEntry.Records
if _, ok := dnsEntries[fqdn]; !ok {
records = []string{ip}
} else {
records = dnsEntries[dnsEntry.Fqdn].Records
records = append(records, dnsEntry.Records...)
records = dnsEntries[fqdn].Records
// skip if the records already have that IP
for _, val := range records {
if val == ip {
return
}
}
records = append(records, ip)
}
dnsEntry = utils.DnsRecord{dnsEntry.Fqdn, records, dnsEntry.Type, dnsEntry.TTL}
dnsEntries[dnsEntry.Fqdn] = dnsEntry

dnsEntries[fqdn] = utils.DnsRecord{fqdn, records, "A", config.TTL}
}

func containerStateOK(container metadata.Container) bool {
Expand Down

0 comments on commit 4264044

Please sign in to comment.