Skip to content

Commit 39a0644

Browse files
committed
chore: put ctx first
1 parent 1592889 commit 39a0644

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

internal/controller/account_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (r *AccountReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
8989

9090
secret := &corev1.Secret{}
9191
if err := r.Get(ctx, client.ObjectKey{Namespace: account.Spec.ApiToken.SecretRef.Namespace, Name: account.Spec.ApiToken.SecretRef.Name}, secret); err != nil {
92-
if err := r.markFailed(account, ctx, "Failed to get secret"); err != nil {
92+
if err := r.markFailed(ctx, account, "Failed to get secret"); err != nil {
9393
log.Error(err, "Failed to update Account status")
9494
return ctrl.Result{}, err
9595
}
@@ -98,7 +98,7 @@ func (r *AccountReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
9898

9999
cfApiToken := string(secret.Data["apiToken"])
100100
if cfApiToken == "" {
101-
if err := r.markFailed(account, ctx, "Secret has no 'apiToken' key"); err != nil {
101+
if err := r.markFailed(ctx, account, "Secret has no 'apiToken' key"); err != nil {
102102
log.Error(err, "Failed to update Account status")
103103
return ctrl.Result{}, err
104104
}
@@ -108,7 +108,7 @@ func (r *AccountReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
108108
if r.Cf.APIToken != cfApiToken {
109109
cf, err := cloudflare.NewWithAPIToken(cfApiToken)
110110
if err != nil {
111-
if err := r.markFailed(account, ctx, err.Error()); err != nil {
111+
if err := r.markFailed(ctx, account, err.Error()); err != nil {
112112
log.Error(err, "Failed to update Account status")
113113
return ctrl.Result{}, err
114114
}
@@ -133,7 +133,7 @@ func (r *AccountReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
133133
}
134134

135135
// markFailed marks the reconciled object as failed
136-
func (r *AccountReconciler) markFailed(account *cloudflareoperatoriov1.Account, ctx context.Context, message string) error {
136+
func (r *AccountReconciler) markFailed(ctx context.Context, account *cloudflareoperatoriov1.Account, message string) error {
137137
metrics.AccountFailureCounter.WithLabelValues(account.Name).Set(1)
138138
apimeta.SetStatusCondition(&account.Status.Conditions, metav1.Condition{
139139
Type: "Ready",

internal/controller/dnsrecord_controller.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (r *DNSRecordReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
8787
zones := &cloudflareoperatoriov1.ZoneList{}
8888
if err := r.List(ctx, zones); err != nil {
8989
if errors.IsNotFound(err) {
90-
if err := r.markFailed(dnsrecord, ctx, "Failed to fetch Zones"); err != nil {
90+
if err := r.markFailed(ctx, dnsrecord, "Failed to fetch Zones"); err != nil {
9191
log.Error(err, "Failed to update DNSRecord status")
9292
return ctrl.Result{}, err
9393
}
@@ -106,7 +106,7 @@ func (r *DNSRecordReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
106106
}
107107

108108
if zone.Spec.Name == "" {
109-
if err := r.markFailed(dnsrecord, ctx, "Zone not found"); err != nil {
109+
if err := r.markFailed(ctx, dnsrecord, "Zone not found"); err != nil {
110110
log.Error(err, "Failed to update DNSRecord status")
111111
return ctrl.Result{}, err
112112
}
@@ -139,7 +139,7 @@ func (r *DNSRecordReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
139139
if !dnsrecord.DeletionTimestamp.IsZero() {
140140
if controllerutil.ContainsFinalizer(dnsrecord, common.CloudflareOperatorFinalizer) {
141141
if err := r.finalizeDNSRecord(ctx, zone.Status.ID, log, dnsrecord); err != nil && err.Error() != "Record does not exist. (81044)" {
142-
if err := r.markFailed(dnsrecord, ctx, err.Error()); err != nil {
142+
if err := r.markFailed(ctx, dnsrecord, err.Error()); err != nil {
143143
log.Error(err, "Failed to update DNSRecord status")
144144
return ctrl.Result{}, err
145145
}
@@ -163,7 +163,7 @@ func (r *DNSRecordReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
163163
Content: dnsrecord.Spec.Content,
164164
})
165165
if err != nil {
166-
if err := r.markFailed(dnsrecord, ctx, err.Error()); err != nil {
166+
if err := r.markFailed(ctx, dnsrecord, err.Error()); err != nil {
167167
log.Error(err, "Failed to update DNSRecord status")
168168
return ctrl.Result{}, err
169169
}
@@ -178,7 +178,7 @@ func (r *DNSRecordReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
178178
if (dnsrecord.Spec.Type == "A" || dnsrecord.Spec.Type == "AAAA") && dnsrecord.Spec.IPRef.Name != "" {
179179
ip := &cloudflareoperatoriov1.IP{}
180180
if err := r.Get(ctx, client.ObjectKey{Name: dnsrecord.Spec.IPRef.Name}, ip); err != nil {
181-
if err := r.markFailed(dnsrecord, ctx, "IP object not found"); err != nil {
181+
if err := r.markFailed(ctx, dnsrecord, "IP object not found"); err != nil {
182182
log.Error(err, "Failed to update DNSRecord status")
183183
return ctrl.Result{}, err
184184
}
@@ -194,7 +194,7 @@ func (r *DNSRecordReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
194194
}
195195

196196
if *dnsrecord.Spec.Proxied && dnsrecord.Spec.TTL != 1 {
197-
if err := r.markFailed(dnsrecord, ctx, "TTL must be 1 when proxied"); err != nil {
197+
if err := r.markFailed(ctx, dnsrecord, "TTL must be 1 when proxied"); err != nil {
198198
log.Error(err, "Failed to update DNSRecord status")
199199
return ctrl.Result{}, err
200200
}
@@ -212,7 +212,7 @@ func (r *DNSRecordReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
212212
Data: dnsrecord.Spec.Data,
213213
})
214214
if err != nil {
215-
if err := r.markFailed(dnsrecord, ctx, err.Error()); err != nil {
215+
if err := r.markFailed(ctx, dnsrecord, err.Error()); err != nil {
216216
log.Error(err, "Failed to update DNSRecord status")
217217
return ctrl.Result{}, err
218218
}
@@ -244,7 +244,7 @@ func (r *DNSRecordReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
244244
Priority: dnsrecord.Spec.Priority,
245245
Data: dnsrecord.Spec.Data,
246246
}); err != nil {
247-
if err := r.markFailed(dnsrecord, ctx, err.Error()); err != nil {
247+
if err := r.markFailed(ctx, dnsrecord, err.Error()); err != nil {
248248
log.Error(err, "Failed to update DNSRecord status")
249249
return ctrl.Result{}, err
250250
}
@@ -293,7 +293,7 @@ func (r *DNSRecordReconciler) finalizeDNSRecord(ctx context.Context, dnsRecordZo
293293
}
294294

295295
// markFailed marks the reconciled object as failed
296-
func (r *DNSRecordReconciler) markFailed(dnsrecord *cloudflareoperatoriov1.DNSRecord, ctx context.Context, message string) error {
296+
func (r *DNSRecordReconciler) markFailed(ctx context.Context, dnsrecord *cloudflareoperatoriov1.DNSRecord, message string) error {
297297
metrics.DnsRecordFailureCounter.WithLabelValues(dnsrecord.Namespace, dnsrecord.Name, dnsrecord.Spec.Name).Set(1)
298298
apimeta.SetStatusCondition(&dnsrecord.Status.Conditions, metav1.Condition{
299299
Type: "Ready",

internal/controller/ip_controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ func (r *IPReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Re
9797

9898
if ip.Spec.Type == "static" {
9999
if ip.Spec.Address == "" {
100-
if err := r.markFailed(ip, ctx, "Address is required for static IPs"); err != nil {
100+
if err := r.markFailed(ctx, ip, "Address is required for static IPs"); err != nil {
101101
log.Error(err, "Failed to update IP resource")
102102
return ctrl.Result{}, err
103103
}
104104
return ctrl.Result{}, nil
105105
}
106106
if net.ParseIP(ip.Spec.Address) == nil {
107-
if err := r.markFailed(ip, ctx, "Address is not a valid IP address"); err != nil {
107+
if err := r.markFailed(ctx, ip, "Address is not a valid IP address"); err != nil {
108108
log.Error(err, "Failed to update IP resource")
109109
return ctrl.Result{}, err
110110
}
@@ -122,7 +122,7 @@ func (r *IPReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Re
122122
}
123123

124124
if len(ip.Spec.IPSources) == 0 {
125-
if err := r.markFailed(ip, ctx, "IPSources is required for dynamic IPs"); err != nil {
125+
if err := r.markFailed(ctx, ip, "IPSources is required for dynamic IPs"); err != nil {
126126
log.Error(err, "Failed to update IP resource")
127127
return ctrl.Result{}, err
128128
}
@@ -148,7 +148,7 @@ func (r *IPReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Re
148148
}
149149

150150
if ipSourceError != "" {
151-
if err := r.markFailed(ip, ctx, ipSourceError); err != nil {
151+
if err := r.markFailed(ctx, ip, ipSourceError); err != nil {
152152
log.Error(err, "Failed to update IP resource")
153153
return ctrl.Result{}, err
154154
}
@@ -308,7 +308,7 @@ func (r *IPReconciler) getIPSource(ctx context.Context, source cloudflareoperato
308308
}
309309

310310
// markFailed marks the reconciled object as failed
311-
func (r *IPReconciler) markFailed(ip *cloudflareoperatoriov1.IP, ctx context.Context, message string) error {
311+
func (r *IPReconciler) markFailed(ctx context.Context, ip *cloudflareoperatoriov1.IP, message string) error {
312312
metrics.IpFailureCounter.WithLabelValues(ip.Name, ip.Spec.Type).Set(1)
313313
apimeta.SetStatusCondition(&ip.Status.Conditions, metav1.Condition{
314314
Type: "Ready",

internal/controller/zone_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (r *ZoneReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
102102

103103
zoneID, err := r.Cf.ZoneIDByName(zone.Spec.Name)
104104
if err != nil {
105-
if err := r.markFailed(zone, ctx, err.Error()); err != nil {
105+
if err := r.markFailed(ctx, zone, err.Error()); err != nil {
106106
log.Error(err, "Failed to update Zone status")
107107
return ctrl.Result{}, err
108108
}
@@ -126,7 +126,7 @@ func (r *ZoneReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
126126

127127
cfDnsRecords, _, err := r.Cf.ListDNSRecords(ctx, cloudflare.ZoneIdentifier(zone.Status.ID), cloudflare.ListDNSRecordsParams{})
128128
if err != nil {
129-
if err := r.markFailed(zone, ctx, err.Error()); err != nil {
129+
if err := r.markFailed(ctx, zone, err.Error()); err != nil {
130130
log.Error(err, "Failed to update Zone status")
131131
return ctrl.Result{}, err
132132
}
@@ -145,7 +145,7 @@ func (r *ZoneReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
145145

146146
if _, found := dnsRecordMap[cfDnsRecord.ID]; !found {
147147
if err := r.Cf.DeleteDNSRecord(ctx, cloudflare.ZoneIdentifier(zone.Status.ID), cfDnsRecord.ID); err != nil {
148-
if err := r.markFailed(zone, ctx, err.Error()); err != nil {
148+
if err := r.markFailed(ctx, zone, err.Error()); err != nil {
149149
log.Error(err, "Failed to update Zone status")
150150
}
151151
}
@@ -170,7 +170,7 @@ func (r *ZoneReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
170170
}
171171

172172
// markFailed marks the reconciled object as failed
173-
func (r *ZoneReconciler) markFailed(zone *cloudflareoperatoriov1.Zone, ctx context.Context, message string) error {
173+
func (r *ZoneReconciler) markFailed(ctx context.Context, zone *cloudflareoperatoriov1.Zone, message string) error {
174174
metrics.ZoneFailureCounter.WithLabelValues(zone.Name, zone.Spec.Name).Set(1)
175175
apimeta.SetStatusCondition(&zone.Status.Conditions, metav1.Condition{
176176
Type: "Ready",

0 commit comments

Comments
 (0)