@@ -157,15 +157,22 @@ func (r *DNSRecordReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
157
157
158
158
metrics .DnsRecordFailureCounter .WithLabelValues (dnsrecord .Namespace , dnsrecord .Name , dnsrecord .Spec .Name ).Set (0 )
159
159
160
- var existingRecord cloudflare.DNSRecord
161
-
162
- if dnsrecord .Status .RecordID != "" {
163
- var err error
164
- existingRecord , err = r .Cf .GetDNSRecord (ctx , cloudflare .ZoneIdentifier (zone .Status .ID ), dnsrecord .Status .RecordID )
165
- if err != nil && err .Error () != "Record does not exist. (81044)" {
166
- log .Error (err , "Failed to get DNS record from Cloudflare" )
167
- return ctrl.Result {RequeueAfter : time .Second * 30 }, err
160
+ cfExistingRecord , _ , err := r .Cf .ListDNSRecords (ctx , cloudflare .ZoneIdentifier (zone .Status .ID ), cloudflare.ListDNSRecordsParams {
161
+ Name : dnsrecord .Spec .Name ,
162
+ Type : dnsrecord .Spec .Type ,
163
+ Content : dnsrecord .Spec .Content ,
164
+ })
165
+ if err != nil {
166
+ if err := r .markFailed (dnsrecord , ctx , err .Error ()); err != nil {
167
+ log .Error (err , "Failed to update DNSRecord status" )
168
+ return ctrl.Result {}, err
168
169
}
170
+ return ctrl.Result {}, err
171
+ }
172
+
173
+ var existingRecord cloudflare.DNSRecord
174
+ if len (cfExistingRecord ) != 0 {
175
+ existingRecord = cfExistingRecord [0 ]
169
176
}
170
177
171
178
if (dnsrecord .Spec .Type == "A" || dnsrecord .Spec .Type == "AAAA" ) && dnsrecord .Spec .IPRef .Name != "" {
0 commit comments