@@ -56,10 +56,19 @@ type TXTRegistry struct {
56
56
// encrypt text records
57
57
txtEncryptEnabled bool
58
58
txtEncryptAESKey []byte
59
+
60
+ newFormatOnly bool
59
61
}
60
62
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
+
63
72
if ownerID == "" {
64
73
return nil , errors .New ("owner id cannot be empty" )
65
74
}
@@ -88,6 +97,7 @@ func NewTXTRegistry(provider provider.Provider, txtPrefix, txtSuffix, ownerID st
88
97
excludeRecordTypes : excludeRecordTypes ,
89
98
txtEncryptEnabled : txtEncryptEnabled ,
90
99
txtEncryptAESKey : txtEncryptAESKey ,
100
+ newFormatOnly : newFormatOnly ,
91
101
}, nil
92
102
}
93
103
@@ -209,12 +219,14 @@ func (im *TXTRegistry) Records(ctx context.Context) ([]*endpoint.Endpoint, error
209
219
return endpoints , nil
210
220
}
211
221
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.
214
225
func (im * TXTRegistry ) generateTXTRecord (r * endpoint.Endpoint ) []* endpoint.Endpoint {
215
226
endpoints := make ([]* endpoint.Endpoint , 0 )
216
227
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 {
218
230
// old TXT record format
219
231
txt := endpoint .NewEndpoint (im .mapper .toTXTName (r .DNSName ), endpoint .RecordTypeTXT , r .Labels .Serialize (true , im .txtEncryptEnabled , im .txtEncryptAESKey ))
220
232
if txt != nil {
@@ -224,7 +236,8 @@ func (im *TXTRegistry) generateTXTRecord(r *endpoint.Endpoint) []*endpoint.Endpo
224
236
endpoints = append (endpoints , txt )
225
237
}
226
238
}
227
- // new TXT record format (containing record type)
239
+
240
+ // Always create new format record
228
241
recordType := r .RecordType
229
242
// AWS Alias records are encoded as type "cname"
230
243
if isAlias , found := r .GetProviderSpecificProperty ("alias" ); found && isAlias == "true" && recordType == endpoint .RecordTypeA {
0 commit comments