dnscontrol/documentation/language-reference/domain-modifiers
tridion f1b30a1a04
feat: Add IGNORE_EXTERNAL_DNS() for Kubernetes external-dns coexistence (#3869)s
## Summary

This PR adds a new domain modifier `IGNORE_EXTERNAL_DNS()` that
automatically detects and ignores DNS records managed by Kubernetes
[external-dns](https://github.com/kubernetes-sigs/external-dns)
controller.

**Related Issue:** This addresses the feature request discussed in
StackExchange/dnscontrol#935 (Idea: Ownership system), where
@tlimoncelli indicated openness to accepting a PR for this
functionality.

## Problem

When running DNSControl alongside Kubernetes external-dns, users face a
challenge:

- **external-dns** dynamically creates DNS records based on Kubernetes
Ingress/Service resources
- Users cannot use `IGNORE()` because they cannot predict which record
names external-dns will create
- Using `NO_PURGE()` is too broad - it prevents DNSControl from cleaning
up any orphaned records

The fundamental issue is that `IGNORE()` requires static patterns known
at config-time, but external-dns creates records dynamically at runtime.

## Solution

`IGNORE_EXTERNAL_DNS()` solves this by detecting external-dns managed
records at runtime:

```javascript
D("example.com", REG_CHANGEME, DnsProvider(DSP_MY_PROVIDER),
    IGNORE_EXTERNAL_DNS(),  // Automatically ignore external-dns managed records
    A("@", "1.2.3.4"),
    CNAME("www", "@")
);
```

### How It Works

external-dns uses a TXT record registry to track ownership. For each
managed record, it creates a TXT record like:

- `a-myapp.example.com` → TXT containing
`heritage=external-dns,external-dns/owner=...`
- `cname-api.example.com` → TXT containing
`heritage=external-dns,external-dns/owner=...`

This PR:
1. Scans existing TXT records for the `heritage=external-dns` marker
2. Parses the TXT record name prefix (e.g., `a-`, `cname-`) to determine
the managed record type
3. Automatically adds those records to the ignore list during diff
operations

## Changes

| File | Purpose |
|------|---------|
| `models/domain.go` | Add `IgnoreExternalDNS` field to DomainConfig |
| `pkg/js/helpers.js` | Add `IGNORE_EXTERNAL_DNS()` JavaScript helper |
| `pkg/diff2/externaldns.go` | Core detection logic for external-dns TXT
records |
| `pkg/diff2/externaldns_test.go` | Unit tests for detection logic |
| `pkg/diff2/handsoff.go` | Integrate external-dns detection into
handsoff() |
| `pkg/diff2/diff2.go` | Pass IgnoreExternalDNS flag to handsoff() |
| `commands/types/dnscontrol.d.ts` | TypeScript definitions for IDE
support |
| `documentation/.../IGNORE_EXTERNAL_DNS.md` | User documentation |

## Design Philosophy

This follows DNSControl's pattern of convenience builders (like
`M365_BUILDER`, `SPF_BUILDER`, `DKIM_BUILDER`) that make complex
operations simple. Just as those builders abstract away implementation
details, `IGNORE_EXTERNAL_DNS()` abstracts away the complexity of
detecting external-dns managed records.

## Testing

All unit tests pass:
```
go test ./pkg/diff2/... -v  # Tests detection logic
go test ./pkg/js/...        # Tests JS helpers
go build ./...              # Builds successfully
```

## Caveats Documented

- Only supports TXT registry (the default for external-dns)
- Requires external-dns to use default naming conventions
- May need updates if external-dns changes its registry format

---------

Co-authored-by: Tom Limoncelli <6293917+tlimoncelli@users.noreply.github.com>
2025-12-03 08:56:55 -05:00
..
A.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
AAAA.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
ADGUARDHOME_A_PASSTHROUGH.md NEW PROVIDER: ADGUARDHOME (#3638) 2025-07-09 12:06:34 -04:00
ADGUARDHOME_AAAA_PASSTHROUGH.md NEW PROVIDER: ADGUARDHOME (#3638) 2025-07-09 12:06:34 -04:00
AKAMAICDN.md DOCS: fix broken links (#3437) 2025-02-17 08:41:37 -05:00
AKAMAITLC.md AKAMAIEDGEDNS: Add ALIAS and AKAMAITLC support to the Akamai Edge DNS provider (#3836) 2025-11-14 09:48:42 -05:00
ALIAS.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
AUTODNSSEC_OFF.md
AUTODNSSEC_ON.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
AZURE_ALIAS.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
CAA.md CAA: Support issuemail / issuevmc tag in CAA builder (#3774) 2025-09-22 16:12:30 -04:00
CAA_BUILDER.md CAA: Support issuemail / issuevmc tag in CAA builder (#3774) 2025-09-22 16:12:30 -04:00
CF_REDIRECT.md DOCS: fix broken links (#3437) 2025-02-17 08:41:37 -05:00
CF_SINGLE_REDIRECT.md feat(cloudflare) SINGLE_REDIRECT permits more than 301/302 redirects (#3514) 2025-03-30 16:16:12 -04:00
CF_TEMP_REDIRECT.md DOCS: fix broken links (#3437) 2025-02-17 08:41:37 -05:00
CF_WORKER_ROUTE.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
CLOUDNS_WR.md
CNAME.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
DefaultTTL.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
DHCID.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
DISABLE_IGNORE_SAFETY_CHECK.md
DKIM_BUILDER.md refactor(DKIM_BUILDER): improve input validation and error handling (#3812) 2025-11-03 11:33:09 -05:00
DMARC_BUILDER.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
DNAME.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
DNSKEY.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
DnsProvider.md DOCS: [GitBook] Refactor structure to match URL paths and fix missing page links (#3613) 2025-06-11 16:20:23 -04:00
DS.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
FRAME.md DOCS: document redirect types (#3585) 2025-05-28 10:01:09 -04:00
HTTPS.md FEATURE: Support ignoring the ech= parameter in HTTPS/SVCB RR types (#3485) 2025-06-11 11:16:15 -04:00
IGNORE.md DOCS: Fix typo in IGNORE.md (#3512) 2025-03-30 14:25:08 -04:00
IGNORE_EXTERNAL_DNS.md feat: Add IGNORE_EXTERNAL_DNS() for Kubernetes external-dns coexistence (#3869)s 2025-12-03 08:56:55 -05:00
IGNORE_NAME.md
IGNORE_TARGET.md
IMPORT_TRANSFORM.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
IMPORT_TRANSFORM_STRIP.md
INCLUDE.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
LOC.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
LOC_BUILDER_DD.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
LOC_BUILDER_DMM_STR.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
LOC_BUILDER_DMS_STR.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
LOC_BUILDER_STR.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
LUA.md POWERDNS: New record type: LUA (#3815) 2025-11-03 11:32:28 -05:00
M365_BUILDER.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
MX.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
NAMESERVER.md DOCS: Fix many minor typos (#3752) 2025-09-02 11:00:25 -04:00
NAMESERVER_TTL.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
NAPTR.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
NO_PURGE.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
NS.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
OPENPGPKEY.md NEW RECORD TYPE: OPENPGPKEY (basic) (#3718) 2025-08-11 10:44:12 -04:00
PORKBUN_URLFWD.md
PTR.md DOCS: fix broken links (#3437) 2025-02-17 08:41:37 -05:00
PURGE.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
R53_ALIAS.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
SMIMEA.md NEW FEATURE: Add SMIMEA support for BIND and deSEC (#3786) 2025-10-10 11:16:13 -04:00
SOA.md DOCS: SOA RNAME description isn't accurate (#3481) 2025-03-07 09:06:23 -05:00
SPF_BUILDER.md FEATURE: Optionally disable spfcache.json (#3765) 2025-09-13 12:23:46 -04:00
SRV.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
SSHFP.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
SVCB.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
TLSA.md DOCS: Trailing commas are no longer an issue (#3248) 2024-12-17 07:46:37 -05:00
TXT.md DOCS: Clarification on quotes in TXT record. (#3721) 2025-08-13 09:58:19 -04:00
URL.md DOCS: document redirect types (#3585) 2025-05-28 10:01:09 -04:00
URL301.md DOCS: document redirect types (#3585) 2025-05-28 10:01:09 -04:00