mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-07 01:56:57 +02:00
Make DNSimple tolerant of unknown zones
Like other providers, the DNSimple provider should ignore any records that belong to zones outside of its control.
This commit is contained in:
parent
43649f01ae
commit
5216b5b15c
@ -227,9 +227,11 @@ func (p *dnsimpleProvider) submitChanges(changes []*dnsimpleChange) error {
|
|||||||
}
|
}
|
||||||
for _, change := range changes {
|
for _, change := range changes {
|
||||||
zone := dnsimpleSuitableZone(change.ResourceRecordSet.Name, zones)
|
zone := dnsimpleSuitableZone(change.ResourceRecordSet.Name, zones)
|
||||||
if zone.ID == 0 {
|
if zone == nil {
|
||||||
return fmt.Errorf("No suitable zone name found")
|
log.Debugf("Skipping record %s because no hosted zone matching record DNS Name was detected ", change.ResourceRecordSet.Name)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("Changing records: %s %v in zone: %s", change.Action, change.ResourceRecordSet, zone.Name)
|
log.Infof("Changing records: %s %v in zone: %s", change.Action, change.ResourceRecordSet, zone.Name)
|
||||||
|
|
||||||
change.ResourceRecordSet.Name = strings.TrimSuffix(change.ResourceRecordSet.Name, "."+zone.Name)
|
change.ResourceRecordSet.Name = strings.TrimSuffix(change.ResourceRecordSet.Name, "."+zone.Name)
|
||||||
@ -290,12 +292,13 @@ func (p *dnsimpleProvider) GetRecordID(zone string, recordName string) (recordID
|
|||||||
}
|
}
|
||||||
|
|
||||||
// dnsimpleSuitableZone returns the most suitable zone for a given hostname and a set of zones.
|
// dnsimpleSuitableZone returns the most suitable zone for a given hostname and a set of zones.
|
||||||
func dnsimpleSuitableZone(hostname string, zones map[string]dnsimple.Zone) dnsimple.Zone {
|
func dnsimpleSuitableZone(hostname string, zones map[string]dnsimple.Zone) *dnsimple.Zone {
|
||||||
var zone dnsimple.Zone
|
var zone *dnsimple.Zone
|
||||||
for _, z := range zones {
|
for _, z := range zones {
|
||||||
if strings.HasSuffix(hostname, z.Name) {
|
if strings.HasSuffix(hostname, z.Name) {
|
||||||
if zone.ID == 0 || len(z.Name) > len(zone.Name) {
|
if zone == nil || len(z.Name) > len(zone.Name) {
|
||||||
zone = z
|
newZ := z
|
||||||
|
zone = &newZ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,6 +124,7 @@ func TestDnsimpleServices(t *testing.T) {
|
|||||||
t.Run("Zones", testDnsimpleProviderZones)
|
t.Run("Zones", testDnsimpleProviderZones)
|
||||||
t.Run("Records", testDnsimpleProviderRecords)
|
t.Run("Records", testDnsimpleProviderRecords)
|
||||||
t.Run("ApplyChanges", testDnsimpleProviderApplyChanges)
|
t.Run("ApplyChanges", testDnsimpleProviderApplyChanges)
|
||||||
|
t.Run("ApplyChanges/SkipUnknownZone", testDnsimpleProviderApplyChangesSkipsUnknown)
|
||||||
t.Run("SuitableZone", testDnsimpleSuitableZone)
|
t.Run("SuitableZone", testDnsimpleSuitableZone)
|
||||||
t.Run("GetRecordID", testDnsimpleGetRecordID)
|
t.Run("GetRecordID", testDnsimpleGetRecordID)
|
||||||
}
|
}
|
||||||
@ -165,6 +166,19 @@ func testDnsimpleProviderApplyChanges(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testDnsimpleProviderApplyChangesSkipsUnknown(t *testing.T) {
|
||||||
|
changes := &plan.Changes{}
|
||||||
|
changes.Create = []*endpoint.Endpoint{
|
||||||
|
{DNSName: "example.not-included.com", Targets: endpoint.Targets{"dasd"}, RecordType: endpoint.RecordTypeCNAME},
|
||||||
|
}
|
||||||
|
|
||||||
|
mockProvider.accountID = "1"
|
||||||
|
err := mockProvider.ApplyChanges(changes)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Failed to ignore unknown zones: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testDnsimpleSuitableZone(t *testing.T) {
|
func testDnsimpleSuitableZone(t *testing.T) {
|
||||||
mockProvider.accountID = "1"
|
mockProvider.accountID = "1"
|
||||||
zones, err := mockProvider.Zones()
|
zones, err := mockProvider.Zones()
|
||||||
|
Loading…
Reference in New Issue
Block a user