You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/02/20 11:40:04 UTC

[camel-k] branch master updated: Add a phase to wake up integration reconcile loop on context build completion

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 4fb84e5  Add a phase to wake up integration reconcile loop on context build completion
4fb84e5 is described below

commit 4fb84e5e406781471f37d23676e52d419d3381e4
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Wed Feb 20 11:17:31 2019 +0100

    Add a phase to wake up integration reconcile loop on context build completion
    
    Fixes #460
---
 pkg/apis/camel/v1alpha1/integration_types.go |  2 ++
 pkg/controller/integration/build_context.go  |  3 ++-
 pkg/controller/integrationcontext/build.go   | 19 ++++++-----------
 pkg/trait/deployment.go                      | 31 ++++++++++++++--------------
 4 files changed, 25 insertions(+), 30 deletions(-)

diff --git a/pkg/apis/camel/v1alpha1/integration_types.go b/pkg/apis/camel/v1alpha1/integration_types.go
index 75f9726..e3dee63 100644
--- a/pkg/apis/camel/v1alpha1/integration_types.go
+++ b/pkg/apis/camel/v1alpha1/integration_types.go
@@ -132,6 +132,8 @@ const (
 	IntegrationPhaseWaitingForPlatform IntegrationPhase = "Waiting For Platform"
 	// IntegrationPhaseBuildingContext --
 	IntegrationPhaseBuildingContext IntegrationPhase = "Building Context"
+	// IntegrationPhaseResolvingContext --
+	IntegrationPhaseResolvingContext IntegrationPhase = "Resolving Context"
 	// IntegrationPhaseBuildImageSubmitted --
 	IntegrationPhaseBuildImageSubmitted IntegrationPhase = "Build Image Submitted"
 	// IntegrationPhaseBuildImageRunning --
diff --git a/pkg/controller/integration/build_context.go b/pkg/controller/integration/build_context.go
index e4d3061..2c03f24 100644
--- a/pkg/controller/integration/build_context.go
+++ b/pkg/controller/integration/build_context.go
@@ -42,7 +42,8 @@ func (action *buildContextAction) Name() string {
 }
 
 func (action *buildContextAction) CanHandle(integration *v1alpha1.Integration) bool {
-	return integration.Status.Phase == v1alpha1.IntegrationPhaseBuildingContext
+	return integration.Status.Phase == v1alpha1.IntegrationPhaseBuildingContext ||
+		integration.Status.Phase == v1alpha1.IntegrationPhaseResolvingContext
 }
 
 func (action *buildContextAction) Handle(ctx context.Context, integration *v1alpha1.Integration) error {
diff --git a/pkg/controller/integrationcontext/build.go b/pkg/controller/integrationcontext/build.go
index fd90163..8dad883 100644
--- a/pkg/controller/integrationcontext/build.go
+++ b/pkg/controller/integrationcontext/build.go
@@ -22,19 +22,16 @@ import (
 	"errors"
 	"fmt"
 
-	"github.com/apache/camel-k/pkg/util/cancellable"
-
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 
-	"github.com/apache/camel-k/pkg/util/kubernetes"
-
-	"github.com/apache/camel-k/pkg/trait"
+	k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
 
 	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
 	"github.com/apache/camel-k/pkg/builder"
 	"github.com/apache/camel-k/pkg/platform"
-
-	k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
+	"github.com/apache/camel-k/pkg/trait"
+	"github.com/apache/camel-k/pkg/util/cancellable"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
 )
 
 // NewBuildAction creates a new build request handling action for the context
@@ -245,12 +242,8 @@ func (action *buildAction) informIntegrations(ctx context.Context, ictx *v1alpha
 		if integration.Status.Context != ictx.Name {
 			continue
 		}
-
-		if integration.Annotations == nil {
-			integration.Annotations = make(map[string]string)
-		}
-		integration.Annotations["camel.apache.org/context.digest"] = ictx.Status.Digest
-		err = action.client.Update(ctx, &integration)
+		integration.Status.Phase = v1alpha1.IntegrationPhaseResolvingContext
+		err = action.client.Status().Update(ctx, &integration)
 		if err != nil {
 			return err
 		}
diff --git a/pkg/trait/deployment.go b/pkg/trait/deployment.go
index 6551e33..f91d002 100644
--- a/pkg/trait/deployment.go
+++ b/pkg/trait/deployment.go
@@ -23,11 +23,10 @@ import (
 	"strconv"
 	"strings"
 
-	"github.com/apache/camel-k/pkg/util/kubernetes"
-
+	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
 	"github.com/apache/camel-k/pkg/util/envvar"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
 
-	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
 	appsv1 "k8s.io/api/apps/v1"
 	corev1 "k8s.io/api/core/v1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -62,11 +61,9 @@ func (t *deploymentTrait) Configure(e *Environment) (bool, error) {
 		return strategy == ControllerStrategyDeployment, nil
 	}
 
-	if t.ContainerImage && e.InPhase(v1alpha1.IntegrationContextPhaseReady, v1alpha1.IntegrationPhaseBuildingContext) {
-		return true, nil
-	}
-
-	if !t.ContainerImage && e.InPhase(v1alpha1.IntegrationContextPhaseReady, v1alpha1.IntegrationPhaseBuildingContext) {
+	if e.IntegrationContextInPhase(v1alpha1.IntegrationContextPhaseReady) &&
+		(e.IntegrationInPhase(v1alpha1.IntegrationPhaseBuildingContext) ||
+			e.IntegrationInPhase(v1alpha1.IntegrationPhaseResolvingContext)) {
 		return true, nil
 	}
 
@@ -74,14 +71,16 @@ func (t *deploymentTrait) Configure(e *Environment) (bool, error) {
 }
 
 func (t *deploymentTrait) Apply(e *Environment) error {
-	if t.ContainerImage && e.InPhase(v1alpha1.IntegrationContextPhaseReady, v1alpha1.IntegrationPhaseBuildingContext) {
-		// trigger container image build
-		e.Integration.Status.Phase = v1alpha1.IntegrationPhaseBuildImageSubmitted
-	}
-
-	if !t.ContainerImage && e.InPhase(v1alpha1.IntegrationContextPhaseReady, v1alpha1.IntegrationPhaseBuildingContext) {
-		// trigger integration deploy
-		e.Integration.Status.Phase = v1alpha1.IntegrationPhaseDeploying
+	if e.IntegrationContextInPhase(v1alpha1.IntegrationContextPhaseReady) &&
+		(e.IntegrationInPhase(v1alpha1.IntegrationPhaseBuildingContext) ||
+			e.IntegrationInPhase(v1alpha1.IntegrationPhaseResolvingContext)) {
+		if t.ContainerImage {
+			// trigger container image build
+			e.Integration.Status.Phase = v1alpha1.IntegrationPhaseBuildImageSubmitted
+		} else {
+			// trigger integration deploy
+			e.Integration.Status.Phase = v1alpha1.IntegrationPhaseDeploying
+		}
 	}
 
 	if e.Integration != nil && e.Integration.Status.Phase == v1alpha1.IntegrationPhaseDeploying {