@@ -145,32 +145,41 @@ func (im *TXTRegistry) Records(ctx context.Context) ([]*endpoint.Endpoint, error
145
145
endpoints = append (endpoints , record )
146
146
continue
147
147
}
148
- // We simply assume that TXT records for the registry will always have only one target.
149
148
// If there are no targets (e.g for routing policy based records in google), direct targets will be empty
150
149
if len (record .Targets ) == 0 {
151
150
log .Errorf ("TXT record has no targets %s" , record .DNSName )
152
151
continue
153
152
}
154
- labels , err := endpoint .NewLabelsFromString (record .Targets [0 ], im .txtEncryptAESKey )
155
- if errors .Is (err , endpoint .ErrInvalidHeritage ) {
156
- // if no heritage is found or it is invalid
157
- // case when value of txt record cannot be identified
158
- // record will not be removed as it will have empty owner
159
- endpoints = append (endpoints , record )
160
- continue
161
- }
162
- if err != nil {
163
- return nil , err
164
- }
165
153
166
- endpointName , recordType := im .mapper .toEndpointName (record .DNSName )
167
- key := endpoint.EndpointKey {
168
- DNSName : endpointName ,
169
- RecordType : recordType ,
170
- SetIdentifier : record .SetIdentifier ,
154
+ // Some of the targets in the TXT records may be heritage labels
155
+ // filter them out and add them to the txtRecordsMap
156
+ txtTargets := record .Targets
157
+ record .Targets = endpoint.Targets {}
158
+ for _ , target := range txtTargets {
159
+ labels , err := endpoint .NewLabelsFromString (target , im .txtEncryptAESKey )
160
+ if errors .Is (err , endpoint .ErrInvalidHeritage ) {
161
+ // add target back into record.Targets as
162
+ // this is not a heritage/label entry
163
+ record .Targets = append (record .Targets , target )
164
+ continue
165
+ }
166
+ if err != nil {
167
+ return nil , err
168
+ }
169
+
170
+ endpointName , recordType := im .mapper .toEndpointName (record .DNSName )
171
+ key := endpoint.EndpointKey {
172
+ DNSName : endpointName ,
173
+ RecordType : recordType ,
174
+ SetIdentifier : record .SetIdentifier ,
175
+ }
176
+ labelMap [key ] = labels
177
+ txtRecordsMap [record .DNSName ] = struct {}{}
178
+ }
179
+
180
+ if len (record .Targets ) != 0 {
181
+ endpoints = append (endpoints , record )
171
182
}
172
- labelMap [key ] = labels
173
- txtRecordsMap [record .DNSName ] = struct {}{}
174
183
}
175
184
176
185
for _ , ep := range endpoints {
0 commit comments