From 63dcbb195a79e6cc0051a4474dca8af8b63d1cb1 Mon Sep 17 00:00:00 2001 From: Antonin Stefanutti Date: Wed, 9 Oct 2019 17:50:15 +0200 Subject: [PATCH] fix: Handle traits update conflicts gracefully --- .../integration/integration_controller.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/controller/integration/integration_controller.go b/pkg/controller/integration/integration_controller.go index a8c7935198..33ecdb2cb3 100644 --- a/pkg/controller/integration/integration_controller.go +++ b/pkg/controller/integration/integration_controller.go @@ -19,8 +19,9 @@ package integration import ( "context" + "github.com/pkg/errors" + appsv1 "k8s.io/api/apps/v1" - "k8s.io/apimachinery/pkg/api/errors" k8serrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" @@ -215,7 +216,7 @@ func (r *ReconcileIntegration) Reconcile(request reconcile.Request) (reconcile.R var instance v1alpha1.Integration if err := r.client.Get(ctx, request.NamespacedName, &instance); err != nil { - if errors.IsNotFound(err) { + if k8serrors.IsNotFound(err) { // Request object not found, could have been deleted after reconcile request. // Owned objects are automatically garbage collected. For additional cleanup logic use finalizers. // Return and don't requeue @@ -268,6 +269,16 @@ func (r *ReconcileIntegration) Reconcile(request reconcile.Request) (reconcile.R newTarget, err := a.Handle(ctx, target) if err != nil { + // Some traits, like the deployment and knative service ones, + // update owned resources in the running phase, so it's better + // handling update conflicts gracefully, consistently with the + // primary integration update requests. + if cause := errors.Cause(err); k8serrors.IsConflict(cause) { + log.Error(cause, "conflict") + return reconcile.Result{ + Requeue: true, + }, nil + } return reconcile.Result{}, err }