Skip to content

Commit 0d56712

Browse files
committed
feat: add option to use only new format TXT records
1 parent 8384fab commit 0d56712

File tree

4 files changed

+169
-38
lines changed

4 files changed

+169
-38
lines changed

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func main() {
387387
case "noop":
388388
r, err = registry.NewNoopRegistry(p)
389389
case "txt":
390-
r, err = registry.NewTXTRegistry(p, cfg.TXTPrefix, cfg.TXTSuffix, cfg.TXTOwnerID, cfg.TXTCacheInterval, cfg.TXTWildcardReplacement, cfg.ManagedDNSRecordTypes, cfg.ExcludeDNSRecordTypes, cfg.TXTEncryptEnabled, []byte(cfg.TXTEncryptAESKey))
390+
r, err = registry.NewTXTRegistry(p, cfg.TXTPrefix, cfg.TXTSuffix, cfg.TXTOwnerID, cfg.TXTCacheInterval, cfg.TXTWildcardReplacement, cfg.ManagedDNSRecordTypes, cfg.ExcludeDNSRecordTypes, cfg.TXTEncryptEnabled, []byte(cfg.TXTEncryptAESKey), cfg.TXTNewFormatOnly)
391391
case "aws-sd":
392392
r, err = registry.NewAWSSDRegistry(p, cfg.TXTOwnerID)
393393
default:

pkg/apis/externaldns/types.go

+2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ type Config struct {
138138
TXTSuffix string
139139
TXTEncryptEnabled bool
140140
TXTEncryptAESKey string `secure:"yes"`
141+
TXTNewFormatOnly bool
141142
Interval time.Duration
142143
MinEventSyncInterval time.Duration
143144
Once bool
@@ -299,6 +300,7 @@ var defaultConfig = &Config{
299300
MinEventSyncInterval: 5 * time.Second,
300301
TXTEncryptEnabled: false,
301302
TXTEncryptAESKey: "",
303+
TXTNewFormatOnly: false,
302304
Interval: time.Minute,
303305
Once: false,
304306
DryRun: false,

registry/txt.go

+19-6
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,19 @@ type TXTRegistry struct {
5656
// encrypt text records
5757
txtEncryptEnabled bool
5858
txtEncryptAESKey []byte
59+
60+
newFormatOnly bool
5961
}
6062

61-
// NewTXTRegistry returns new TXTRegistry object
62-
func NewTXTRegistry(provider provider.Provider, txtPrefix, txtSuffix, ownerID string, cacheInterval time.Duration, txtWildcardReplacement string, managedRecordTypes, excludeRecordTypes []string, txtEncryptEnabled bool, txtEncryptAESKey []byte) (*TXTRegistry, error) {
63+
// NewTXTRegistry returns a new TXTRegistry object. When newFormatOnly is true, it will only
64+
// generate new format TXT records, otherwise it generates both old and new formats for
65+
// backwards compatibility.
66+
func NewTXTRegistry(provider provider.Provider, txtPrefix, txtSuffix, ownerID string,
67+
cacheInterval time.Duration, txtWildcardReplacement string,
68+
managedRecordTypes, excludeRecordTypes []string,
69+
txtEncryptEnabled bool, txtEncryptAESKey []byte,
70+
newFormatOnly bool) (*TXTRegistry, error) {
71+
6372
if ownerID == "" {
6473
return nil, errors.New("owner id cannot be empty")
6574
}
@@ -88,6 +97,7 @@ func NewTXTRegistry(provider provider.Provider, txtPrefix, txtSuffix, ownerID st
8897
excludeRecordTypes: excludeRecordTypes,
8998
txtEncryptEnabled: txtEncryptEnabled,
9099
txtEncryptAESKey: txtEncryptAESKey,
100+
newFormatOnly: newFormatOnly,
91101
}, nil
92102
}
93103

@@ -209,12 +219,14 @@ func (im *TXTRegistry) Records(ctx context.Context) ([]*endpoint.Endpoint, error
209219
return endpoints, nil
210220
}
211221

212-
// generateTXTRecord generates both "old" and "new" TXT records.
213-
// Once we decide to drop old format we need to drop toTXTName() and rename toNewTXTName
222+
// generateTXTRecord generates TXT records in either both formats (old and new) or new format only,
223+
// depending on the newFormatOnly configuration. The old format is maintained for backwards
224+
// compatibility but can be disabled to reduce the number of DNS records.
214225
func (im *TXTRegistry) generateTXTRecord(r *endpoint.Endpoint) []*endpoint.Endpoint {
215226
endpoints := make([]*endpoint.Endpoint, 0)
216227

217-
if !im.txtEncryptEnabled && !im.mapper.recordTypeInAffix() && r.RecordType != endpoint.RecordTypeAAAA {
228+
// Create legacy format record by default unless newFormatOnly is true
229+
if !im.newFormatOnly && !im.txtEncryptEnabled && !im.mapper.recordTypeInAffix() && r.RecordType != endpoint.RecordTypeAAAA {
218230
// old TXT record format
219231
txt := endpoint.NewEndpoint(im.mapper.toTXTName(r.DNSName), endpoint.RecordTypeTXT, r.Labels.Serialize(true, im.txtEncryptEnabled, im.txtEncryptAESKey))
220232
if txt != nil {
@@ -224,7 +236,8 @@ func (im *TXTRegistry) generateTXTRecord(r *endpoint.Endpoint) []*endpoint.Endpo
224236
endpoints = append(endpoints, txt)
225237
}
226238
}
227-
// new TXT record format (containing record type)
239+
240+
// Always create new format record
228241
recordType := r.RecordType
229242
// AWS Alias records are encoded as type "cname"
230243
if isAlias, found := r.GetProviderSpecificProperty("alias"); found && isAlias == "true" && recordType == endpoint.RecordTypeA {

0 commit comments

Comments
 (0)