Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(txt-registry): deprecate legacy txt-format #5172

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
141e87b
Merge branch 'kubernetes-sigs:master' into master
ivankatliarchuk Mar 6, 2025
a3395cc
Merge branch 'kubernetes-sigs:master' into master
ivankatliarchuk Mar 7, 2025
fc24c55
Merge branch 'kubernetes-sigs:master' into master
ivankatliarchuk Mar 11, 2025
6e691be
Merge branch 'kubernetes-sigs:master' into master
ivankatliarchuk Mar 13, 2025
bc329b3
feat(txt-registry): only support single format
ivankatliarchuk Mar 13, 2025
9fb8141
feat(txt-registry): only support single format
ivankatliarchuk Mar 13, 2025
5d82582
feat(txt-registry): only support single format
ivankatliarchuk Mar 13, 2025
d595404
feat(txt-registry): only support single format
ivankatliarchuk Mar 13, 2025
b50c7d9
feat(txt-registry): only support single format
ivankatliarchuk Mar 13, 2025
566bb39
feat(txt-registry): deprecate legacy txt-format
ivankatliarchuk Mar 14, 2025
2ee1723
feat(txt-registry): deprecate legacy txt-format
ivankatliarchuk Mar 14, 2025
f8882f6
feat(txt-registry): deprecate legacy txt-format
ivankatliarchuk Mar 14, 2025
8301811
feat(txt-registry): deprecate legacy txt-format
ivankatliarchuk Mar 14, 2025
213003a
feat(txt-registry): deprecate legacy txt-format
ivankatliarchuk Mar 14, 2025
06bdd64
feat(txt-registry): deprecate legacy txt-format
ivankatliarchuk Mar 14, 2025
33c5960
feat(txt-registry): deprecate legacy txt-format
ivankatliarchuk Mar 14, 2025
81e5483
feat(txt-registry): deprecate legacy txt-format
ivankatliarchuk Mar 14, 2025
84d8573
feat(txt-registry): deprecate legacy txt-format
ivankatliarchuk Mar 14, 2025
4faec98
feat(txt-registry): deprecate legacy txt-format
ivankatliarchuk Mar 19, 2025
fa9e37e
feat(txt-registry): deprecate legacy txt-format
ivankatliarchuk Mar 19, 2025
7b491e5
feat(txt-registry): deprecate legacy txt-format
ivankatliarchuk Mar 19, 2025
9be0cf1
feat(txt-registry): deprecate legacy txt-format
ivankatliarchuk Mar 19, 2025
4fe4f9e
feat(txt-registry): deprecate legacy txt-format
ivankatliarchuk Mar 20, 2025
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
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ insert_final_newline = true
[{Makefile,go.mod,go.sum,*.go}]
indent_style = tab
indent_size = 4

[*.py]
indent_style = space
indent_size = 4
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ repos:
rev: v0.44.0
hooks:
- id: markdownlint
args: ["--fix"]

minimum_pre_commit_version: !!str 3.2
2 changes: 1 addition & 1 deletion docs/flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
| `--txt-wildcard-replacement=""` | When using the TXT registry, a custom string that's used instead of an asterisk for TXT records corresponding to wildcard DNS records (optional) |
| `--[no-]txt-encrypt-enabled` | When using the TXT registry, set if TXT records should be encrypted before stored (default: disabled) |
| `--txt-encrypt-aes-key=""` | When using the TXT registry, set TXT record decryption and encryption 32 byte aes key (required when --txt-encrypt=true) |
| `--[no-]txt-new-format-only` | When using the TXT registry, only use new format records which include record type information (e.g., prefix: 'a-'). Reduces number of TXT records (default: disabled) |
| `--[no-]txt-new-format-only` | Was used during TXT format migration. Enabling or disabling it will not take any effect. (deprecated) |
| `--dynamodb-region=""` | When using the DynamoDB registry, the AWS region of the DynamoDB table (optional) |
| `--dynamodb-table="external-dns"` | When using the DynamoDB registry, the name of the DynamoDB table (default: "external-dns") |
| `--txt-cache-interval=0s` | The interval between cache synchronizations in duration format (default: disabled) |
Expand Down
45 changes: 43 additions & 2 deletions docs/registry/txt.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,49 @@
The TXT registry is the default registry.
It stores DNS record metadata in TXT records, using the same provider.

