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
@@ -68,16 +68,14 @@ func (d *differ) IncrementalDiff(existing []*models.RecordConfig) (unchanged, cr
|
||||
desired := d.dc.Records
|
||||
|
||||
// sort existing and desired by name
|
||||
type key struct {
|
||||
name, rType string
|
||||
}
|
||||
existingByNameAndType := map[key][]*models.RecordConfig{}
|
||||
desiredByNameAndType := map[key][]*models.RecordConfig{}
|
||||
|
||||
existingByNameAndType := map[models.RecordKey][]*models.RecordConfig{}
|
||||
desiredByNameAndType := map[models.RecordKey][]*models.RecordConfig{}
|
||||
for _, e := range existing {
|
||||
if d.matchIgnored(e.GetLabel()) {
|
||||
log.Printf("Ignoring record %s %s due to IGNORE", e.GetLabel(), e.Type)
|
||||
} else {
|
||||
k := key{e.GetLabelFQDN(), e.Type}
|
||||
k := e.Key()
|
||||
existingByNameAndType[k] = append(existingByNameAndType[k], e)
|
||||
}
|
||||
}
|
||||
@@ -85,7 +83,7 @@ func (d *differ) IncrementalDiff(existing []*models.RecordConfig) (unchanged, cr
|
||||
if d.matchIgnored(dr.GetLabel()) {
|
||||
panic(fmt.Sprintf("Trying to update/add IGNOREd record: %s %s", dr.GetLabel(), dr.Type))
|
||||
} else {
|
||||
k := key{dr.GetLabelFQDN(), dr.Type}
|
||||
k := dr.Key()
|
||||
desiredByNameAndType[k] = append(desiredByNameAndType[k], dr)
|
||||
}
|
||||
}
|
||||
@@ -93,7 +91,7 @@ func (d *differ) IncrementalDiff(existing []*models.RecordConfig) (unchanged, cr
|
||||
if d.dc.KeepUnknown {
|
||||
for k := range existingByNameAndType {
|
||||
if _, ok := desiredByNameAndType[k]; !ok {
|
||||
log.Printf("Ignoring record set %s %s due to NO_PURGE", k.rType, k.name)
|
||||
log.Printf("Ignoring record set %s %s due to NO_PURGE", k.Type, k.Name)
|
||||
delete(existingByNameAndType, k)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user