mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-07 18:16:57 +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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -871,26 +871,35 @@ func testTXTRegistryMissingRecordsNoPrefix(t *testing.T) {
|
|||||||
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{
|
Labels: map[string]string{
|
||||||
endpoint.OwnerLabelKey: "owner",
|
endpoint.OwnerLabelKey: "owner",
|
||||||
},
|
},
|
||||||
|
ProviderSpecific: []endpoint.ProviderSpecificProperty{
|
||||||
|
{
|
||||||
|
Name: "txt/force-update",
|
||||||
|
Value: "true",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DNSName: "newformat.test-zone.example.org",
|
DNSName: "newformat.test-zone.example.org",
|
||||||
Targets: endpoint.Targets{"foobar.nameserver.com"},
|
Targets: endpoint.Targets{"foobar.nameserver.com"},
|
||||||
RecordType: endpoint.RecordTypeNS,
|
RecordType: endpoint.RecordTypeNS,
|
||||||
ForceUpdate: false,
|
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
endpoint.OwnerLabelKey: "owner",
|
endpoint.OwnerLabelKey: "owner",
|
||||||
},
|
},
|
||||||
@ -900,7 +909,6 @@ func testTXTRegistryMissingRecordsNoPrefix(t *testing.T) {
|
|||||||
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: "",
|
||||||
@ -910,7 +918,6 @@ func testTXTRegistryMissingRecordsNoPrefix(t *testing.T) {
|
|||||||
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",
|
||||||
@ -920,19 +927,16 @@ func testTXTRegistryMissingRecordsNoPrefix(t *testing.T) {
|
|||||||
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",
|
||||||
},
|
},
|
||||||
@ -970,26 +974,35 @@ func testTXTRegistryMissingRecordsWithPrefix(t *testing.T) {
|
|||||||
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{
|
Labels: map[string]string{
|
||||||
endpoint.OwnerLabelKey: "owner",
|
endpoint.OwnerLabelKey: "owner",
|
||||||
},
|
},
|
||||||
|
ProviderSpecific: []endpoint.ProviderSpecificProperty{
|
||||||
|
{
|
||||||
|
Name: "txt/force-update",
|
||||||
|
Value: "true",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DNSName: "newformat.test-zone.example.org",
|
DNSName: "newformat.test-zone.example.org",
|
||||||
Targets: endpoint.Targets{"foobar.nameserver.com"},
|
Targets: endpoint.Targets{"foobar.nameserver.com"},
|
||||||
RecordType: endpoint.RecordTypeNS,
|
RecordType: endpoint.RecordTypeNS,
|
||||||
ForceUpdate: false,
|
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
endpoint.OwnerLabelKey: "owner",
|
endpoint.OwnerLabelKey: "owner",
|
||||||
},
|
},
|
||||||
@ -998,7 +1011,6 @@ func testTXTRegistryMissingRecordsWithPrefix(t *testing.T) {
|
|||||||
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: "",
|
||||||
@ -1008,7 +1020,6 @@ func testTXTRegistryMissingRecordsWithPrefix(t *testing.T) {
|
|||||||
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",
|
||||||
@ -1018,13 +1029,11 @@ func testTXTRegistryMissingRecordsWithPrefix(t *testing.T) {
|
|||||||
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