If you plan to manage apex domains with external-dns whilst using a txt registry, you should ensure when using --txt-prefix that you specify the record type substitution and that it ends in a period ., to ensure the record is created under the same domain as the apex record being managed, i.e. --txt-prefix=someprefix-%{record_type}.

## Record Format Options

### For version `v0.16.2+`

The TXT registry supports single format for storing DNS record metadata:

- Creates a TXT record with record type information (e.g., 'a-' prefix for A records)

The TXT registry would try to guarantee a consistency in between providers and sources, if provider supports the behaviour

If you are dealing with APEX domains, example `example.com` and TXT records are failing to be created for managed record types specified by `--managed-record-types`, consider following options:

1. TXT record with prefix based on requirements. Example `--txt-prefix="%{record_type}-abc-"` or `--txt-prefix="%{record_type}.abc-"`
2. TXT record with suffix based on requirements. Example `--txt-suffix="-abc-%{record_type}"` or `--txt-suffix="-abc.%{record_type}."`

Example when configured `--txt-prefix="%{record_type}-abc-"` for apex domain `example.com` the expected result is

| Name | TYPE |
|:-----------------------------:|:--------:|
| `a-abc-nginx-v2.ex.com.` | `TXT` |
| `nginx-v2.ex.com.` | `CNAME` |

And when configured `--txt-suffix="-abc.%{record_type}"` for apex domain `example.com` the expected result is

| Name | TYPE |
|:-----------------------------:|:-------:|
| `nginx-v2-abc.a.ex.com.` | `TXT` |
| `nginx-v3.ex.com..` | `CNAME` |

### Manually Cleanup Legacy TXT Records

> While deleting registry TXT records won't cause downtime, a well-thought-out migration and cleanup plan is crucial.

Occasionally, it may be necessary to remove outdated TXT records from your registry.

An example script for AWS can be found in [scripts/cleanup-legacy-txt-records.py](../../scripts/cleanup-legacy-txt-records.py) with instructions on how to run it.
The script performs targeted deletion of TXT records that include `ResourceRecords` matching the `heritage=external-dns,external-dns/owner=default` or similar pattern.
In the event of unintended deletion of all TXT records managed by `external-dns`, `external-dns` will initiate a full DNS record regeneration, along with`TXT` and `non-TXT` records. Just be aware, this operation's duration is directly proportional to the DNS estate size."

### For version `v0.16.0 & v0.16.1`

The TXT registry supports two formats for storing DNS record metadata:

- Legacy format: Creates a TXT record without record type information
Expand All @@ -31,14 +72,14 @@ The `--txt-new-format-only` flag should be used in addition to your existing ext

### Migration to New Format Only

> Note: `external-dns` will not automatically remove legacy format records when switching to new-format-only mode. You'll need to clean up the old records manually if desired.

When transitioning from dual-format to new-format-only records:

- Ensure all your `external-dns` instances support the new format
- Enable the `--txt-new-format-only` flag on your external-dns instances
Manually clean up any existing legacy format TXT records from your DNS provider

Note: `external-dns` will not automatically remove legacy format records when switching to new-format-only mode. You'll need to clean up the old records manually if desired.

## Prefixes and Suffixes

