From 44230462e749c3063910202987ab4b61447c09c6 Mon Sep 17 00:00:00 2001 From: lburgazzoli Date: Thu, 4 Jul 2019 11:47:00 +0200 Subject: [PATCH] Move waiting for platform to controller #797 (fix PR review) --- pkg/apis/camel/v1alpha1/build_types.go | 2 +- pkg/apis/camel/v1alpha1/integration_types.go | 2 +- .../camel/v1alpha1/integrationkit_types.go | 2 +- pkg/controller/build/build_controller.go | 35 +++++++++--------- .../integration/integration_controller.go | 36 +++++++++--------- .../integrationkit_controller.go | 37 +++++++++---------- 6 files changed, 55 insertions(+), 59 deletions(-) diff --git a/pkg/apis/camel/v1alpha1/build_types.go b/pkg/apis/camel/v1alpha1/build_types.go index b70ffd0f3e..8f8e90a397 100644 --- a/pkg/apis/camel/v1alpha1/build_types.go +++ b/pkg/apis/camel/v1alpha1/build_types.go @@ -67,7 +67,7 @@ const ( // BuildPhaseNone -- BuildPhaseNone BuildPhase = "" // BuildPhaseInitialization -- - BuildPhaseInitialization BuildPhase = "initialization" + BuildPhaseInitialization BuildPhase = "Initialization" // BuildPhaseWaitingForPlatform -- BuildPhaseWaitingForPlatform BuildPhase = "Waiting For Platform" // BuildPhaseScheduling -- diff --git a/pkg/apis/camel/v1alpha1/integration_types.go b/pkg/apis/camel/v1alpha1/integration_types.go index 86ab6f35f8..a3b211f6fa 100644 --- a/pkg/apis/camel/v1alpha1/integration_types.go +++ b/pkg/apis/camel/v1alpha1/integration_types.go @@ -145,7 +145,7 @@ const ( // IntegrationPhaseNone -- IntegrationPhaseNone IntegrationPhase = "" // IntegrationPhaseInitialization -- - IntegrationPhaseInitialization IntegrationPhase = "initialization" + IntegrationPhaseInitialization IntegrationPhase = "Initialization" // IntegrationPhaseWaitingForPlatform -- IntegrationPhaseWaitingForPlatform IntegrationPhase = "Waiting For Platform" // IntegrationPhaseBuildingKit -- diff --git a/pkg/apis/camel/v1alpha1/integrationkit_types.go b/pkg/apis/camel/v1alpha1/integrationkit_types.go index a00cc861ec..3a9b77066e 100644 --- a/pkg/apis/camel/v1alpha1/integrationkit_types.go +++ b/pkg/apis/camel/v1alpha1/integrationkit_types.go @@ -85,7 +85,7 @@ const ( // IntegrationKitPhaseNone -- IntegrationKitPhaseNone IntegrationKitPhase = "" // IntegrationKitPhaseInitialization -- - IntegrationKitPhaseInitialization IntegrationKitPhase = "initialization" + IntegrationKitPhaseInitialization IntegrationKitPhase = "Initialization" // IntegrationKitPhaseWaitingForPlatform -- IntegrationKitPhaseWaitingForPlatform IntegrationKitPhase = "Waiting For Platform" // IntegrationKitPhaseBuildSubmitted -- diff --git a/pkg/controller/build/build_controller.go b/pkg/controller/build/build_controller.go index b88d0cb992..3d6dac634e 100644 --- a/pkg/controller/build/build_controller.go +++ b/pkg/controller/build/build_controller.go @@ -39,6 +39,7 @@ import ( "github.com/apache/camel-k/pkg/apis/camel/v1alpha1" "github.com/apache/camel-k/pkg/builder" "github.com/apache/camel-k/pkg/client" + "github.com/apache/camel-k/pkg/util/log" ) // Add creates a new Build Controller and adds it to the Manager. The Manager will set fields on the Controller @@ -178,13 +179,7 @@ func (r *ReconcileBuild) Reconcile(request reconcile.Request) (reconcile.Result, } if instance.Status.Phase != target.Status.Phase { - err = r.update(ctx, target) - if err != nil { - if k8serrors.IsConflict(err) { - targetLog.Error(err, "conflict") - err = nil - } - } + return r.update(ctx, targetLog, target) } return reconcile.Result{}, err @@ -213,15 +208,8 @@ func (r *ReconcileBuild) Reconcile(request reconcile.Request) (reconcile.Result, } if newTarget != nil { - if err := r.update(ctx, newTarget); err != nil { - if k8serrors.IsConflict(err) { - targetLog.Error(err, "conflict") - return reconcile.Result{ - Requeue: true, - }, nil - } - - return reconcile.Result{}, err + if r, err := r.update(ctx, targetLog, newTarget); err != nil { + return r, err } if newTarget.Status.Phase != target.Status.Phase { @@ -252,6 +240,17 @@ func (r *ReconcileBuild) Reconcile(request reconcile.Request) (reconcile.Result, } // Update -- -func (r *ReconcileBuild) update(ctx context.Context, target *v1alpha1.Build) error { - return r.client.Status().Update(ctx, target) +func (r *ReconcileBuild) update(ctx context.Context, log log.Logger, target *v1alpha1.Build) (reconcile.Result, error) { + err := r.client.Status().Update(ctx, target) + if err != nil { + if k8serrors.IsConflict(err) { + log.Error(err, "conflict") + + return reconcile.Result{ + Requeue: true, + }, nil + } + } + + return reconcile.Result{}, err } diff --git a/pkg/controller/integration/integration_controller.go b/pkg/controller/integration/integration_controller.go index 2bdfb96efc..ef1defc66d 100644 --- a/pkg/controller/integration/integration_controller.go +++ b/pkg/controller/integration/integration_controller.go @@ -247,13 +247,7 @@ func (r *ReconcileIntegration) Reconcile(request reconcile.Request) (reconcile.R } if instance.Status.Phase != target.Status.Phase { - err = r.update(ctx, target) - if err != nil { - if k8serrors.IsConflict(err) { - targetLog.Error(err, "conflict") - err = nil - } - } + return r.update(ctx, targetLog, target) } return reconcile.Result{}, err @@ -281,15 +275,8 @@ func (r *ReconcileIntegration) Reconcile(request reconcile.Request) (reconcile.R } if newTarget != nil { - if err := r.update(ctx, newTarget); err != nil { - if k8serrors.IsConflict(err) { - targetLog.Error(err, "conflict") - return reconcile.Result{ - Requeue: true, - }, nil - } - - return reconcile.Result{}, err + if r, err := r.update(ctx, targetLog, newTarget); err != nil { + return r, err } if newTarget.Status.Phase != target.Status.Phase { @@ -311,13 +298,24 @@ func (r *ReconcileIntegration) Reconcile(request reconcile.Request) (reconcile.R } // Update -- -func (r *ReconcileIntegration) update(ctx context.Context, target *v1alpha1.Integration) error { +func (r *ReconcileIntegration) update(ctx context.Context, log log.Logger, target *v1alpha1.Integration) (reconcile.Result, error) { dgst, err := digest.ComputeForIntegration(target) if err != nil { - return err + return reconcile.Result{}, err } target.Status.Digest = dgst - return r.client.Status().Update(ctx, target) + err = r.client.Status().Update(ctx, target) + if err != nil { + if k8serrors.IsConflict(err) { + log.Error(err, "conflict") + + return reconcile.Result{ + Requeue: true, + }, nil + } + } + + return reconcile.Result{}, err } diff --git a/pkg/controller/integrationkit/integrationkit_controller.go b/pkg/controller/integrationkit/integrationkit_controller.go index ff401d523f..fe14bc06db 100644 --- a/pkg/controller/integrationkit/integrationkit_controller.go +++ b/pkg/controller/integrationkit/integrationkit_controller.go @@ -22,6 +22,7 @@ import ( "github.com/apache/camel-k/pkg/platform" "github.com/apache/camel-k/pkg/util/digest" + "github.com/apache/camel-k/pkg/util/log" "k8s.io/apimachinery/pkg/api/errors" k8serrors "k8s.io/apimachinery/pkg/api/errors" @@ -159,13 +160,7 @@ func (r *ReconcileIntegrationKit) Reconcile(request reconcile.Request) (reconcil } if instance.Status.Phase != target.Status.Phase { - err = r.update(ctx, target) - if err != nil { - if k8serrors.IsConflict(err) { - targetLog.Error(err, "conflict") - err = nil - } - } + return r.update(ctx, targetLog, target) } return reconcile.Result{}, err @@ -191,15 +186,8 @@ func (r *ReconcileIntegrationKit) Reconcile(request reconcile.Request) (reconcil } if newTarget != nil { - if err := r.update(ctx, newTarget); err != nil { - if k8serrors.IsConflict(err) { - targetLog.Error(err, "conflict") - return reconcile.Result{ - Requeue: true, - }, nil - } - - return reconcile.Result{}, err + if r, err := r.update(ctx, targetLog, newTarget); err != nil { + return r, err } if newTarget.Status.Phase != target.Status.Phase { @@ -221,13 +209,24 @@ func (r *ReconcileIntegrationKit) Reconcile(request reconcile.Request) (reconcil } // Update -- -func (r *ReconcileIntegrationKit) update(ctx context.Context, target *v1alpha1.IntegrationKit) error { +func (r *ReconcileIntegrationKit) update(ctx context.Context, log log.Logger, target *v1alpha1.IntegrationKit) (reconcile.Result, error) { dgst, err := digest.ComputeForIntegrationKit(target) if err != nil { - return err + return reconcile.Result{}, err } target.Status.Digest = dgst - return r.client.Status().Update(ctx, target) + err = r.client.Status().Update(ctx, target) + if err != nil { + if k8serrors.IsConflict(err) { + log.Error(err, "conflict") + + return reconcile.Result{ + Requeue: true, + }, nil + } + } + + return reconcile.Result{}, err }