fix: godaddy - handle correctly when no postfix/prefix used for TXT

fix: godaddy.go - gofmt

fix: linter errors
This commit is contained in:
Timofey Titovets 2023-03-10 04:24:43 +01:00
parent 36409bb0fc
commit 3abaaeee9b
2 changed files with 37 additions and 35 deletions

View File

@ -29,6 +29,7 @@ import (
"time"
"golang.org/x/time/rate"
"sigs.k8s.io/external-dns/pkg/apis/externaldns"
)
@ -230,7 +231,7 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) {
for i := 1; i < 3 && err == nil && resp.StatusCode == 429; i++ {
retryAfter, _ := strconv.ParseInt(resp.Header.Get("Retry-After"), 10, 0)
jitter := rand.Int63n(int64(retryAfter))
jitter := rand.Int63n(retryAfter)
retryAfterSec := retryAfter + jitter/2
sleepTime := time.Duration(retryAfterSec) * time.Second

View File

@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@ -367,22 +367,6 @@ func (p *GDProvider) changeAllRecords(endpoints []gdEndpoint, zoneRecords []*gdR
return nil
}
func (p *GDProvider) endpointEqual(l *endpoint.Endpoint, r *endpoint.Endpoint) bool {
if l.DNSName != r.DNSName || l.RecordType!= r.RecordType {
return false
}
if ! l.Targets.Same(r.Targets) {
return false
}
if l.RecordTTL != r.RecordTTL {
return false
}
return true
}
// ApplyChanges applies a given set of changes in a given zone.
func (p *GDProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error {
if countTargets(changes) == 0 {
@ -404,25 +388,45 @@ func (p *GDProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) er
allChanges = p.appendChange(gdDelete, changes.Delete, allChanges)
for _, recOld := range changes.UpdateOld {
for _, recNew := range changes.UpdateNew {
if recOld.DNSName != recNew.DNSName {
continue
}
iOldSkip := make(map[int]bool)
iNewSkip := make(map[int]bool)
if ! p.endpointEqual(recOld, recNew) {
DeleteEndpoints := []*endpoint.Endpoint{recOld}
PatchEndpoints := []*endpoint.Endpoint{recNew}
if recOld.RecordType == recNew.RecordType {
allChanges = p.appendChange(gdReplace, PatchEndpoints, allChanges)
} else {
allChanges = p.appendChange(gdDelete, DeleteEndpoints, allChanges)
allChanges = p.appendChange(gdCreate, PatchEndpoints, allChanges)
}
for iOld, recOld := range changes.UpdateOld {
for iNew, recNew := range changes.UpdateNew {
if recOld.DNSName == recNew.DNSName && recOld.RecordType == recNew.RecordType {
ReplaceEndpoints := []*endpoint.Endpoint{recNew}
allChanges = p.appendChange(gdReplace, ReplaceEndpoints, allChanges)
iOldSkip[iOld] = true
iNewSkip[iNew] = true
break
}
}
}
for iOld, recOld := range changes.UpdateOld {
_, found := iOldSkip[iOld]
if found {
continue
}
for iNew, recNew := range changes.UpdateNew {
_, found := iNewSkip[iNew]
if found {
continue
}
if recOld.DNSName != recNew.DNSName {
continue
}
DeleteEndpoints := []*endpoint.Endpoint{recOld}
CreateEndpoints := []*endpoint.Endpoint{recNew}
allChanges = p.appendChange(gdDelete, DeleteEndpoints, allChanges)
allChanges = p.appendChange(gdCreate, CreateEndpoints, allChanges)
break
}
}
allChanges = p.appendChange(gdCreate, changes.Create, allChanges)
log.Infof("GoDaddy: %d changes will be done", len(allChanges))
@ -455,7 +459,6 @@ func (p *gdRecords) addRecord(client gdClient, endpoint endpoint.Endpoint, dnsNa
return err
}
}
return nil
@ -493,7 +496,6 @@ func (p *gdRecords) replaceRecord(client gdClient, endpoint endpoint.Endpoint, d
var response GDErrorResponse
if dryRun {
log.Infof("[DryRun] - Replace record %s.%s of type %s %s", dnsName, p.zone, endpoint.RecordType, records)
@ -540,7 +542,6 @@ func (p *gdRecords) deleteRecord(client gdClient, endpoint endpoint.Endpoint, dn
p.records = p.records[:len(p.records)-1]
p.changed = true
}
}
if dryRun {