Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions docs/tutorials/crd.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,45 @@ spec:
- **With `--force-default-targets` (Legacy Behavior):** A CNAME record for `smoke-nt.example.com` will be created pointing to `1.2.3.4`.

`--force-default-targets` allows migration path to clean CRD resources.

### DNSEndpoint with an SRV record

Here's an example of a `DNSEndpoint` with an SRV record:

```yaml
---
apiVersion: externaldns.k8s.io/v1alpha1
kind: DNSEndpoint
metadata:
name: test-srv
namespace: default
spec:
endpoints:
- dnsName: _sip._udp.test.example.com
recordTTL: 180
recordType: SRV
targets:
- 1 50 5060 sip1-n1.test.example.com
- 1 50 5060 sip1-n2.test.example.com
```

### DNSEndpoint with an NAPTR record

Here's an example of a `DNSEndpoint` with an NAPTR record:

```yaml
---
apiVersion: externaldns.k8s.io/v1alpha1
kind: DNSEndpoint
metadata:
name: test-naptr
namespace: default
spec:
endpoints:
- dnsName: test.example.com
recordTTL: 180
recordType: NAPTR
targets:
- 50 50 "S" "SIPS+D2T" "" _sips._tcp.test.example.com.
- 100 50 "S" "SIP+D2U" "" _sip._udp.test.example.com.
```
2 changes: 1 addition & 1 deletion registry/txt.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func NewTXTRegistry(provider provider.Provider, txtPrefix, txtSuffix, ownerID st
}

func getSupportedTypes() []string {
return []string{endpoint.RecordTypeA, endpoint.RecordTypeAAAA, endpoint.RecordTypeCNAME, endpoint.RecordTypeNS, endpoint.RecordTypeMX}
return []string{endpoint.RecordTypeA, endpoint.RecordTypeAAAA, endpoint.RecordTypeCNAME, endpoint.RecordTypeNS, endpoint.RecordTypeMX, endpoint.RecordTypeSRV, endpoint.RecordTypeNAPTR}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may need to share more information why this constants added here. TXT registry does supports SRV records. So not too sure what is reason of updating the method.

Maybe worth to rename a method and add a description what is for. Hard to say

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this change, SRV and NAPTR records are not cleaned up when using sync mode.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have NAPTR records in my environment, but quite few SRV records. Not come across this problem. Could you share manifests so I could try to reproduce the problem?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, no problem. Steps to reproduce:

  • Start external-dns with the following arguments:
    --log-level=debug
    --log-format=text
    --interval=1m
    --source=service
    --source=ingress
    --source=crd
    --policy=sync
    --registry=txt
    --txt-owner-id=some-owner
    --txt-prefix=extdns-%{record_type}-
    --domain-filter=your-zone.example.com
    --provider=aws
    --zone-id-filter=REDACTED
    --managed-record-types=A
    --managed-record-types=AAAA
    --managed-record-types=CNAME
    --managed-record-types=NAPTR
    --managed-record-types=SRV
    --aws-zone-match-parent
    --aws-assume-role=arn:aws:iam::REDACTED:role/REDACTED
    
  • Create a DNSEndpoint with an SRV record. For example:
    apiVersion: externaldns.k8s.io/v1alpha1
    kind: DNSEndpoint
    metadata:
      name: test-srv
      namespace: default
    spec:
      endpoints:
      - dnsName: _sip._udp.your-zone.example.com
        recordTTL: 180
        recordType: SRV
        targets:
        - 1 50 5060 sip1-n1.your-zone.example.com
        - 1 50 5060 sip1-n2.your-zone.example.com
  • Watch external-dns create the record
  • Delete the DNSEndpoint
  • Notice that the SRV and related TXT record are not deleted from Route53

}

