mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-07 01:56:57 +02:00
fix(registry): improve logging for TXT records with empty targets and add unit test
This commit is contained in:
parent
d097f9c2ff
commit
4ef055b1be
@ -148,7 +148,7 @@ func (im *TXTRegistry) Records(ctx context.Context) ([]*endpoint.Endpoint, error
|
|||||||
// We simply assume that TXT records for the registry will always have only one target.
|
// We simply assume that TXT records for the registry will always have only one target.
|
||||||
// If there are no targets (e.g for routing policy based records in google), direct targets will be empty
|
// If there are no targets (e.g for routing policy based records in google), direct targets will be empty
|
||||||
if len(record.Targets) == 0 {
|
if len(record.Targets) == 0 {
|
||||||
log.Errorf("TXT record has no targets", record.DNSName)
|
log.Errorf("TXT record has no targets %s", record.DNSName)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
labels, err := endpoint.NewLabelsFromString(record.Targets[0], im.txtEncryptAESKey)
|
labels, err := endpoint.NewLabelsFromString(record.Targets[0], im.txtEncryptAESKey)
|
||||||
|
@ -1798,3 +1798,38 @@ func TestApplyChangesWithNewFormatOnly(t *testing.T) {
|
|||||||
"TXT record should have 'a-' prefix when using new format only")
|
"TXT record should have 'a-' prefix when using new format only")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTXTRegistryRecordsWithEmptyTargets(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
p := inmemory.NewInMemoryProvider()
|
||||||
|
p.CreateZone(testZone)
|
||||||
|
p.ApplyChanges(ctx, &plan.Changes{
|
||||||
|
Create: []*endpoint.Endpoint{
|
||||||
|
{
|
||||||
|
DNSName: "empty-targets.test-zone.example.org",
|
||||||
|
RecordType: endpoint.RecordTypeTXT,
|
||||||
|
Targets: endpoint.Targets{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
DNSName: "valid-targets.test-zone.example.org",
|
||||||
|
RecordType: endpoint.RecordTypeTXT,
|
||||||
|
Targets: endpoint.Targets{"target1"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
r, _ := NewTXTRegistry(p, "", "", "owner", time.Hour, "", []string{}, []string{}, false, nil, false)
|
||||||
|
records, err := r.Records(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
expectedRecords := []*endpoint.Endpoint{
|
||||||
|
{
|
||||||
|
DNSName: "valid-targets.test-zone.example.org",
|
||||||
|
Targets: endpoint.Targets{"target1"},
|
||||||
|
RecordType: endpoint.RecordTypeTXT,
|
||||||
|
Labels: map[string]string{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.True(t, testutils.SameEndpoints(records, expectedRecords))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user