From 3e3d655e772a4ff8c591a85a6633a75e667b2427 Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Sun, 26 Feb 2023 13:28:39 -0500 Subject: [PATCH] RWTH: Adopt diff2 in compatibility mode (#1900) --- providers/rwth/dns.go | 83 ++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/providers/rwth/dns.go b/providers/rwth/dns.go index 8112ef9bb..c58159899 100644 --- a/providers/rwth/dns.go +++ b/providers/rwth/dns.go @@ -53,49 +53,52 @@ func (api *rwthProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*model txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records var corrections []*models.Correction - if !diff2.EnableDiff2 || true { // Remove "|| true" when diff2 version arrives - + var create, del, modify diff.Changeset + if !diff2.EnableDiff2 { differ := diff.New(dc) - _, create, del, modify, err := differ.IncrementalDiff(existingRecords) - if err != nil { - return nil, err - } - - for _, d := range create { - des := d.Desired - corrections = append(corrections, &models.Correction{ - Msg: d.String(), - F: func() error { return api.createRecord(dc.Name, des) }, - }) - } - for _, d := range del { - existingRecord := d.Existing.Original.(RecordReply) - corrections = append(corrections, &models.Correction{ - Msg: d.String(), - F: func() error { return api.destroyRecord(existingRecord) }, - }) - } - for _, d := range modify { - rec := d.Desired - existingID := d.Existing.Original.(RecordReply).ID - corrections = append(corrections, &models.Correction{ - Msg: d.String(), - F: func() error { return api.updateRecord(existingID, *rec) }, - }) - } - - // And deploy if any corrections were applied - if len(corrections) > 0 { - corrections = append(corrections, &models.Correction{ - Msg: fmt.Sprintf("Deploy zone %s", domain), - F: func() error { return api.deployZone(domain) }, - }) - } - - return corrections, nil + _, create, del, modify, err = differ.IncrementalDiff(existingRecords) + } else { + differ := diff.NewCompat(dc) + _, create, del, modify, err = differ.IncrementalDiff(existingRecords) + } + if err != nil { + return nil, err } - // Insert Future diff2 version here. + if err != nil { + return nil, err + } + + for _, d := range create { + des := d.Desired + corrections = append(corrections, &models.Correction{ + Msg: d.String(), + F: func() error { return api.createRecord(dc.Name, des) }, + }) + } + for _, d := range del { + existingRecord := d.Existing.Original.(RecordReply) + corrections = append(corrections, &models.Correction{ + Msg: d.String(), + F: func() error { return api.destroyRecord(existingRecord) }, + }) + } + for _, d := range modify { + rec := d.Desired + existingID := d.Existing.Original.(RecordReply).ID + corrections = append(corrections, &models.Correction{ + Msg: d.String(), + F: func() error { return api.updateRecord(existingID, *rec) }, + }) + } + + // And deploy if any corrections were applied + if len(corrections) > 0 { + corrections = append(corrections, &models.Correction{ + Msg: fmt.Sprintf("Deploy zone %s", domain), + F: func() error { return api.deployZone(domain) }, + }) + } return corrections, nil }