reconciler/managed: simplify conflict suppression with helper

Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@upbound.io>
This commit is contained in:
Dr. Stefan Schimanski 2023-09-26 16:20:56 +02:00
parent 712d0dbc69
commit 8333c5c0bd
No known key found for this signature in database
GPG Key ID: 4C68E0F19F95EC33
2 changed files with 17 additions and 15 deletions

View File

@ -1,5 +1,18 @@
// Copyright 2023 Upbound Inc.
// All rights reserved
/*
Copyright 2023 The Crossplane Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package errors

View File

@ -22,7 +22,6 @@ import (
"strings"
"time"
kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/controller-runtime/pkg/client"
@ -714,19 +713,9 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (resu
// NOTE(negz): This method is a well over our cyclomatic complexity goal.
// Be wary of adding additional complexity.
defer func() { result, err = errors.SilentlyRequeueOnConflict(result, err) }()
log := r.log.WithValues("request", req)
defer func() {
if kerrors.IsConflict(errors.Cause(err)) {
// conflict errors are transient in Kubernetes and completely normal.
// The right reaction is to requeue, but not record the object as error'ing
// or creating events.
log.Debug("Transient conflict error", "error", err)
result.Requeue = true
err = nil
}
}()
log.Debug("Reconciling")
ctx, cancel := context.WithTimeout(ctx, r.timeout+reconcileGracePeriod)