func (im *TXTRegistry) GetDomainFilter() endpoint.DomainFilterInterface {
Expand Down
84 changes: 84 additions & 0 deletions registry/txt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ func testTXTRegistryRecordsPrefixed(t *testing.T) {
newEndpointWithOwner("txt.aaaa-dualstack.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner-2\"", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("mail.test-zone.example.org", "10 onemail.example.com", endpoint.RecordTypeMX, ""),
newEndpointWithOwner("txt.mx-mail.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
newMultiTargetEndpointWithOwner(
"_sip._udp.sip1.test-zone.example.org",
[]string{"1 50 5060 sip1-n1.test-zone.example.org", "1 50 5060 sip1-n2.test-zone.example.org"},
endpoint.RecordTypeSRV,
"",
),
newEndpointWithOwner("txt._sip._udp.sip1.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("sip1.test-zone.example.org", `10 "U" "SIP+DTU" "" _sip._udp.sip1.test-zone.example.org.`, endpoint.RecordTypeNAPTR, ""),
newEndpointWithOwner("txt.sip1.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
},
})
expectedRecords := []*endpoint.Endpoint{
Expand Down Expand Up @@ -226,6 +235,25 @@ func testTXTRegistryRecordsPrefixed(t *testing.T) {
endpoint.OwnerLabelKey: "owner",
},
},
{
DNSName: "_sip._udp.sip1.test-zone.example.org",
Targets: endpoint.Targets{
"1 50 5060 sip1-n1.test-zone.example.org",
"1 50 5060 sip1-n2.test-zone.example.org",
},
RecordType: endpoint.RecordTypeSRV,
Labels: map[string]string{
endpoint.OwnerLabelKey: "owner",
},
},
{
DNSName: "sip1.test-zone.example.org",
Targets: endpoint.Targets{`10 "U" "SIP+DTU" "" _sip._udp.sip1.test-zone.example.org.`},
RecordType: endpoint.RecordTypeNAPTR,
Labels: map[string]string{
endpoint.OwnerLabelKey: "owner",
},
},
}

r, _ := NewTXTRegistry(p, "txt.", "", "owner", time.Hour, "wc", []string{}, []string{}, false, nil, "")
Expand Down Expand Up @@ -265,6 +293,15 @@ func testTXTRegistryRecordsSuffixed(t *testing.T) {
newEndpointWithOwner("aaaa-dualstack-txt.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner-2\"", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("mail.test-zone.example.org", "10 onemail.example.com", endpoint.RecordTypeMX, ""),
newEndpointWithOwner("mx-mail-txt.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
newMultiTargetEndpointWithOwner(
"_sip._udp.sip1.test-zone.example.org",
[]string{"1 50 5060 sip1-n1.test-zone.example.org", "1 50 5060 sip1-n2.test-zone.example.org"},
endpoint.RecordTypeSRV,
"",
),
newEndpointWithOwner("_sip-txt._udp.sip1.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("sip1.test-zone.example.org", `10 "U" "SIP+DTU" "" _sip._udp.sip1.test-zone.example.org.`, endpoint.RecordTypeNAPTR, ""),
newEndpointWithOwner("sip1-txt.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
},
})
expectedRecords := []*endpoint.Endpoint{
Expand Down Expand Up @@ -361,6 +398,25 @@ func testTXTRegistryRecordsSuffixed(t *testing.T) {
endpoint.OwnerLabelKey: "owner",
},
},
{
DNSName: "_sip._udp.sip1.test-zone.example.org",
Targets: endpoint.Targets{
"1 50 5060 sip1-n1.test-zone.example.org",
"1 50 5060 sip1-n2.test-zone.example.org",
},
RecordType: endpoint.RecordTypeSRV,
Labels: map[string]string{
endpoint.OwnerLabelKey: "owner",
},
},
{
DNSName: "sip1.test-zone.example.org",
Targets: endpoint.Targets{`10 "U" "SIP+DTU" "" _sip._udp.sip1.test-zone.example.org.`},
RecordType: endpoint.RecordTypeNAPTR,
Labels: map[string]string{
endpoint.OwnerLabelKey: "owner",
},
},
}

r, _ := NewTXTRegistry(p, "", "-txt", "owner", time.Hour, "", []string{}, []string{}, false, nil, "")
Expand Down Expand Up @@ -398,6 +454,15 @@ func testTXTRegistryRecordsNoPrefix(t *testing.T) {
newEndpointWithOwner("aaaa-dualstack.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner-2\"", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("mail.test-zone.example.org", "10 onemail.example.com", endpoint.RecordTypeMX, ""),
newEndpointWithOwner("mx-mail.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
newMultiTargetEndpointWithOwner(
"_sip._udp.sip1.test-zone.example.org",
[]string{"1 50 5060 sip1-n1.test-zone.example.org", "1 50 5060 sip1-n2.test-zone.example.org"},
endpoint.RecordTypeSRV,
"",
),
newEndpointWithOwner("_sip._udp.sip1.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("sip1.test-zone.example.org", `10 "U" "SIP+DTU" "" _sip._udp.sip1.test-zone.example.org.`, endpoint.RecordTypeNAPTR, ""),
newEndpointWithOwner("sip1.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
},
})
expectedRecords := []*endpoint.Endpoint{
Expand Down Expand Up @@ -488,6 +553,25 @@ func testTXTRegistryRecordsNoPrefix(t *testing.T) {
endpoint.OwnerLabelKey: "owner",
},
},
{
DNSName: "_sip._udp.sip1.test-zone.example.org",
Targets: endpoint.Targets{
"1 50 5060 sip1-n1.test-zone.example.org",
"1 50 5060 sip1-n2.test-zone.example.org",
},
RecordType: endpoint.RecordTypeSRV,
Labels: map[string]string{
endpoint.OwnerLabelKey: "owner",
},
},
{
DNSName: "sip1.test-zone.example.org",
Targets: endpoint.Targets{`10 "U" "SIP+DTU" "" _sip._udp.sip1.test-zone.example.org.`},
RecordType: endpoint.RecordTypeNAPTR,
Labels: map[string]string{
endpoint.OwnerLabelKey: "owner",
},
},
}

r, _ := NewTXTRegistry(p, "", "", "owner", time.Hour, "", []string{}, []string{}, false, nil, "")
Expand Down
13 changes: 13 additions & 0 deletions registry/txt_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,23 @@ func newEndpointWithOwner(dnsName, target, recordType, ownerID string) *endpoint
return newEndpointWithOwnerAndLabels(dnsName, target, recordType, ownerID, nil)
}

func newMultiTargetEndpointWithOwner(dnsName string, targets endpoint.Targets, recordType, ownerID string) *endpoint.Endpoint {
return newMultiTargetEndpointWithOwnerAndLabels(dnsName, targets, recordType, ownerID, nil)
}

func newEndpointWithOwnerAndOwnedRecord(dnsName, target, recordType, ownerID, ownedRecord string) *endpoint.Endpoint {
return newEndpointWithOwnerAndLabels(dnsName, target, recordType, ownerID, endpoint.Labels{endpoint.OwnedRecordLabelKey: ownedRecord})
}

func newMultiTargetEndpointWithOwnerAndLabels(dnsName string, targets endpoint.Targets, recordType, ownerID string, labels endpoint.Labels) *endpoint.Endpoint {
e := endpoint.NewEndpoint(dnsName, recordType, targets...)
e.Labels[endpoint.OwnerLabelKey] = ownerID
for k, v := range labels {
e.Labels[k] = v
}
return e
}

func newEndpointWithOwnerAndLabels(dnsName, target, recordType, ownerID string, labels endpoint.Labels) *endpoint.Endpoint {
e := endpoint.NewEndpoint(dnsName, recordType, target)
e.Labels[endpoint.OwnerLabelKey] = ownerID
Expand Down
Loading