mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-08 02:26:58 +02:00
reimplement ForceUpdate using ProviderSpecific properties
Signed-off-by: Matias Charriere <matias@giantswarm.io>
This commit is contained in:
parent
ed49e67c00
commit
44b5761330
@ -30,7 +30,10 @@ import (
|
|||||||
"sigs.k8s.io/external-dns/provider"
|
"sigs.k8s.io/external-dns/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
const recordTemplate = "%{record_type}"
|
const (
|
||||||
|
recordTemplate = "%{record_type}"
|
||||||
|
providerSpecificForceUpdate = "txt/force-update"
|
||||||
|
)
|
||||||
|
|
||||||
// TXTRegistry implements registry interface with ownership implemented via associated TXT records
|
// TXTRegistry implements registry interface with ownership implemented via associated TXT records
|
||||||
type TXTRegistry struct {
|
type TXTRegistry struct {
|
||||||
@ -172,7 +175,7 @@ func (im *TXTRegistry) Records(ctx context.Context) ([]*endpoint.Endpoint, error
|
|||||||
desiredTXTs := im.generateTXTRecord(ep)
|
desiredTXTs := im.generateTXTRecord(ep)
|
||||||
for _, desiredTXT := range desiredTXTs {
|
for _, desiredTXT := range desiredTXTs {
|
||||||
if _, exists := txtRecordsMap[desiredTXT.DNSName]; !exists {
|
if _, exists := txtRecordsMap[desiredTXT.DNSName]; !exists {
|
||||||
ep.ForceUpdate = true
|
ep.WithProviderSpecific(providerSpecificForceUpdate, "true")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -283,6 +286,9 @@ func (im *TXTRegistry) ApplyChanges(ctx context.Context, changes *plan.Changes)
|
|||||||
|
|
||||||
// PropertyValuesEqual compares two attribute values for equality
|
// PropertyValuesEqual compares two attribute values for equality
|
||||||
func (im *TXTRegistry) PropertyValuesEqual(name string, previous string, current string) bool {
|
func (im *TXTRegistry) PropertyValuesEqual(name string, previous string, current string) bool {
|
||||||
|
if name == "txt/force-update" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return im.provider.PropertyValuesEqual(name, previous, current)
|
return im.provider.PropertyValuesEqual(name, previous, current)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -868,71 +868,75 @@ func testTXTRegistryMissingRecordsNoPrefix(t *testing.T) {
|
|||||||
})
|
})
|
||||||
expectedRecords := []*endpoint.Endpoint{
|
expectedRecords := []*endpoint.Endpoint{
|
||||||
{
|
{
|
||||||
DNSName: "oldformat.test-zone.example.org",
|
DNSName: "oldformat.test-zone.example.org",
|
||||||
Targets: endpoint.Targets{"foo.loadbalancer.com"},
|
Targets: endpoint.Targets{"foo.loadbalancer.com"},
|
||||||
RecordType: endpoint.RecordTypeCNAME,
|
RecordType: endpoint.RecordTypeCNAME,
|
||||||
ForceUpdate: true,
|
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
// owner was added from the TXT record's target
|
// owner was added from the TXT record's target
|
||||||
endpoint.OwnerLabelKey: "owner",
|
endpoint.OwnerLabelKey: "owner",
|
||||||
},
|
},
|
||||||
},
|
ProviderSpecific: []endpoint.ProviderSpecificProperty{
|
||||||
{
|
{
|
||||||
DNSName: "oldformat2.test-zone.example.org",
|
Name: "txt/force-update",
|
||||||
Targets: endpoint.Targets{"bar.loadbalancer.com"},
|
Value: "true",
|
||||||
RecordType: endpoint.RecordTypeA,
|
},
|
||||||
ForceUpdate: true,
|
|
||||||
Labels: map[string]string{
|
|
||||||
endpoint.OwnerLabelKey: "owner",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DNSName: "newformat.test-zone.example.org",
|
DNSName: "oldformat2.test-zone.example.org",
|
||||||
Targets: endpoint.Targets{"foobar.nameserver.com"},
|
Targets: endpoint.Targets{"bar.loadbalancer.com"},
|
||||||
RecordType: endpoint.RecordTypeNS,
|
RecordType: endpoint.RecordTypeA,
|
||||||
ForceUpdate: false,
|
Labels: map[string]string{
|
||||||
|
endpoint.OwnerLabelKey: "owner",
|
||||||
|
},
|
||||||
|
ProviderSpecific: []endpoint.ProviderSpecificProperty{
|
||||||
|
{
|
||||||
|
Name: "txt/force-update",
|
||||||
|
Value: "true",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
DNSName: "newformat.test-zone.example.org",
|
||||||
|
Targets: endpoint.Targets{"foobar.nameserver.com"},
|
||||||
|
RecordType: endpoint.RecordTypeNS,
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
endpoint.OwnerLabelKey: "owner",
|
endpoint.OwnerLabelKey: "owner",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Only TXT records with the wrong heritage are returned by Records()
|
// Only TXT records with the wrong heritage are returned by Records()
|
||||||
{
|
{
|
||||||
DNSName: "noheritage.test-zone.example.org",
|
DNSName: "noheritage.test-zone.example.org",
|
||||||
Targets: endpoint.Targets{"random"},
|
Targets: endpoint.Targets{"random"},
|
||||||
RecordType: endpoint.RecordTypeTXT,
|
RecordType: endpoint.RecordTypeTXT,
|
||||||
ForceUpdate: false,
|
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
// No owner because it's not external-dns heritage
|
// No owner because it's not external-dns heritage
|
||||||
endpoint.OwnerLabelKey: "",
|
endpoint.OwnerLabelKey: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DNSName: "oldformat-otherowner.test-zone.example.org",
|
DNSName: "oldformat-otherowner.test-zone.example.org",
|
||||||
Targets: endpoint.Targets{"bar.loadbalancer.com"},
|
Targets: endpoint.Targets{"bar.loadbalancer.com"},
|
||||||
RecordType: endpoint.RecordTypeA,
|
RecordType: endpoint.RecordTypeA,
|
||||||
ForceUpdate: false,
|
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
// Records() retrieves all the records of the zone, no matter the owner
|
// Records() retrieves all the records of the zone, no matter the owner
|
||||||
endpoint.OwnerLabelKey: "otherowner",
|
endpoint.OwnerLabelKey: "otherowner",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DNSName: "unmanaged1.test-zone.example.org",
|
DNSName: "unmanaged1.test-zone.example.org",
|
||||||
Targets: endpoint.Targets{"unmanaged1.loadbalancer.com"},
|
Targets: endpoint.Targets{"unmanaged1.loadbalancer.com"},
|
||||||
RecordType: endpoint.RecordTypeA,
|
RecordType: endpoint.RecordTypeA,
|
||||||
ForceUpdate: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DNSName: "unmanaged2.test-zone.example.org",
|
DNSName: "unmanaged2.test-zone.example.org",
|
||||||
Targets: endpoint.Targets{"unmanaged2.loadbalancer.com"},
|
Targets: endpoint.Targets{"unmanaged2.loadbalancer.com"},
|
||||||
RecordType: endpoint.RecordTypeCNAME,
|
RecordType: endpoint.RecordTypeCNAME,
|
||||||
ForceUpdate: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DNSName: "this-is-a-63-characters-long-label-that-we-do-expect-will-work.test-zone.example.org",
|
DNSName: "this-is-a-63-characters-long-label-that-we-do-expect-will-work.test-zone.example.org",
|
||||||
Targets: endpoint.Targets{"foo.loadbalancer.com"},
|
Targets: endpoint.Targets{"foo.loadbalancer.com"},
|
||||||
RecordType: endpoint.RecordTypeCNAME,
|
RecordType: endpoint.RecordTypeCNAME,
|
||||||
ForceUpdate: false,
|
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
endpoint.OwnerLabelKey: "owner",
|
endpoint.OwnerLabelKey: "owner",
|
||||||
},
|
},
|
||||||
@ -967,64 +971,69 @@ func testTXTRegistryMissingRecordsWithPrefix(t *testing.T) {
|
|||||||
})
|
})
|
||||||
expectedRecords := []*endpoint.Endpoint{
|
expectedRecords := []*endpoint.Endpoint{
|
||||||
{
|
{
|
||||||
DNSName: "oldformat.test-zone.example.org",
|
DNSName: "oldformat.test-zone.example.org",
|
||||||
Targets: endpoint.Targets{"foo.loadbalancer.com"},
|
Targets: endpoint.Targets{"foo.loadbalancer.com"},
|
||||||
RecordType: endpoint.RecordTypeCNAME,
|
RecordType: endpoint.RecordTypeCNAME,
|
||||||
ForceUpdate: true,
|
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
// owner was added from the TXT record's target
|
// owner was added from the TXT record's target
|
||||||
endpoint.OwnerLabelKey: "owner",
|
endpoint.OwnerLabelKey: "owner",
|
||||||
},
|
},
|
||||||
|
ProviderSpecific: []endpoint.ProviderSpecificProperty{
|
||||||
|
{
|
||||||
|
Name: "txt/force-update",
|
||||||
|
Value: "true",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DNSName: "oldformat2.test-zone.example.org",
|
DNSName: "oldformat2.test-zone.example.org",
|
||||||
Targets: endpoint.Targets{"bar.loadbalancer.com"},
|
Targets: endpoint.Targets{"bar.loadbalancer.com"},
|
||||||
RecordType: endpoint.RecordTypeA,
|
RecordType: endpoint.RecordTypeA,
|
||||||
ForceUpdate: true,
|
Labels: map[string]string{
|
||||||
|
endpoint.OwnerLabelKey: "owner",
|
||||||
|
},
|
||||||
|
ProviderSpecific: []endpoint.ProviderSpecificProperty{
|
||||||
|
{
|
||||||
|
Name: "txt/force-update",
|
||||||
|
Value: "true",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
DNSName: "newformat.test-zone.example.org",
|
||||||
|
Targets: endpoint.Targets{"foobar.nameserver.com"},
|
||||||
|
RecordType: endpoint.RecordTypeNS,
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
endpoint.OwnerLabelKey: "owner",
|
endpoint.OwnerLabelKey: "owner",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DNSName: "newformat.test-zone.example.org",
|
DNSName: "noheritage.test-zone.example.org",
|
||||||
Targets: endpoint.Targets{"foobar.nameserver.com"},
|
Targets: endpoint.Targets{"random"},
|
||||||
RecordType: endpoint.RecordTypeNS,
|
RecordType: endpoint.RecordTypeTXT,
|
||||||
ForceUpdate: false,
|
|
||||||
Labels: map[string]string{
|
|
||||||
endpoint.OwnerLabelKey: "owner",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
DNSName: "noheritage.test-zone.example.org",
|
|
||||||
Targets: endpoint.Targets{"random"},
|
|
||||||
RecordType: endpoint.RecordTypeTXT,
|
|
||||||
ForceUpdate: false,
|
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
// No owner because it's not external-dns heritage
|
// No owner because it's not external-dns heritage
|
||||||
endpoint.OwnerLabelKey: "",
|
endpoint.OwnerLabelKey: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DNSName: "oldformat-otherowner.test-zone.example.org",
|
DNSName: "oldformat-otherowner.test-zone.example.org",
|
||||||
Targets: endpoint.Targets{"bar.loadbalancer.com"},
|
Targets: endpoint.Targets{"bar.loadbalancer.com"},
|
||||||
RecordType: endpoint.RecordTypeA,
|
RecordType: endpoint.RecordTypeA,
|
||||||
ForceUpdate: false,
|
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
// All the records of the zone are retrieved, no matter the owner
|
// All the records of the zone are retrieved, no matter the owner
|
||||||
endpoint.OwnerLabelKey: "otherowner",
|
endpoint.OwnerLabelKey: "otherowner",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DNSName: "unmanaged1.test-zone.example.org",
|
DNSName: "unmanaged1.test-zone.example.org",
|
||||||
Targets: endpoint.Targets{"unmanaged1.loadbalancer.com"},
|
Targets: endpoint.Targets{"unmanaged1.loadbalancer.com"},
|
||||||
RecordType: endpoint.RecordTypeA,
|
RecordType: endpoint.RecordTypeA,
|
||||||
ForceUpdate: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DNSName: "unmanaged2.test-zone.example.org",
|
DNSName: "unmanaged2.test-zone.example.org",
|
||||||
Targets: endpoint.Targets{"unmanaged2.loadbalancer.com"},
|
Targets: endpoint.Targets{"unmanaged2.loadbalancer.com"},
|
||||||
RecordType: endpoint.RecordTypeCNAME,
|
RecordType: endpoint.RecordTypeCNAME,
|
||||||
ForceUpdate: false,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user