diff --git a/pkg/diff/diff.go b/pkg/diff/diff.go index 1e24402fa7..08806d8e3f 100644 --- a/pkg/diff/diff.go +++ b/pkg/diff/diff.go @@ -18,7 +18,7 @@ type Changeset []Correlation // Differ is an interface for computing the difference between two zones. type Differ interface { // IncrementalDiff performs a diff on a record-by-record basis, and returns a sets for which records need to be created, deleted, or modified. - IncrementalDiff(existing []*models.RecordConfig) (unchanged, create, toDelete, modify Changeset, err error) + IncrementalDiff(existing []*models.RecordConfig) (reportMsgs []string, create, toDelete, modify Changeset, err error) // ChangedGroups performs a diff more appropriate for providers with a "RecordSet" model, where all records with the same name and type are grouped. // Individual record changes are often not useful in such scenarios. Instead we return a map of record keys to a list of change descriptions within that group. ChangedGroups(existing []*models.RecordConfig) (map[models.RecordKey][]string, error) diff --git a/pkg/diff/diff2compat.go b/pkg/diff/diff2compat.go index 6a75edada6..2a926832fe 100644 --- a/pkg/diff/diff2compat.go +++ b/pkg/diff/diff2compat.go @@ -45,7 +45,7 @@ type differCompat struct { // - The NewCompat() feature `extraValues` is not supported. That // parameter must be set to nil. If you use that feature, consider // one of the pkg/diff2/By*() functions. -func (d *differCompat) IncrementalDiff(existing []*models.RecordConfig) (unchanged, toCreate, toDelete, toModify Changeset, err error) { +func (d *differCompat) IncrementalDiff(existing []*models.RecordConfig) (reportMsgs []string, toCreate, toDelete, toModify Changeset, err error) { instructions, err := diff2.ByRecord(existing, d.dc, nil) if err != nil { return nil, nil, nil, nil, err @@ -55,15 +55,7 @@ func (d *differCompat) IncrementalDiff(existing []*models.RecordConfig) (unchang cor := Correlation{} switch inst.Type { case diff2.REPORT: - // Sadly the NewCompat function doesn't have an equivalent. We - // just output the messages now. - fmt.Print("INFO: ") - fmt.Println(inst.MsgsJoined) - - // TODO(tlim): When diff1 is deleted, IncremtntalDiff should add a - // parameter to list the REPORT messages. It can also eliminate the - // first parameter (existing) since nobody uses that in the diff2 - // world. + reportMsgs = append(reportMsgs, inst.Msgs...) case diff2.CREATE: cor.Desired = inst.New[0] toCreate = append(toCreate, cor) @@ -82,6 +74,13 @@ func (d *differCompat) IncrementalDiff(existing []*models.RecordConfig) (unchang return } +func GenerateMessageCorrections(msgs []string) (corrections []*models.Correction) { + for _, msg := range msgs { + corrections = append(corrections, &models.Correction{Msg: msg}) + } + return +} + // ChangedGroups provides the same results as IncrementalDiff but grouped by key. func (d *differCompat) ChangedGroups(existing []*models.RecordConfig) (map[models.RecordKey][]string, error) { changedKeys := map[models.RecordKey][]string{} diff --git a/providers/cloudns/cloudnsProvider.go b/providers/cloudns/cloudnsProvider.go index 05471312a7..ab79ef1cb4 100644 --- a/providers/cloudns/cloudnsProvider.go +++ b/providers/cloudns/cloudnsProvider.go @@ -128,11 +128,12 @@ func (c *cloudnsProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, exi record.TTL = fixTTL(record.TTL) } - var corrections []*models.Correction - _, create, del, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) + toReport, create, del, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) // Deletes first so changing type works etc. for _, m := range del { diff --git a/providers/cscglobal/dns.go b/providers/cscglobal/dns.go index ba41ff72a5..4cf3cb5175 100644 --- a/providers/cscglobal/dns.go +++ b/providers/cscglobal/dns.go @@ -78,11 +78,12 @@ func (client *providerClient) GetNameservers(domain string) ([]*models.Nameserve func (client *providerClient) GetZoneRecordsCorrections(dc *models.DomainConfig, foundRecords models.Records) ([]*models.Correction, error) { //txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records - var corrections []*models.Correction - _, creates, dels, modifications, err := diff.NewCompat(dc).IncrementalDiff(foundRecords) + toReport, creates, dels, modifications, err := diff.NewCompat(dc).IncrementalDiff(foundRecords) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) // CSCGlobal has a unique API. A list of edits is sent in one API // call. Edits aren't permitted if an existing edit is being diff --git a/providers/digitalocean/digitaloceanProvider.go b/providers/digitalocean/digitaloceanProvider.go index 9ba96a3a3b..62ec0d7dd9 100644 --- a/providers/digitalocean/digitaloceanProvider.go +++ b/providers/digitalocean/digitaloceanProvider.go @@ -172,11 +172,12 @@ func (api *digitaloceanProvider) GetZoneRecordsCorrections(dc *models.DomainConf ctx := context.Background() - var corrections []*models.Correction - _, toCreate, toDelete, toModify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) + toReport, toCreate, toDelete, toModify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) // Deletes first so changing type works etc. for _, m := range toDelete { diff --git a/providers/dnsimple/dnsimpleProvider.go b/providers/dnsimple/dnsimpleProvider.go index 3789792afd..e1fc4277eb 100644 --- a/providers/dnsimple/dnsimpleProvider.go +++ b/providers/dnsimple/dnsimpleProvider.go @@ -139,20 +139,21 @@ func (c *dnsimpleProvider) GetZoneRecords(domain string, meta map[string]string) } func (c *dnsimpleProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, actual models.Records) ([]*models.Correction, error) { - var corrections []*models.Correction - removeOtherApexNS(dc) dnssecFixes, err := c.getDNSSECCorrections(dc) if err != nil { return nil, err } - corrections = append(corrections, dnssecFixes...) - _, create, del, modify, err := diff.NewCompat(dc).IncrementalDiff(actual) + toReport, create, del, modify, err := diff.NewCompat(dc).IncrementalDiff(actual) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) + // Next dnsSec fixes + corrections = append(corrections, dnssecFixes...) for _, del := range del { rec := del.Existing.Original.(dnsimpleapi.ZoneRecord) diff --git a/providers/dnsmadeeasy/dnsMadeEasyProvider.go b/providers/dnsmadeeasy/dnsMadeEasyProvider.go index 72afc913b8..3e6f1eb31e 100644 --- a/providers/dnsmadeeasy/dnsMadeEasyProvider.go +++ b/providers/dnsmadeeasy/dnsMadeEasyProvider.go @@ -117,11 +117,12 @@ func (api *dnsMadeEasyProvider) GetZoneRecordsCorrections(dc *models.DomainConfi } } - var corrections []*models.Correction - _, create, del, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) + toReport, create, del, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) var deleteRecordIds []int deleteDescription := []string{"Batch deletion of records:"} diff --git a/providers/domainnameshop/dns.go b/providers/domainnameshop/dns.go index 436356456a..e7619c11d8 100644 --- a/providers/domainnameshop/dns.go +++ b/providers/domainnameshop/dns.go @@ -39,11 +39,12 @@ func (api *domainNameShopProvider) GetZoneRecordsCorrections(dc *models.DomainCo record.TTL = fixTTL(record.TTL) } - var corrections []*models.Correction - _, create, delete, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) + toReport, create, delete, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) // Delete record for _, r := range delete { diff --git a/providers/exoscale/exoscaleProvider.go b/providers/exoscale/exoscaleProvider.go index b689f5a148..491e3e7be3 100644 --- a/providers/exoscale/exoscaleProvider.go +++ b/providers/exoscale/exoscaleProvider.go @@ -190,11 +190,12 @@ func (c *exoscaleProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, ex } domainID := *domain.ID - var corrections []*models.Correction - _, create, toDelete, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) + toReport, create, toDelete, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) for _, del := range toDelete { record := del.Existing.Original.(*egoscale.DNSDomainRecord) diff --git a/providers/gcloud/gcloudProvider.go b/providers/gcloud/gcloudProvider.go index c20cf4a84e..8fd387ee20 100644 --- a/providers/gcloud/gcloudProvider.go +++ b/providers/gcloud/gcloudProvider.go @@ -259,7 +259,6 @@ type correctionValues struct { // GetZoneRecordsCorrections returns a list of corrections that will turn existing records into dc.Records. func (g *gcloudProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, existingRecords models.Records) ([]*models.Correction, error) { - txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records oldRRs, ok := g.oldRRsMap[dc.Name] @@ -272,16 +271,20 @@ func (g *gcloudProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, exis } // first collect keys that have changed - _, create, delete, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) + toReport, create, toDelete, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) if err != nil { return nil, fmt.Errorf("incdiff error: %w", err) } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) + + // Now generate all other corrections changedKeys := map[key]string{} for _, c := range create { changedKeys[keyForRec(c.Desired)] = fmt.Sprintln(c) } - for _, d := range delete { + for _, d := range toDelete { changedKeys[keyForRec(d.Existing)] = fmt.Sprintln(d) } for _, m := range modify { @@ -366,7 +369,6 @@ func (g *gcloudProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, exis } // create a Correction for each gdns.Change // that needs to be executed - corrections := []*models.Correction{} makeCorrection := func(chg *gdns.Change, msgs string) { runChange := func() error { retry: diff --git a/providers/hetzner/hetznerProvider.go b/providers/hetzner/hetznerProvider.go index d8566ffb14..fbb411252c 100644 --- a/providers/hetzner/hetznerProvider.go +++ b/providers/hetzner/hetznerProvider.go @@ -70,15 +70,16 @@ func (api *hetznerProvider) EnsureZoneExists(domain string) error { // GetZoneRecordsCorrections returns a list of corrections that will turn existing records into dc.Records. func (api *hetznerProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, existingRecords models.Records) ([]*models.Correction, error) { - var corrections []*models.Correction domain := dc.Name txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records - _, create, del, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) + toReport, create, del, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) z, err := api.getZone(domain) if err != nil { diff --git a/providers/hexonet/records.go b/providers/hexonet/records.go index 912feee5b2..3cb1846db7 100644 --- a/providers/hexonet/records.go +++ b/providers/hexonet/records.go @@ -58,14 +58,14 @@ func (n *HXClient) GetZoneRecords(domain string, meta map[string]string) (models // GetZoneRecordsCorrections returns a list of corrections that will turn existing records into dc.Records. func (n *HXClient) GetZoneRecordsCorrections(dc *models.DomainConfig, actual models.Records) ([]*models.Correction, error) { - var corrections []*models.Correction - txtutil.SplitSingleLongTxt(dc.Records) - _, create, del, mod, err := diff.NewCompat(dc).IncrementalDiff(actual) + toReport, create, del, mod, err := diff.NewCompat(dc).IncrementalDiff(actual) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) buf := &bytes.Buffer{} // Print a list of changes. Generate an actual change that is the zone diff --git a/providers/hostingde/hostingdeProvider.go b/providers/hostingde/hostingdeProvider.go index e15eeae80e..9410ee4b41 100644 --- a/providers/hostingde/hostingdeProvider.go +++ b/providers/hostingde/hostingdeProvider.go @@ -137,10 +137,12 @@ func (hp *hostingdeProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, return nil, err } - _, create, del, mod, err := diff.NewCompat(dc).IncrementalDiff(records) + toReport, create, del, mod, err := diff.NewCompat(dc).IncrementalDiff(records) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) // NOPURGE if dc.KeepUnknown { @@ -261,31 +263,30 @@ func (hp *hostingdeProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, return nil, nil } - corrections := []*models.Correction{ - { - Msg: fmt.Sprintf("\n%s", strings.Join(msg, "\n")), - F: func() error { - for i := 0; i < 10; i++ { - err := hp.updateZone(&zone.ZoneConfig, DNSSecOptions, create, del, mod) - if err == nil { - return nil - } - // Code:10205 indicates the zone is currently blocked due to a running zone update. - if !strings.Contains(err.Error(), "Code:10205") { - return err - } - - // Exponential back-off retry. - // Base of 1.8 seemed like a good trade-off, retrying for approximately 45 seconds. - time.Sleep(time.Duration(math.Pow(1.8, float64(i))) * 100 * time.Millisecond) + corrections = append(corrections, &models.Correction{ + Msg: fmt.Sprintf("\n%s", strings.Join(msg, "\n")), + F: func() error { + for i := 0; i < 10; i++ { + err := hp.updateZone(&zone.ZoneConfig, DNSSecOptions, create, del, mod) + if err == nil { + return nil } - return fmt.Errorf("retry exhaustion: zone blocked for 10 attempts") - }, + // Code:10205 indicates the zone is currently blocked due to a running zone update. + if !strings.Contains(err.Error(), "Code:10205") { + return err + } + + // Exponential back-off retry. + // Base of 1.8 seemed like a good trade-off, retrying for approximately 45 seconds. + time.Sleep(time.Duration(math.Pow(1.8, float64(i))) * 100 * time.Millisecond) + } + return fmt.Errorf("retry exhaustion: zone blocked for 10 attempts") }, - } + }, + ) if removeDNSSecEntries != nil { - correction := models.Correction{ + correction := &models.Correction{ Msg: "Removing AutoDNSSEC Keys from Domain", F: func() error { err := hp.dnsSecKeyModify(dc.Name, nil, removeDNSSecEntries) @@ -295,7 +296,7 @@ func (hp *hostingdeProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, return nil }, } - corrections = append(corrections, &correction) + corrections = append(corrections, correction) } return corrections, nil diff --git a/providers/inwx/inwxProvider.go b/providers/inwx/inwxProvider.go index cb78c74999..189a1ce406 100644 --- a/providers/inwx/inwxProvider.go +++ b/providers/inwx/inwxProvider.go @@ -235,11 +235,12 @@ func (api *inwxAPI) GetZoneRecordsCorrections(dc *models.DomainConfig, foundReco return nil, err } - var corrections []*models.Correction - _, create, del, mod, err := diff.NewCompat(dc).IncrementalDiff(foundRecords) + toReport, create, del, mod, err := diff.NewCompat(dc).IncrementalDiff(foundRecords) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) for _, d := range create { des := d.Desired diff --git a/providers/linode/linodeProvider.go b/providers/linode/linodeProvider.go index 107569238b..de3b4cd523 100644 --- a/providers/linode/linodeProvider.go +++ b/providers/linode/linodeProvider.go @@ -126,7 +126,6 @@ func (api *linodeProvider) GetZoneRecords(domain string, meta map[string]string) // GetZoneRecordsCorrections returns a list of corrections that will turn existing records into dc.Records. func (api *linodeProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, existingRecords models.Records) ([]*models.Correction, error) { - var corrections []*models.Correction // Linode doesn't allow selecting an arbitrary TTL, only a set of predefined values // We need to make sure we don't change it every time if it is as close as it's going to get // The documentation says that it will always round up to the next highest value: 300 -> 300, 301 -> 3600. @@ -145,10 +144,12 @@ func (api *linodeProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, ex return nil, fmt.Errorf("'%s' not a zone in Linode account", dc.Name) } - _, create, del, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) + toReport, create, del, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) // Deletes first so changing type works etc. for _, m := range del { diff --git a/providers/loopia/loopiaProvider.go b/providers/loopia/loopiaProvider.go index 1275f32247..cfa68c60e6 100644 --- a/providers/loopia/loopiaProvider.go +++ b/providers/loopia/loopiaProvider.go @@ -266,7 +266,6 @@ func gatherAffectedLabels(groups map[models.RecordKey][]string) (labels map[stri // GetZoneRecordsCorrections returns a list of corrections that will turn existing records into dc.Records. func (c *APIClient) GetZoneRecordsCorrections(dc *models.DomainConfig, existingRecords models.Records) ([]*models.Correction, error) { - var corrections []*models.Correction if c.Debug { debugRecords("GenerateZoneRecordsCorrections input:\n", existingRecords) @@ -278,7 +277,7 @@ func (c *APIClient) GetZoneRecordsCorrections(dc *models.DomainConfig, existingR var keysToUpdate map[models.RecordKey][]string differ := diff.NewCompat(dc) - _, create, del, modify, err := differ.IncrementalDiff(existingRecords) + toReport, create, del, modify, err := differ.IncrementalDiff(existingRecords) if err != nil { return nil, err } @@ -287,6 +286,9 @@ func (c *APIClient) GetZoneRecordsCorrections(dc *models.DomainConfig, existingR return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) + for _, d := range create { // fmt.Printf("a creation: subdomain: %+v, existingfqdn: %+v \n", d.Desired.Name, d.Desired.NameFQDN) des := d.Desired diff --git a/providers/namecheap/namecheapProvider.go b/providers/namecheap/namecheapProvider.go index d7f23ae9c9..ddbc2a0273 100644 --- a/providers/namecheap/namecheapProvider.go +++ b/providers/namecheap/namecheapProvider.go @@ -244,10 +244,12 @@ func (n *namecheapProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, a return true }) - _, create, delete, modify, err := diff.NewCompat(dc).IncrementalDiff(actual) + toReport, create, delete, modify, err := diff.NewCompat(dc).IncrementalDiff(actual) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) // because namecheap doesn't have selective create, delete, modify, // we bundle them all up to send at once. We *do* want to see the @@ -264,11 +266,9 @@ func (n *namecheapProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, a desc = append(desc, "\n"+i.String()) } - msg := fmt.Sprintf("GENERATE_ZONE: %s (%d records)%s", dc.Name, len(dc.Records), desc) - var corrections []*models.Correction - // only create corrections if there are changes if len(desc) > 0 { + msg := fmt.Sprintf("GENERATE_ZONE: %s (%d records)%s", dc.Name, len(dc.Records), desc) corrections = append(corrections, &models.Correction{ Msg: msg, diff --git a/providers/namedotcom/records.go b/providers/namedotcom/records.go index 398915c293..b9edb4ef8e 100644 --- a/providers/namedotcom/records.go +++ b/providers/namedotcom/records.go @@ -28,8 +28,6 @@ func (n *namedotcomProvider) GetZoneRecords(domain string, meta map[string]strin // GetZoneRecordsCorrections returns a list of corrections that will turn existing records into dc.Records. func (n *namedotcomProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, actual models.Records) ([]*models.Correction, error) { - var corrections []*models.Correction - checkNSModifications(dc) for _, rec := range dc.Records { @@ -38,10 +36,12 @@ func (n *namedotcomProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, } } - _, create, del, mod, err := diff.NewCompat(dc).IncrementalDiff(actual) + toReport, create, del, mod, err := diff.NewCompat(dc).IncrementalDiff(actual) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) for _, d := range del { rec := d.Existing.Original.(*namecom.Record) diff --git a/providers/netcup/netcupProvider.go b/providers/netcup/netcupProvider.go index 9d9fb31666..e55901772d 100644 --- a/providers/netcup/netcupProvider.go +++ b/providers/netcup/netcupProvider.go @@ -69,7 +69,6 @@ func (api *netcupProvider) GetNameservers(domain string) ([]*models.Nameserver, // GetZoneRecordsCorrections returns a list of corrections that will turn existing records into dc.Records. func (api *netcupProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, existingRecords models.Records) ([]*models.Correction, error) { - var corrections []*models.Correction domain := dc.Name // no need for txtutil.SplitSingleLongTxt in function GetDomainCorrections @@ -89,10 +88,12 @@ func (api *netcupProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, ex } dc.Records = newRecords - _, create, del, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) + toReport, create, del, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) // Deletes first so changing type works etc. for _, m := range del { diff --git a/providers/netlify/netlifyProvider.go b/providers/netlify/netlifyProvider.go index ae4a3f0688..2bdb1c1e8e 100644 --- a/providers/netlify/netlifyProvider.go +++ b/providers/netlify/netlifyProvider.go @@ -140,12 +140,12 @@ func (n *netlifyProvider) GetZoneRecords(domain string, meta map[string]string) // GetZoneRecordsCorrections returns a list of corrections that will turn existing records into dc.Records. func (n *netlifyProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, records models.Records) ([]*models.Correction, error) { - var corrections []*models.Correction - - _, create, del, modify, err := diff.NewCompat(dc).IncrementalDiff(records) + toReport, create, del, modify, err := diff.NewCompat(dc).IncrementalDiff(records) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) zone, err := n.getZone(dc.Name) if err != nil { diff --git a/providers/oracle/oracleProvider.go b/providers/oracle/oracleProvider.go index a9b0c078d5..892e6cee8a 100644 --- a/providers/oracle/oracleProvider.go +++ b/providers/oracle/oracleProvider.go @@ -224,10 +224,12 @@ func (o *oracleProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, exis } } - _, create, dels, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) + toReport, create, dels, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) /* Oracle's API doesn't have a way to update an existing record. @@ -266,15 +268,17 @@ func (o *oracleProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, exis desc = desc[:len(desc)-1] } + // There were corrections. Send them as one big batch: if len(createRecords) > 0 || len(deleteRecords) > 0 { - return []*models.Correction{{ + corrections = append(corrections, &models.Correction{ Msg: desc, F: func() error { return o.patch(createRecords, deleteRecords, dc.Name) }, - }}, nil + }) } - return []*models.Correction{}, nil + + return corrections, nil } func (o *oracleProvider) patch(createRecords, deleteRecords models.Records, domain string) error { diff --git a/providers/packetframe/packetframeProvider.go b/providers/packetframe/packetframeProvider.go index 7ab111db39..82e5565c25 100644 --- a/providers/packetframe/packetframeProvider.go +++ b/providers/packetframe/packetframeProvider.go @@ -101,17 +101,17 @@ func (api *packetframeProvider) GetZoneRecords(domain string, meta map[string]st // GetZoneRecordsCorrections returns a list of corrections that will turn existing records into dc.Records. func (api *packetframeProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, existingRecords models.Records) ([]*models.Correction, error) { - var corrections []*models.Correction - zone, err := api.getZone(dc.Name) if err != nil { return nil, fmt.Errorf("no such zone %q in Packetframe account", dc.Name) } - _, create, dels, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) + toReport, create, dels, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) for _, m := range create { req, err := toReq(zone.ID, dc, m.Desired) diff --git a/providers/rwth/dns.go b/providers/rwth/dns.go index 645be5e5a4..88b31e6e7e 100644 --- a/providers/rwth/dns.go +++ b/providers/rwth/dns.go @@ -34,11 +34,12 @@ func (api *rwthProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, exis txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records domain := dc.Name - var corrections []*models.Correction - _, create, del, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) + toReport, create, del, modify, err := diff.NewCompat(dc).IncrementalDiff(existingRecords) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) for _, d := range create { des := d.Desired diff --git a/providers/softlayer/softlayerProvider.go b/providers/softlayer/softlayerProvider.go index 326dc81b50..4238302b89 100644 --- a/providers/softlayer/softlayerProvider.go +++ b/providers/softlayer/softlayerProvider.go @@ -76,17 +76,17 @@ func (s *softlayerProvider) GetZoneRecords(domainName string, meta map[string]st // GetZoneRecordsCorrections returns a list of corrections that will turn existing records into dc.Records. func (s *softlayerProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, actual models.Records) ([]*models.Correction, error) { - var corrections []*models.Correction - domain, err := s.getDomain(&dc.Name) if err != nil { return nil, err } - _, create, deletes, modify, err := diff.NewCompat(dc).IncrementalDiff(actual) + toReport, create, deletes, modify, err := diff.NewCompat(dc).IncrementalDiff(actual) if err != nil { return nil, err } + // Start corrections with the reports + corrections := diff.GenerateMessageCorrections(toReport) for _, del := range deletes { existing := del.Existing.Original.(datatypes.Dns_Domain_ResourceRecord)