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" "time"
"golang.org/x/time/rate" "golang.org/x/time/rate"
"sigs.k8s.io/external-dns/pkg/apis/externaldns" "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++ { for i := 1; i < 3 && err == nil && resp.StatusCode == 429; i++ {
retryAfter, _ := strconv.ParseInt(resp.Header.Get("Retry-After"), 10, 0) retryAfter, _ := strconv.ParseInt(resp.Header.Get("Retry-After"), 10, 0)
jitter := rand.Int63n(int64(retryAfter)) jitter := rand.Int63n(retryAfter)
retryAfterSec := retryAfter + jitter/2 retryAfterSec := retryAfter + jitter/2
sleepTime := time.Duration(retryAfterSec) * time.Second 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 not use this file except in compliance with the License.
You may obtain a copy of the License at 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 Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, 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 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. // ApplyChanges applies a given set of changes in a given zone.
func (p *GDProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error { func (p *GDProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error {
if countTargets(changes) == 0 { 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) allChanges = p.appendChange(gdDelete, changes.Delete, allChanges)
for _, recOld := range changes.UpdateOld { iOldSkip := make(map[int]bool)
for _, recNew := range changes.UpdateNew { iNewSkip := make(map[int]bool)
if recOld.DNSName != recNew.DNSName {
continue
}
if ! p.endpointEqual(recOld, recNew) { for iOld, recOld := range changes.UpdateOld {
DeleteEndpoints := []*endpoint.Endpoint{recOld} for iNew, recNew := range changes.UpdateNew {
PatchEndpoints := []*endpoint.Endpoint{recNew} if recOld.DNSName == recNew.DNSName && recOld.RecordType == recNew.RecordType {
if recOld.RecordType == recNew.RecordType { ReplaceEndpoints := []*endpoint.Endpoint{recNew}
allChanges = p.appendChange(gdReplace, PatchEndpoints, allChanges) allChanges = p.appendChange(gdReplace, ReplaceEndpoints, allChanges)
} else { iOldSkip[iOld] = true
allChanges = p.appendChange(gdDelete, DeleteEndpoints, allChanges) iNewSkip[iNew] = true
allChanges = p.appendChange(gdCreate, PatchEndpoints, allChanges) 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) allChanges = p.appendChange(gdCreate, changes.Create, allChanges)
log.Infof("GoDaddy: %d changes will be done", len(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 err
} }
} }
return nil return nil
@ -493,7 +496,6 @@ func (p *gdRecords) replaceRecord(client gdClient, endpoint endpoint.Endpoint, d
var response GDErrorResponse var response GDErrorResponse
if dryRun { if dryRun {
log.Infof("[DryRun] - Replace record %s.%s of type %s %s", dnsName, p.zone, endpoint.RecordType, records) 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.records = p.records[:len(p.records)-1]
p.changed = true p.changed = true
} }
} }
if dryRun { if dryRun {