In order to avoid having the registry TXT records collide with
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/externaldns/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ func App(cfg *Config) *kingpin.Application {
app.Flag("txt-wildcard-replacement", "When using the TXT registry, a custom string that's used instead of an asterisk for TXT records corresponding to wildcard DNS records (optional)").Default(defaultConfig.TXTWildcardReplacement).StringVar(&cfg.TXTWildcardReplacement)
app.Flag("txt-encrypt-enabled", "When using the TXT registry, set if TXT records should be encrypted before stored (default: disabled)").BoolVar(&cfg.TXTEncryptEnabled)
app.Flag("txt-encrypt-aes-key", "When using the TXT registry, set TXT record decryption and encryption 32 byte aes key (required when --txt-encrypt=true)").Default(defaultConfig.TXTEncryptAESKey).StringVar(&cfg.TXTEncryptAESKey)
app.Flag("txt-new-format-only", "When using the TXT registry, only use new format records which include record type information (e.g., prefix: 'a-'). Reduces number of TXT records (default: disabled)").BoolVar(&cfg.TXTNewFormatOnly)
app.Flag("txt-new-format-only", "Was used during TXT format migration. Enabling or disabling it will not take any effect. (deprecated)").BoolVar(&cfg.TXTNewFormatOnly)
app.Flag("dynamodb-region", "When using the DynamoDB registry, the AWS region of the DynamoDB table (optional)").Default(cfg.AWSDynamoDBRegion).StringVar(&cfg.AWSDynamoDBRegion)
app.Flag("dynamodb-table", "When using the DynamoDB registry, the name of the DynamoDB table (default: \"external-dns\")").Default(defaultConfig.AWSDynamoDBTable).StringVar(&cfg.AWSDynamoDBTable)

Expand Down
19 changes: 4 additions & 15 deletions registry/txt.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ type TXTRegistry struct {
// encrypt text records
txtEncryptEnabled bool
txtEncryptAESKey []byte

newFormatOnly bool
}

// NewTXTRegistry returns a new TXTRegistry object. When newFormatOnly is true, it will only
Expand All @@ -74,6 +72,10 @@ func NewTXTRegistry(provider provider.Provider, txtPrefix, txtSuffix, ownerID st
return nil, errors.New("owner id cannot be empty")
}

if newFormatOnly {
log.Warn("--txt-new-format-only is left for backward compatibility, it will be removed in future releases")
}

if len(txtEncryptAESKey) == 0 {
txtEncryptAESKey = nil
} else if len(txtEncryptAESKey) != 32 {
Expand Down Expand Up @@ -103,7 +105,6 @@ func NewTXTRegistry(provider provider.Provider, txtPrefix, txtSuffix, ownerID st
excludeRecordTypes: excludeRecordTypes,
txtEncryptEnabled: txtEncryptEnabled,
txtEncryptAESKey: txtEncryptAESKey,
newFormatOnly: newFormatOnly,
}, nil
}

Expand Down Expand Up @@ -236,18 +237,6 @@ func (im *TXTRegistry) Records(ctx context.Context) ([]*endpoint.Endpoint, error
func (im *TXTRegistry) generateTXTRecord(r *endpoint.Endpoint) []*endpoint.Endpoint {
endpoints := make([]*endpoint.Endpoint, 0)

// Create legacy format record by default unless newFormatOnly is true
if !im.newFormatOnly && !im.txtEncryptEnabled && !im.mapper.recordTypeInAffix() && r.RecordType != endpoint.RecordTypeAAAA {
// old TXT record format
txt := endpoint.NewEndpoint(im.mapper.toTXTName(r.DNSName), endpoint.RecordTypeTXT, r.Labels.Serialize(true, im.txtEncryptEnabled, im.txtEncryptAESKey))
if txt != nil {
txt.WithSetIdentifier(r.SetIdentifier)
txt.Labels[endpoint.OwnedRecordLabelKey] = r.DNSName
txt.ProviderSpecific = r.ProviderSpecific
endpoints = append(endpoints, txt)
}
}

// Always create new format record
recordType := r.RecordType
// AWS Alias records are encoded as type "cname"
Expand Down
Loading
Loading