Skip to content

Commit 3ac013d

Browse files
authored
Merge pull request #498 from sttts/sttts-conflict-errors
2 parents 7e4097d + c1ae379 commit 3ac013d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pkg/reconciler/managed/reconciler.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"strings"
2222
"time"
2323

24+
kerrors "k8s.io/apimachinery/pkg/api/errors"
2425
"k8s.io/apimachinery/pkg/runtime/schema"
2526
"k8s.io/apimachinery/pkg/util/sets"
2627
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -685,11 +686,23 @@ func NewReconciler(m manager.Manager, of resource.ManagedKind, o ...ReconcilerOp
685686
}
686687

687688
// Reconcile a managed resource with an external resource.
688-
func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) { //nolint:gocyclo // See note below.
689+
func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (result reconcile.Result, err error) { //nolint:gocyclo // See note below.
689690
// NOTE(negz): This method is a well over our cyclomatic complexity goal.
690691
// Be wary of adding additional complexity.
691692

692693
log := r.log.WithValues("request", req)
694+
695+
defer func() {
696+
if kerrors.IsConflict(errors.Cause(err)) {
697+
// conflict errors are transient in Kubernetes and completely normal.
698+
// The right reaction is to requeue, but not record the object as error'ing
699+
// or creating events.
700+
log.Debug("Transient conflict error", "error", err)
701+
result.Requeue = true
702+
err = nil
703+
}
704+
}()
705+
693706
log.Debug("Reconciling")
694707

695708
ctx, cancel := context.WithTimeout(ctx, r.timeout+reconcileGracePeriod)

0 commit comments

Comments
 (0)