From b404f0275f09fccdad36fa1a7279d68936e74a01 Mon Sep 17 00:00:00 2001 From: gourishkb <104021126+gourishkb@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:14:10 +0530 Subject: [PATCH 1/4] fix(): add weighted shuffle filter by default Signed-off-by: gourishkb <104021126+gourishkb@users.noreply.github.com> --- provider/ns1/ns1.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/provider/ns1/ns1.go b/provider/ns1/ns1.go index fa1c0d2dbb..748513d54e 100644 --- a/provider/ns1/ns1.go +++ b/provider/ns1/ns1.go @@ -255,12 +255,17 @@ func (p *NS1Provider) ns1BuildRecord(zoneName string, change *ns1Change) *dns.Re func (p *NS1Provider) reconcileRecordChanges(record *dns.Record, action string) (*dns.Record, string) { r, _, err := p.client.GetRecord(record.Zone, record.Domain, record.Type) - // Add the filters back to the posting object // method ns1BuildRecord creats a new record object, which discards the original filters available at ns1 - // if r != nil { - // record.Filters = r.Filters - // } + if r != nil { + if r.Filters != nil { + if len(r.Filters) == 0 { + r.Filters = make([]*filter.Filter, 0) + r.Filters = append(r.Filters, filter.NewWeightedShuffle()) + } + record.Filters = r.Filters + } + } switch action { case ns1Create: @@ -338,7 +343,6 @@ func (p *NS1Provider) ns1SubmitChanges(changes []*ns1Change) error { // So we need to update the records properly while making sure that we are not changing records owned by // other instances record, action := p.reconcileRecordChanges(record, change.Action) - logFields = log.Fields{ "record": record.Domain, "type": record.Type, @@ -346,6 +350,7 @@ func (p *NS1Provider) ns1SubmitChanges(changes []*ns1Change) error { "action": change.Action, "zone": zoneName, "Answers": record.Answers, + "Filters": record.Filters, } log.WithFields(logFields).Info("record changes after reconcile") @@ -354,8 +359,6 @@ func (p *NS1Provider) ns1SubmitChanges(changes []*ns1Change) error { } - record.Filters = make([]*filter.Filter, 0) - switch action { case ns1Create: _, err := p.client.CreateRecord(record) From 50621642944cb269774cfbf54d5af14b569025c1 Mon Sep 17 00:00:00 2001 From: gourishkb <104021126+gourishkb@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:56:33 +0530 Subject: [PATCH 2/4] fix(): liniting issues Signed-off-by: gourishkb <104021126+gourishkb@users.noreply.github.com> --- provider/ns1/ns1.go | 1 - provider/stackpath/stackpath.go | 7 +------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/provider/ns1/ns1.go b/provider/ns1/ns1.go index 748513d54e..611d1f55fb 100644 --- a/provider/ns1/ns1.go +++ b/provider/ns1/ns1.go @@ -356,7 +356,6 @@ func (p *NS1Provider) ns1SubmitChanges(changes []*ns1Change) error { if p.dryRun { continue - } switch action { diff --git a/provider/stackpath/stackpath.go b/provider/stackpath/stackpath.go index 892b051cc8..a57ed28a85 100644 --- a/provider/stackpath/stackpath.go +++ b/provider/stackpath/stackpath.go @@ -24,6 +24,7 @@ import ( "time" log "github.com/sirupsen/logrus" + "sigs.k8s.io/external-dns/endpoint" "sigs.k8s.io/external-dns/plan" "sigs.k8s.io/external-dns/provider" @@ -54,7 +55,6 @@ type StackPathConfig struct { } func NewStackPathProvider(config StackPathConfig) (*StackPathProvider, error) { - log.Info("Creating StackPath provider") clientID, ok := os.LookupEnv("STACKPATH_CLIENT_ID") @@ -103,7 +103,6 @@ func NewStackPathProvider(config StackPathConfig) (*StackPathProvider, error) { //Base Provider Functions func (p *StackPathProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, error) { - log.Info("Getting records from StackPath") var endpoints []*endpoint.Endpoint @@ -114,7 +113,6 @@ func (p *StackPathProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, } for _, zone := range zones { - recordsResponse, _, err := p.getZoneRecords(zone.GetId()) if err != nil { return nil, err @@ -186,7 +184,6 @@ func (p *StackPathProvider) StackPathStyleRecords() ([]dns.ZoneZoneRecord, error } } } - } return records, nil @@ -357,9 +354,7 @@ func (p *StackPathProvider) createCall(zoneID string, domain string, endpoint *e func (p *StackPathProvider) delete(endpoints []*endpoint.Endpoint, zones *[]dns.ZoneZone, zoneIDNameMap *provider.ZoneIDName, records *[]dns.ZoneZoneRecord) error { for _, endpoint := range endpoints { for _, zone := range *zones { - endpoint.DNSName = strings.Replace(endpoint.DNSName, "-"+zone.GetDomain(), "-at."+zone.GetDomain(), -1) - } } From c6f971aaeca394562f2e173e22090887661c90b0 Mon Sep 17 00:00:00 2001 From: gourishkb <104021126+gourishkb@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:09:00 +0530 Subject: [PATCH 3/4] fix(): linting issues Signed-off-by: gourishkb <104021126+gourishkb@users.noreply.github.com> --- go.mod | 14 -------------- go.sum | 14 -------------- provider/stackpath/stackpath.go | 3 --- 3 files changed, 31 deletions(-) diff --git a/go.mod b/go.mod index ab5460da66..54386cfc36 100644 --- a/go.mod +++ b/go.mod @@ -93,7 +93,6 @@ require ( github.com/alexbrainman/sspi v0.0.0-20180613141037-e580b900e9f5 // indirect github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect github.com/ans-group/go-durationstring v1.2.0 // indirect - github.com/ans-group/go-durationstring v1.2.0 // indirect github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect @@ -205,17 +204,4 @@ require ( require github.com/kubeslice/stackpath v0.1.0 -require ( - github.com/PuerkitoBio/purell v1.1.1 // indirect - github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect - github.com/emicklei/go-restful v2.9.5+incompatible // indirect - github.com/go-openapi/jsonpointer v0.19.5 // indirect - github.com/go-openapi/jsonreference v0.19.5 // indirect - github.com/go-openapi/swag v0.19.14 // indirect - github.com/google/gnostic v0.5.7-v3refs // indirect - github.com/josharian/intern v1.0.0 // indirect - github.com/mailru/easyjson v0.7.6 // indirect - github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect -) - replace k8s.io/klog/v2 => github.com/Raffo/knolog v0.0.0-20211016155154-e4d5e0cc970a diff --git a/go.sum b/go.sum index d98e2a7f7b..e1d7466dad 100644 --- a/go.sum +++ b/go.sum @@ -82,8 +82,6 @@ github.com/Azure/go-autorest/autorest v0.11.1/go.mod h1:JFgpikqFJ/MleTTxwepExTKn github.com/Azure/go-autorest/autorest v0.11.12/go.mod h1:eipySxLmqSyC5s5k1CLupqet0PSENBEDP93LQ9a8QYw= github.com/Azure/go-autorest/autorest v0.11.18/go.mod h1:dSiJPy22c3u0OtOKDNttNgqpNFY/GeWa7GH/Pz56QRA= github.com/Azure/go-autorest/autorest v0.11.19/go.mod h1:dSiJPy22c3u0OtOKDNttNgqpNFY/GeWa7GH/Pz56QRA= -github.com/Azure/go-autorest/autorest v0.11.27 h1:F3R3q42aWytozkV8ihzcgMO4OA4cuqr3bNlsEuF6//A= -github.com/Azure/go-autorest/autorest v0.11.27/go.mod h1:7l8ybrIdUmGqZMTD0sRtAr8NvbHjfofbf8RSP2q7w7U= github.com/Azure/go-autorest/autorest v0.11.28 h1:ndAExarwr5Y+GaHE6VCaY1kyS/HwwGGyuimVhWsHOEM= github.com/Azure/go-autorest/autorest v0.11.28/go.mod h1:MrkzG3Y3AH668QyF9KRk5neJnGgmhQ6krbhR8Q5eMvA= github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0= @@ -92,8 +90,6 @@ github.com/Azure/go-autorest/autorest/adal v0.9.5/go.mod h1:B7KF7jKIeC9Mct5spmyC github.com/Azure/go-autorest/autorest/adal v0.9.13/go.mod h1:W/MM4U6nLxnIskrw4UwWzlHfGjwUS50aOsc/I3yuU8M= github.com/Azure/go-autorest/autorest/adal v0.9.14/go.mod h1:W/MM4U6nLxnIskrw4UwWzlHfGjwUS50aOsc/I3yuU8M= github.com/Azure/go-autorest/autorest/adal v0.9.18/go.mod h1:XVVeme+LZwABT8K5Lc3hA4nAe8LDBVle26gTrguhhPQ= -github.com/Azure/go-autorest/autorest/adal v0.9.20 h1:gJ3E98kMpFB1MFqQCvA1yFab8vthOeD4VlFRQULxahg= -github.com/Azure/go-autorest/autorest/adal v0.9.20/go.mod h1:XVVeme+LZwABT8K5Lc3hA4nAe8LDBVle26gTrguhhPQ= github.com/Azure/go-autorest/autorest/adal v0.9.21 h1:jjQnVFXPfekaqb8vIsv2G1lxshoW+oGv4MDlhRtnYZk= github.com/Azure/go-autorest/autorest/adal v0.9.21/go.mod h1:zua7mBUaCc5YnSLKYgGJR/w5ePdMDA6H56upLsHzA9U= github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA= @@ -397,7 +393,6 @@ github.com/ecodia/golang-awaitility v0.0.0-20180710094957-fb55e59708c7/go.mod h1 github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= -github.com/emicklei/go-restful v2.9.5+incompatible h1:spTtZBk5DYEvbxMVutUuTyh1Ao2r4iyvLdACqsl/Ljk= github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/emicklei/go-restful/v3 v3.8.0 h1:eCZ8ulSerjdAiaNpF7GxXIE7ZCMo1moN1qX+S609eVw= github.com/emicklei/go-restful/v3 v3.8.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= @@ -1035,8 +1030,6 @@ github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKju github.com/miekg/dns v1.1.34/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4= -github.com/miekg/dns v1.1.48 h1:Ucfr7IIVyMBz4lRE8qmGUuZ4Wt3/ZGu9hmcMT3Uu4tQ= -github.com/miekg/dns v1.1.48/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME= github.com/miekg/dns v1.1.50 h1:DQUfb9uc6smULcREF09Uc+/Gd46YWqJd5DbpPE9xkcA= github.com/miekg/dns v1.1.50/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= @@ -1386,14 +1379,10 @@ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PK github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= -github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.344 h1:QhPDamT0YL04UaoteA9AEHnE/sklwYr+VSKd/pPQ6r8= -github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.344/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.550 h1:Yni5V2K50ke+YAdq2Y2C0F8wrz2f4BM6WXQU2g+/m2Y= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.550/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.344 h1:pdwJ6T3iEjP5nB9Mgi4y/OBO8XNtkGN2/+mjGZ8yCbw= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.344/go.mod h1:CuOaLxOQr477GhMWAQPYQFUJrsZbW+ZqkAgP2uHDZXg= -github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/privatedns v1.0.344 h1:q4r39zJkMyHvrORok48IOJz/nJ235dIkHStA9LZYwgw= -github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/privatedns v1.0.344/go.mod h1:En+pdagcHkAASorHT1l8R6tUtieRNNxaQ7nfyqWPefk= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/privatedns v1.0.550 h1:dJ5Rhnrx8lGd1dzfeuZvFK5nvMWe/qAp8U164fh86PM= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/privatedns v1.0.550/go.mod h1:wzxhy082eCcH3tVMl7J+YtXDY+EnNO+xCJP8CdsLrDg= github.com/terra-farm/udnssdk v1.3.5 h1:MNR3adfuuEK/l04+jzo8WW/0fnorY+nW515qb3vEr6I= @@ -1571,12 +1560,9 @@ golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211202192323-5770296d904e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f h1:OeJjE6G4dgCY4PIXvIRQbE8+RX+uXZyGhUy/ksMGJoc= -golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa h1:zuSxTR4o9y82ebqCUJYNGJbGPo6sKVl54f/TVDObg1c= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= diff --git a/provider/stackpath/stackpath.go b/provider/stackpath/stackpath.go index a57ed28a85..d368136f83 100644 --- a/provider/stackpath/stackpath.go +++ b/provider/stackpath/stackpath.go @@ -162,7 +162,6 @@ func (p *StackPathProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, } func (p *StackPathProvider) StackPathStyleRecords() ([]dns.ZoneZoneRecord, error) { - var records []dns.ZoneZoneRecord zones, err := p.zones() @@ -171,7 +170,6 @@ func (p *StackPathProvider) StackPathStyleRecords() ([]dns.ZoneZoneRecord, error } for _, zone := range zones { - recordsResponse, _, err := p.getZoneRecords(zone.GetId()) if err != nil || (p.testing && p.dryRun) { return nil, err @@ -190,7 +188,6 @@ func (p *StackPathProvider) StackPathStyleRecords() ([]dns.ZoneZoneRecord, error } func (p *StackPathProvider) getZoneRecords(zoneID string) (dns.ZoneGetZoneRecordsResponse, *http.Response, error) { - if p.testing && p.dryRun { return testGetZoneZoneRecordsResponse, nil, fmt.Errorf("testing") } else if p.testing { From d2b196aafda333a67ce6aeb4c794ead203f2c502 Mon Sep 17 00:00:00 2001 From: gourishkb <104021126+gourishkb@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:16:41 +0530 Subject: [PATCH 4/4] fix(): linting, newline Signed-off-by: gourishkb <104021126+gourishkb@users.noreply.github.com> --- provider/ns1/ns1.go | 1 - provider/stackpath/stackpath.go | 6 ------ 2 files changed, 7 deletions(-) diff --git a/provider/ns1/ns1.go b/provider/ns1/ns1.go index 611d1f55fb..096d004248 100644 --- a/provider/ns1/ns1.go +++ b/provider/ns1/ns1.go @@ -175,7 +175,6 @@ func (p *NS1Provider) Records(ctx context.Context) ([]*endpoint.Endpoint, error) for _, record := range zoneData.Records { if provider.SupportedRecordType(record.Type) { - // Fetch the complete record object from NS1 // This is required to get weight and note metadata r, _, err := p.client.GetRecord(zone.Zone, record.Domain, record.Type) diff --git a/provider/stackpath/stackpath.go b/provider/stackpath/stackpath.go index d368136f83..0488ad8262 100644 --- a/provider/stackpath/stackpath.go +++ b/provider/stackpath/stackpath.go @@ -198,7 +198,6 @@ func (p *StackPathProvider) getZoneRecords(zoneID string) (dns.ZoneGetZoneRecord } func (p *StackPathProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error { - infoString := "Creating " + fmt.Sprint(len(changes.Create)) + " Record(s), Updating " + fmt.Sprint(len(changes.UpdateNew)) + " Record(s), Deleting " + fmt.Sprint(len(changes.Delete)) + " Record(s)" //log.Infof(fmt.Sprint(changes)) @@ -247,7 +246,6 @@ func (p *StackPathProvider) ApplyChanges(ctx context.Context, changes *plan.Chan } func (p *StackPathProvider) create(endpoints []*endpoint.Endpoint, zones *[]dns.ZoneZone, zoneIDNameMap *provider.ZoneIDName) error { - for _, endpoint := range endpoints { for _, zone := range *zones { endpoint.DNSName = strings.Replace(endpoint.DNSName, "-"+zone.GetDomain(), "-at."+zone.GetDomain(), -1) @@ -276,7 +274,6 @@ func (p *StackPathProvider) create(endpoints []*endpoint.Endpoint, zones *[]dns. } func (p *StackPathProvider) createTarget(zoneID string, domain string, ep *endpoint.Endpoint, target string) error { - if val, ok := ep.GetProviderSpecificProperty("weight"); ok { if val, err := strconv.Atoi(val.Value); err == nil { if val < 1 { @@ -408,7 +405,6 @@ func (p *StackPathProvider) deleteCall(zoneID string, recordID string) (*http.Re } func (p *StackPathProvider) update(old []*endpoint.Endpoint, new []*endpoint.Endpoint, zones *[]dns.ZoneZone, zoneIDNameMap *provider.ZoneIDName, records *[]dns.ZoneZoneRecord) error { - err := p.create(new, zones, zoneIDNameMap) if err != nil { return err @@ -423,7 +419,6 @@ func (p *StackPathProvider) update(old []*endpoint.Endpoint, new []*endpoint.End } func (p *StackPathProvider) zones() ([]dns.ZoneZone, error) { - zoneResponse, _, err := p.getZones() if err != nil { return nil, err @@ -509,7 +504,6 @@ func endpointsByZoneID(zoneNameIDMapper provider.ZoneIDName, endpoints []*endpoi } func recordFromTarget(endpoint *endpoint.Endpoint, target string, records *[]dns.ZoneZoneRecord, domain string, ownerID string) (string, error) { - name := endpoint.DNSName if name == domain {