mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
POWERDNS: Adopt diff2 in compatibility mode (#1899)
This commit is contained in:
@@ -228,7 +228,7 @@ func toRc(dc *models.DomainConfig, r *domainRecord) *models.RecordConfig {
|
|||||||
|
|
||||||
switch rtype := r.Type; rtype { // #rtype_variations
|
switch rtype := r.Type; rtype { // #rtype_variations
|
||||||
case "TXT":
|
case "TXT":
|
||||||
rc.SetTargetTXTString(r.Value)
|
rc.SetTargetTXT(r.Value)
|
||||||
case "SRV":
|
case "SRV":
|
||||||
spl := strings.Split(r.Value, " ")
|
spl := strings.Split(r.Value, " ")
|
||||||
prio, _ := strconv.ParseUint(spl[0], 10, 16)
|
prio, _ := strconv.ParseUint(spl[0], 10, 16)
|
||||||
|
@@ -62,73 +62,71 @@ func (dsp *powerdnsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*m
|
|||||||
}
|
}
|
||||||
models.PostProcessRecords(curRecords)
|
models.PostProcessRecords(curRecords)
|
||||||
|
|
||||||
var corrections []*models.Correction
|
// create record diff by group
|
||||||
if !diff2.EnableDiff2 || true { // Remove "|| true" when diff2 version arrives
|
var keysToUpdate map[models.RecordKey][]string
|
||||||
|
if !diff2.EnableDiff2 {
|
||||||
|
keysToUpdate, err = (diff.New(dc)).ChangedGroups(curRecords)
|
||||||
|
} else {
|
||||||
|
keysToUpdate, err = (diff.NewCompat(dc)).ChangedGroups(curRecords)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
desiredRecords := dc.Records.GroupedByKey()
|
||||||
|
|
||||||
// create record diff by group
|
var cuCorrections []*models.Correction
|
||||||
keysToUpdate, err := (diff.New(dc)).ChangedGroups(curRecords)
|
var dCorrections []*models.Correction
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
desiredRecords := dc.Records.GroupedByKey()
|
|
||||||
|
|
||||||
var cuCorrections []*models.Correction
|
// add create/update and delete corrections separately
|
||||||
var dCorrections []*models.Correction
|
for label, msgs := range keysToUpdate {
|
||||||
|
labelName := label.NameFQDN + "."
|
||||||
|
labelType := label.Type
|
||||||
|
msgJoined := strings.Join(msgs, "\n ")
|
||||||
|
|
||||||
// add create/update and delete corrections separately
|
if _, ok := desiredRecords[label]; !ok {
|
||||||
for label, msgs := range keysToUpdate {
|
// no record found so delete it
|
||||||
labelName := label.NameFQDN + "."
|
dCorrections = append(dCorrections, &models.Correction{
|
||||||
labelType := label.Type
|
Msg: msgJoined,
|
||||||
msgJoined := strings.Join(msgs, "\n ")
|
F: func() error {
|
||||||
|
return dsp.client.Zones().RemoveRecordSetFromZone(context.Background(), dsp.ServerName, dc.Name, labelName, labelType)
|
||||||
if _, ok := desiredRecords[label]; !ok {
|
},
|
||||||
// no record found so delete it
|
})
|
||||||
dCorrections = append(dCorrections, &models.Correction{
|
} else {
|
||||||
Msg: msgJoined,
|
// record found so create or update it
|
||||||
F: func() error {
|
ttl := desiredRecords[label][0].TTL
|
||||||
return dsp.client.Zones().RemoveRecordSetFromZone(context.Background(), dsp.ServerName, dc.Name, labelName, labelType)
|
var records []zones.Record
|
||||||
},
|
for _, recordContent := range desiredRecords[label] {
|
||||||
})
|
records = append(records, zones.Record{
|
||||||
} else {
|
Content: recordContent.GetTargetCombined(),
|
||||||
// record found so create or update it
|
|
||||||
ttl := desiredRecords[label][0].TTL
|
|
||||||
var records []zones.Record
|
|
||||||
for _, recordContent := range desiredRecords[label] {
|
|
||||||
records = append(records, zones.Record{
|
|
||||||
Content: recordContent.GetTargetCombined(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
cuCorrections = append(cuCorrections, &models.Correction{
|
|
||||||
Msg: msgJoined,
|
|
||||||
F: func() error {
|
|
||||||
return dsp.client.Zones().AddRecordSetToZone(context.Background(), dsp.ServerName, dc.Name, zones.ResourceRecordSet{
|
|
||||||
Name: labelName,
|
|
||||||
Type: labelType,
|
|
||||||
TTL: int(ttl),
|
|
||||||
Records: records,
|
|
||||||
ChangeType: zones.ChangeTypeReplace,
|
|
||||||
})
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
cuCorrections = append(cuCorrections, &models.Correction{
|
||||||
|
Msg: msgJoined,
|
||||||
|
F: func() error {
|
||||||
|
return dsp.client.Zones().AddRecordSetToZone(context.Background(), dsp.ServerName, dc.Name, zones.ResourceRecordSet{
|
||||||
|
Name: labelName,
|
||||||
|
Type: labelType,
|
||||||
|
TTL: int(ttl),
|
||||||
|
Records: records,
|
||||||
|
ChangeType: zones.ChangeTypeReplace,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// append corrections in the right order
|
|
||||||
// delete corrections must be run first to avoid correlations with existing RR
|
|
||||||
corrections = append(corrections, dCorrections...)
|
|
||||||
corrections = append(corrections, cuCorrections...)
|
|
||||||
|
|
||||||
// DNSSec corrections
|
|
||||||
dnssecCorrections, err := dsp.getDNSSECCorrections(dc)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
corrections = append(corrections, dnssecCorrections...)
|
|
||||||
|
|
||||||
return corrections, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert Future diff2 version here.
|
// append corrections in the right order
|
||||||
|
// delete corrections must be run first to avoid correlations with existing RR
|
||||||
|
var corrections []*models.Correction
|
||||||
|
corrections = append(corrections, dCorrections...)
|
||||||
|
corrections = append(corrections, cuCorrections...)
|
||||||
|
|
||||||
|
// DNSSec corrections
|
||||||
|
dnssecCorrections, err := dsp.getDNSSECCorrections(dc)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
corrections = append(corrections, dnssecCorrections...)
|
||||||
|
|
||||||
return corrections, nil
|
return corrections, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user