mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-06 17:46:57 +02:00
Merge pull request #5149 from saikatharryc/fix-txt-record-panic
fix(registry): handle empty targets in TXT records logging an error
This commit is contained in:
commit
f43eb0cdcf
@ -146,6 +146,11 @@ func (im *TXTRegistry) Records(ctx context.Context) ([]*endpoint.Endpoint, error
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// 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 len(record.Targets) == 0 {
|
||||||
|
log.Errorf("TXT record has no targets %s", record.DNSName)
|
||||||
|
continue
|
||||||
|
}
|
||||||
labels, err := endpoint.NewLabelsFromString(record.Targets[0], im.txtEncryptAESKey)
|
labels, err := endpoint.NewLabelsFromString(record.Targets[0], im.txtEncryptAESKey)
|
||||||
if errors.Is(err, endpoint.ErrInvalidHeritage) {
|
if errors.Is(err, endpoint.ErrInvalidHeritage) {
|
||||||
// if no heritage is found or it is invalid
|
// if no heritage is found or it is invalid
|
||||||
|
@ -26,6 +26,8 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"sigs.k8s.io/external-dns/endpoint"
|
"sigs.k8s.io/external-dns/endpoint"
|
||||||
"sigs.k8s.io/external-dns/internal/testutils"
|
"sigs.k8s.io/external-dns/internal/testutils"
|
||||||
"sigs.k8s.io/external-dns/plan"
|
"sigs.k8s.io/external-dns/plan"
|
||||||
@ -1798,3 +1800,40 @@ 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)
|
||||||
|
b := testutils.LogsToBuffer(log.ErrorLevel, t)
|
||||||
|
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))
|
||||||
|
assert.Contains(t, b.String(), "TXT record has no targets empty-targets.test-zone.example.org")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user