This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 44230462e749c3063910202987ab4b61447c09c6
Author: lburgazzoli <lburgazz...@gmail.com>
AuthorDate: Thu Jul 4 11:47:00 2019 +0200

    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 +-
 pkg/apis/camel/v1alpha1/integrationkit_types.go    |  2 +-
 pkg/controller/build/build_controller.go           | 35 ++++++++++----------
 .../integration/integration_controller.go          | 36 ++++++++++-----------
 .../integrationkit/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 b70ffd0..8f8e90a 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 86ab6f3..a3b211f 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 a00cc86..3a9b770 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 b88d0cb..3d6dac6 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 2bdfb96..ef1defc 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 ff401d5..fe14bc0 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
 }

Reply via email to