reconciler/managed: simplify conflict suppression with helper
Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@upbound.io>
This commit is contained in:
		
							parent
							
								
									712d0dbc69
								
							
						
					
					
						commit
						8333c5c0bd
					
				| 
						 | 
				
			
			@ -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
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue