Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit 06b4194

Browse files
committed
Ignore but requeue conflict errors
1 parent 1525189 commit 06b4194

4 files changed

Lines changed: 26 additions & 4 deletions

File tree

internal/controller/client_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ type ClientReconciler struct {
4545
// For more details, check Reconcile and its Result here:
4646
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.18.2/pkg/reconcile
4747
func (r *ClientReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
48+
logger := log.FromContext(ctx).WithValues("client", req.NamespacedName)
49+
4850
var client jumpstarterdevv1alpha1.Client
4951
if err := r.Get(ctx, req.NamespacedName, &client); err != nil {
5052
return ctrl.Result{}, kclient.IgnoreNotFound(
@@ -63,7 +65,7 @@ func (r *ClientReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
6365
}
6466

6567
if err := r.Status().Patch(ctx, &client, original); err != nil {
66-
return ctrl.Result{}, err
68+
return RequeueConflict(logger, ctrl.Result{}, err)
6769
}
6870

6971
return ctrl.Result{}, nil

internal/controller/errors.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package controller
2+
3+
import (
4+
"github.com/go-logr/logr"
5+
apierrors "k8s.io/apimachinery/pkg/api/errors"
6+
ctrl "sigs.k8s.io/controller-runtime"
7+
)
8+
9+
func RequeueConflict(logger logr.Logger, result ctrl.Result, err error) (ctrl.Result, error) {
10+
if apierrors.IsConflict(err) {
11+
logger.V(1).Info("Ignoring conflict error but requeuing the reconcilation request", "error", err)
12+
return ctrl.Result{Requeue: true}, nil
13+
} else {
14+
return result, err
15+
}
16+
}

internal/controller/exporter_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ type ExporterReconciler struct {
5252
// For more details, check Reconcile and its Result here:
5353
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.18.2/pkg/reconcile
5454
func (r *ExporterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
55+
logger := log.FromContext(ctx).WithValues("exporter", req.NamespacedName)
56+
5557
var exporter jumpstarterdevv1alpha1.Exporter
5658
if err := r.Get(ctx, req.NamespacedName, &exporter); err != nil {
5759
return ctrl.Result{}, client.IgnoreNotFound(
@@ -74,7 +76,7 @@ func (r *ExporterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
7476
}
7577

7678
if err := r.Status().Patch(ctx, &exporter, original); err != nil {
77-
return ctrl.Result{}, err
79+
return RequeueConflict(logger, ctrl.Result{}, err)
7880
}
7981

8082
return ctrl.Result{}, nil

internal/controller/lease_controller.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ type LeaseReconciler struct {
5454
// For more details, check Reconcile and its Result here:
5555
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.18.4/pkg/reconcile
5656
func (r *LeaseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
57+
logger := log.FromContext(ctx).WithValues("lease", req.NamespacedName)
58+
5759
var lease jumpstarterdevv1alpha1.Lease
5860
if err := r.Get(ctx, req.NamespacedName, &lease); err != nil {
5961
return ctrl.Result{}, client.IgnoreNotFound(
@@ -75,7 +77,7 @@ func (r *LeaseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
7577
}
7678

7779
if err := r.Status().Update(ctx, &lease); err != nil {
78-
return result, err
80+
return RequeueConflict(logger, result, err)
7981
}
8082

8183
if lease.Labels == nil {
@@ -99,7 +101,7 @@ func (r *LeaseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
99101
}
100102

101103
if err := r.Update(ctx, &lease); err != nil {
102-
return result, fmt.Errorf("Reconcile: failed to update lease metadata: %w", err)
104+
return RequeueConflict(logger, result, fmt.Errorf("Reconcile: failed to update lease metadata: %w", err))
103105
}
104106

105107
return result, nil

0 commit comments

Comments
 (0)