reimplement ForceUpdate using ProviderSpecific properties

Signed-off-by: Matias Charriere <matias@giantswarm.io>
This commit is contained in:
Matias Charriere 2023-06-15 11:48:08 +02:00
parent ed49e67c00
commit 44b5761330
No known key found for this signature in database
GPG Key ID: FBD58286F94A15EA
2 changed files with 86 additions and 71 deletions

View File

@ -30,7 +30,10 @@ import (
"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
type TXTRegistry struct {
@ -172,7 +175,7 @@ func (im *TXTRegistry) Records(ctx context.Context) ([]*endpoint.Endpoint, error
desiredTXTs := im.generateTXTRecord(ep)
for _, desiredTXT := range desiredTXTs {
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
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)
}

View File

@ -871,26 +871,35 @@ func testTXTRegistryMissingRecordsNoPrefix(t *testing.T) {
DNSName: "oldformat.test-zone.example.org",
Targets: endpoint.Targets{"foo.loadbalancer.com"},
RecordType: endpoint.RecordTypeCNAME,
ForceUpdate: true,
Labels: map[string]string{
// owner was added from the TXT record's target
endpoint.OwnerLabelKey: "owner",
},
ProviderSpecific: []endpoint.ProviderSpecificProperty{
{
Name: "txt/force-update",
Value: "true",
},
},
},
{
DNSName: "oldformat2.test-zone.example.org",
Targets: endpoint.Targets{"bar.loadbalancer.com"},
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,
ForceUpdate: false,
Labels: map[string]string{
endpoint.OwnerLabelKey: "owner",
},
@ -900,7 +909,6 @@ func testTXTRegistryMissingRecordsNoPrefix(t *testing.T) {
DNSName: "noheritage.test-zone.example.org",
Targets: endpoint.Targets{"random"},
RecordType: endpoint.RecordTypeTXT,
ForceUpdate: false,
Labels: map[string]string{
// No owner because it's not external-dns heritage
endpoint.OwnerLabelKey: "",
@ -910,7 +918,6 @@ func testTXTRegistryMissingRecordsNoPrefix(t *testing.T) {
DNSName: "oldformat-otherowner.test-zone.example.org",
Targets: endpoint.Targets{"bar.loadbalancer.com"},
RecordType: endpoint.RecordTypeA,
ForceUpdate: false,
Labels: map[string]string{
// Records() retrieves all the records of the zone, no matter the owner
endpoint.OwnerLabelKey: "otherowner",
@ -920,19 +927,16 @@ func testTXTRegistryMissingRecordsNoPrefix(t *testing.T) {
DNSName: "unmanaged1.test-zone.example.org",
Targets: endpoint.Targets{"unmanaged1.loadbalancer.com"},
RecordType: endpoint.RecordTypeA,
ForceUpdate: false,
},
{
DNSName: "unmanaged2.test-zone.example.org",
Targets: endpoint.Targets{"unmanaged2.loadbalancer.com"},
RecordType: endpoint.RecordTypeCNAME,
ForceUpdate: false,
},
{
DNSName: "this-is-a-63-characters-long-label-that-we-do-expect-will-work.test-zone.example.org",
Targets: endpoint.Targets{"foo.loadbalancer.com"},
RecordType: endpoint.RecordTypeCNAME,
ForceUpdate: false,
Labels: map[string]string{
endpoint.OwnerLabelKey: "owner",
},
@ -970,26 +974,35 @@ func testTXTRegistryMissingRecordsWithPrefix(t *testing.T) {
DNSName: "oldformat.test-zone.example.org",
Targets: endpoint.Targets{"foo.loadbalancer.com"},
RecordType: endpoint.RecordTypeCNAME,
ForceUpdate: true,
Labels: map[string]string{
// owner was added from the TXT record's target
endpoint.OwnerLabelKey: "owner",
},
ProviderSpecific: []endpoint.ProviderSpecificProperty{
{
Name: "txt/force-update",
Value: "true",
},
},
},
{
DNSName: "oldformat2.test-zone.example.org",
Targets: endpoint.Targets{"bar.loadbalancer.com"},
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,
ForceUpdate: false,
Labels: map[string]string{
endpoint.OwnerLabelKey: "owner",
},
@ -998,7 +1011,6 @@ func testTXTRegistryMissingRecordsWithPrefix(t *testing.T) {
DNSName: "noheritage.test-zone.example.org",
Targets: endpoint.Targets{"random"},
RecordType: endpoint.RecordTypeTXT,
ForceUpdate: false,
Labels: map[string]string{
// No owner because it's not external-dns heritage
endpoint.OwnerLabelKey: "",
@ -1008,7 +1020,6 @@ func testTXTRegistryMissingRecordsWithPrefix(t *testing.T) {
DNSName: "oldformat-otherowner.test-zone.example.org",
Targets: endpoint.Targets{"bar.loadbalancer.com"},
RecordType: endpoint.RecordTypeA,
ForceUpdate: false,
Labels: map[string]string{
// All the records of the zone are retrieved, no matter the owner
endpoint.OwnerLabelKey: "otherowner",
@ -1018,13 +1029,11 @@ func testTXTRegistryMissingRecordsWithPrefix(t *testing.T) {
DNSName: "unmanaged1.test-zone.example.org",
Targets: endpoint.Targets{"unmanaged1.loadbalancer.com"},
RecordType: endpoint.RecordTypeA,
ForceUpdate: false,
},
{
DNSName: "unmanaged2.test-zone.example.org",
Targets: endpoint.Targets{"unmanaged2.loadbalancer.com"},
RecordType: endpoint.RecordTypeCNAME,
ForceUpdate: false,
},
}