Skip to content

Commit

Permalink
Merge pull request #3017 from olemarkus/ignore-invalid-endpoint
Browse files Browse the repository at this point in the history
Don't create endpoint if attempting to create one with invalid dns name
  • Loading branch information
k8s-ci-robot committed Oct 6, 2022
2 parents 178ea0e + 7dbf503 commit 644b880
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
7 changes: 7 additions & 0 deletions endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ func NewEndpointWithTTL(dnsName, recordType string, ttl TTL, targets ...string)
cleanTargets[idx] = strings.TrimSuffix(target, ".")
}

for _, label := range strings.Split(dnsName, ".") {
if len(label) > 63 {
log.Errorf("label %s in %s is longer than 63 characters. Cannot create endpoint", label, dnsName)
return nil
}
}

return &Endpoint{
DNSName: strings.TrimSuffix(dnsName, "."),
Targets: cleanTargets,
Expand Down
9 changes: 7 additions & 2 deletions registry/txt.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,13 @@ func (im *TXTRegistry) generateTXTRecord(r *endpoint.Endpoint) []*endpoint.Endpo
txt := endpoint.NewEndpoint(im.mapper.toTXTName(r.DNSName), endpoint.RecordTypeTXT, r.Labels.Serialize(true)).WithSetIdentifier(r.SetIdentifier)
txt.ProviderSpecific = r.ProviderSpecific
// new TXT record format (containing record type)
txtNew := endpoint.NewEndpoint(im.mapper.toNewTXTName(r.DNSName, r.RecordType), endpoint.RecordTypeTXT, r.Labels.Serialize(true)).WithSetIdentifier(r.SetIdentifier)
txtNew.ProviderSpecific = r.ProviderSpecific
txtNew := endpoint.NewEndpoint(im.mapper.toNewTXTName(r.DNSName, r.RecordType), endpoint.RecordTypeTXT, r.Labels.Serialize(true))
if txtNew != nil {
txtNew.WithSetIdentifier(r.SetIdentifier)
txtNew.ProviderSpecific = r.ProviderSpecific
} else {
return []*endpoint.Endpoint{txt}
}

return []*endpoint.Endpoint{txt, txtNew}
}
Expand Down
10 changes: 10 additions & 0 deletions registry/txt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,8 @@ func testTXTRegistryMissingRecordsNoPrefix(t *testing.T) {
newEndpointWithOwner("oldformat-otherowner.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=otherowner\"", endpoint.RecordTypeTXT, ""),
endpoint.NewEndpoint("unmanaged1.test-zone.example.org", endpoint.RecordTypeA, "unmanaged1.loadbalancer.com"),
endpoint.NewEndpoint("unmanaged2.test-zone.example.org", endpoint.RecordTypeCNAME, "unmanaged2.loadbalancer.com"),
newEndpointWithOwner("this-is-a-63-characters-long-label-that-we-do-expect-will-work.test-zone.example.org", "foo.loadbalancer.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("this-is-a-63-characters-long-label-that-we-do-expect-will-work.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
},
})
expectedRecords := []*endpoint.Endpoint{
Expand Down Expand Up @@ -849,6 +851,14 @@ func testTXTRegistryMissingRecordsNoPrefix(t *testing.T) {
Targets: endpoint.Targets{"unmanaged2.loadbalancer.com"},
RecordType: endpoint.RecordTypeCNAME,
},
{
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,
Labels: map[string]string{
endpoint.OwnerLabelKey: "owner",
},
},
}

expectedMissingRecords := []*endpoint.Endpoint{
Expand Down

0 comments on commit 644b880

Please sign in to comment.