@@ -18,23 +18,21 @@ package txt
1818
1919import (
2020 "context"
21+ b64 "encoding/base64"
2122 "errors"
2223 "maps"
23-
2424 "strings"
2525 "time"
2626
27- b64 "encoding/base64"
28-
2927 log "github.com/sirupsen/logrus"
30-
31- "sigs.k8s.io/external-dns/pkg/apis/externaldns"
32- "sigs.k8s.io/external-dns/registry"
33- "sigs.k8s.io/external-dns/registry/mapper"
28+ "k8s.io/apimachinery/pkg/util/sets"
3429
3530 "sigs.k8s.io/external-dns/endpoint"
31+ "sigs.k8s.io/external-dns/pkg/apis/externaldns"
3632 "sigs.k8s.io/external-dns/plan"
3733 "sigs.k8s.io/external-dns/provider"
34+ "sigs.k8s.io/external-dns/registry"
35+ "sigs.k8s.io/external-dns/registry/mapper"
3836)
3937
4038const (
@@ -76,7 +74,7 @@ type TXTRegistry struct {
7674// It relies on the fact that Records() is always called **before** ApplyChanges()
7775// within a single reconciliation cycle.
7876type existingTXTs struct {
79- entries map [recordKey ]struct {}
77+ entries sets. Set [recordKey ]
8078}
8179
8280type recordKey struct {
@@ -86,7 +84,7 @@ type recordKey struct {
8684
8785func newExistingTXTs () * existingTXTs {
8886 return & existingTXTs {
89- entries : make (map [recordKey ]struct {} ),
87+ entries : make (sets. Set [recordKey ]),
9088 }
9189}
9290
@@ -95,7 +93,7 @@ func (im *existingTXTs) add(r *endpoint.Endpoint) {
9593 dnsName : r .DNSName ,
9694 setIdentifier : r .SetIdentifier ,
9795 }
98- im .entries [ key ] = struct {}{}
96+ im .entries . Insert ( key )
9997}
10098
10199// isAbsent returns true when there is no entry for the given name in the store.
@@ -105,14 +103,13 @@ func (im *existingTXTs) isAbsent(ep *endpoint.Endpoint) bool {
105103 dnsName : ep .DNSName ,
106104 setIdentifier : ep .SetIdentifier ,
107105 }
108- _ , ok := im .entries [key ]
109- return ! ok
106+ return ! im .entries .Has (key )
110107}
111108
112109func (im * existingTXTs ) reset () {
113110 // Reset the existing TXT records for the next reconciliation loop.
114111 // This is necessary because the existing TXT records are only relevant for the current reconciliation cycle.
115- im .entries = make (map [recordKey ]struct {} )
112+ im .entries = make (sets. Set [recordKey ])
116113}
117114
118115// New creates a TXTRegistry from the given configuration.
@@ -203,7 +200,7 @@ func (im *TXTRegistry) Records(ctx context.Context) ([]*endpoint.Endpoint, error
203200 endpoints := []* endpoint.Endpoint {}
204201
205202 labelMap := map [endpoint.EndpointKey ]endpoint.Labels {}
206- txtRecordsMap := map [string ]struct {}{}
203+ txtRecordsSet := make (sets. Set [string ], len ( records ))
207204
208205 for _ , record := range records {
209206 if record .RecordType != endpoint .RecordTypeTXT {
@@ -232,7 +229,7 @@ func (im *TXTRegistry) Records(ctx context.Context) ([]*endpoint.Endpoint, error
232229 SetIdentifier : record .SetIdentifier ,
233230 }
234231 labelMap [key ] = labels
235- txtRecordsMap [ record .DNSName ] = struct {}{}
232+ txtRecordsSet . Insert ( record .DNSName )
236233 im .existingTXTs .add (record )
237234 }
238235
@@ -274,12 +271,12 @@ func (im *TXTRegistry) Records(ctx context.Context) ([]*endpoint.Endpoint, error
274271 // TODO: remove this migration logic in some future release
275272 // Handle the migration of TXT records created before the new format (introduced in v0.12.0).
276273 // The migration is done for the TXT records owned by this instance only.
277- if len (txtRecordsMap ) > 0 && ep .Labels [endpoint .OwnerLabelKey ] == im .ownerID {
274+ if len (txtRecordsSet ) > 0 && ep .Labels [endpoint .OwnerLabelKey ] == im .ownerID {
278275 if plan .IsManagedRecord (ep .RecordType , im .managedRecordTypes , im .excludeRecordTypes ) {
279276 // Get desired TXT records and detect the missing ones
280277 desiredTXTs := im .generateTXTRecord (ep )
281278 for _ , desiredTXT := range desiredTXTs {
282- if _ , exists := txtRecordsMap [ desiredTXT .DNSName ]; ! exists {
279+ if ! txtRecordsSet . Has ( desiredTXT .DNSName ) {
283280 ep .WithProviderSpecific (providerSpecificForceUpdate , "true" )
284281 }
285282 }
0 commit comments