mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
no purge (#111)
This commit is contained in:
@ -55,9 +55,6 @@ func (c *adProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Co
|
|||||||
// Generate changes.
|
// Generate changes.
|
||||||
corrections := []*models.Correction{}
|
corrections := []*models.Correction{}
|
||||||
for _, del := range dels {
|
for _, del := range dels {
|
||||||
if dc.KeepUnknown {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
corrections = append(corrections, c.deleteRec(dc.Name, del.Existing))
|
corrections = append(corrections, c.deleteRec(dc.Name, del.Existing))
|
||||||
}
|
}
|
||||||
for _, cre := range creates {
|
for _, cre := range creates {
|
||||||
|
@ -103,9 +103,6 @@ func (c *CloudflareApi) GetDomainCorrections(dc *models.DomainConfig) ([]*models
|
|||||||
corrections := []*models.Correction{}
|
corrections := []*models.Correction{}
|
||||||
|
|
||||||
for _, d := range del {
|
for _, d := range del {
|
||||||
if dc.KeepUnknown {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
corrections = append(corrections, c.deleteRec(d.Existing.Original.(*cfRecord), id))
|
corrections = append(corrections, c.deleteRec(d.Existing.Original.(*cfRecord), id))
|
||||||
}
|
}
|
||||||
for _, d := range create {
|
for _, d := range create {
|
||||||
|
@ -2,6 +2,7 @@ package diff
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/StackExchange/dnscontrol/models"
|
"github.com/StackExchange/dnscontrol/models"
|
||||||
@ -66,6 +67,15 @@ func (d *differ) IncrementalDiff(existing []*models.RecordConfig) (unchanged, cr
|
|||||||
k := key{d.NameFQDN, d.Type}
|
k := key{d.NameFQDN, d.Type}
|
||||||
desiredByNameAndType[k] = append(desiredByNameAndType[k], d)
|
desiredByNameAndType[k] = append(desiredByNameAndType[k], d)
|
||||||
}
|
}
|
||||||
|
//if NO_PURGE is set, just remove anything that is only in existing.
|
||||||
|
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)
|
||||||
|
delete(existingByNameAndType, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// Look through existing records. This will give us changes and deletions and some additions.
|
// Look through existing records. This will give us changes and deletions and some additions.
|
||||||
// Each iteration is only for a single type/name record set
|
// Each iteration is only for a single type/name record set
|
||||||
for key, existingRecords := range existingByNameAndType {
|
for key, existingRecords := range existingByNameAndType {
|
||||||
|
@ -128,9 +128,14 @@ func TestMetaChange(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkLengths(t *testing.T, existing, desired []*models.RecordConfig, unCount, createCount, delCount, modCount int, valFuncs ...func(*models.RecordConfig) map[string]string) (un, cre, del, mod Changeset) {
|
func checkLengths(t *testing.T, existing, desired []*models.RecordConfig, unCount, createCount, delCount, modCount int, valFuncs ...func(*models.RecordConfig) map[string]string) (un, cre, del, mod Changeset) {
|
||||||
|
return checkLengthsFull(t, existing, desired, unCount, createCount, delCount, modCount, false, valFuncs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkLengthsFull(t *testing.T, existing, desired []*models.RecordConfig, unCount, createCount, delCount, modCount int, keepUnknown bool, valFuncs ...func(*models.RecordConfig) map[string]string) (un, cre, del, mod Changeset) {
|
||||||
dc := &models.DomainConfig{
|
dc := &models.DomainConfig{
|
||||||
Name: "example.com",
|
Name: "example.com",
|
||||||
Records: desired,
|
Records: desired,
|
||||||
|
KeepUnknown: keepUnknown,
|
||||||
}
|
}
|
||||||
d := New(dc, valFuncs...)
|
d := New(dc, valFuncs...)
|
||||||
un, cre, del, mod = d.IncrementalDiff(existing)
|
un, cre, del, mod = d.IncrementalDiff(existing)
|
||||||
@ -151,3 +156,15 @@ func checkLengths(t *testing.T, existing, desired []*models.RecordConfig, unCoun
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNoPurge(t *testing.T) {
|
||||||
|
existing := []*models.RecordConfig{
|
||||||
|
myRecord("www MX 1 1.1.1.1"),
|
||||||
|
myRecord("www MX 1 2.2.2.2"),
|
||||||
|
myRecord("www2 MX 1 1.1.1.1"),
|
||||||
|
}
|
||||||
|
desired := []*models.RecordConfig{
|
||||||
|
myRecord("www MX 1 1.1.1.1"),
|
||||||
|
}
|
||||||
|
checkLengthsFull(t, existing, desired, 1, 0, 1, 0, true)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user