mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Correctly group R53_ALIAS records during IncrementalDiff. (#399)
Previously, unnecessary corrections were possible if both an R53_ALIAS pointing to an A record and to an AAAA record existed for the same label, and map iteration over existing and desired found them in different orders. (This is a common configuration for IPv6-enabled records.) This commit: * mirrors key logic in the R53 provider * centralizes logic around keys in the models package * adds tests
This commit is contained in:
committed by
Craig Peterson
parent
50c126c2d4
commit
61c92c9215
@@ -102,21 +102,6 @@ func (r *route53Provider) getZones() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// map key for grouping records
|
||||
type key struct {
|
||||
Name, Type string
|
||||
}
|
||||
|
||||
func getKey(r *models.RecordConfig) key {
|
||||
var recordType = r.Type
|
||||
|
||||
if r.R53Alias != nil {
|
||||
recordType = fmt.Sprintf("%s_%s", recordType, r.R53Alias["type"])
|
||||
}
|
||||
|
||||
return key{r.GetLabelFQDN(), recordType}
|
||||
}
|
||||
|
||||
type errNoExist struct {
|
||||
domain string
|
||||
}
|
||||
@@ -175,29 +160,18 @@ func (r *route53Provider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
|
||||
|
||||
// diff
|
||||
differ := diff.New(dc, getAliasMap)
|
||||
_, create, delete, modify := differ.IncrementalDiff(existingRecords)
|
||||
|
||||
namesToUpdate := map[key][]string{}
|
||||
for _, c := range create {
|
||||
namesToUpdate[getKey(c.Desired)] = append(namesToUpdate[getKey(c.Desired)], c.String())
|
||||
}
|
||||
for _, d := range delete {
|
||||
namesToUpdate[getKey(d.Existing)] = append(namesToUpdate[getKey(d.Existing)], d.String())
|
||||
}
|
||||
for _, m := range modify {
|
||||
namesToUpdate[getKey(m.Desired)] = append(namesToUpdate[getKey(m.Desired)], m.String())
|
||||
}
|
||||
namesToUpdate := differ.ChangedGroups(existingRecords)
|
||||
|
||||
if len(namesToUpdate) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
updates := map[key][]*models.RecordConfig{}
|
||||
updates := map[models.RecordKey][]*models.RecordConfig{}
|
||||
// for each name we need to update, collect relevant records from dc
|
||||
for k := range namesToUpdate {
|
||||
updates[k] = nil
|
||||
for _, rc := range dc.Records {
|
||||
if getKey(rc) == k {
|
||||
if rc.Key() == k {
|
||||
updates[k] = append(updates[k], rc)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user