You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2019/01/16 14:05:41 UTC

[camel-k] branch master updated: Add a state to integrations waiting for platform to be ready #136

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

nferraro 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 0087d1b  Add a state to integrations waiting for platform to be ready #136
0087d1b is described below

commit 0087d1bfac12798d6238821e2fb38e0765c8190a
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Wed Jan 16 14:40:25 2019 +0100

    Add a state to integrations waiting for platform to be ready #136
---
 pkg/apis/camel/v1alpha1/integration_types.go |  4 +++
 pkg/controller/integration/initialize.go     | 42 ++++++++++++++++++++++------
 2 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/pkg/apis/camel/v1alpha1/integration_types.go b/pkg/apis/camel/v1alpha1/integration_types.go
index a84d2fc..6a4f51b 100644
--- a/pkg/apis/camel/v1alpha1/integration_types.go
+++ b/pkg/apis/camel/v1alpha1/integration_types.go
@@ -123,6 +123,10 @@ const (
 	// IntegrationKind --
 	IntegrationKind string = "Integration"
 
+	// IntegrationPhaseInitial --
+	IntegrationPhaseInitial IntegrationPhase = ""
+	// IntegrationPhaseWaitingForPlatform --
+	IntegrationPhaseWaitingForPlatform IntegrationPhase = "Waiting For Platform"
 	// IntegrationPhaseBuildingContext --
 	IntegrationPhaseBuildingContext IntegrationPhase = "Building Context"
 	// IntegrationPhaseBuildingImage --
diff --git a/pkg/controller/integration/initialize.go b/pkg/controller/integration/initialize.go
index aa824af..642addb 100644
--- a/pkg/controller/integration/initialize.go
+++ b/pkg/controller/integration/initialize.go
@@ -43,32 +43,56 @@ func (action *initializeAction) Name() string {
 
 // CanHandle tells whether this action can handle the integration
 func (action *initializeAction) CanHandle(integration *v1alpha1.Integration) bool {
-	return integration.Status.Phase == ""
+	return integration.Status.Phase == v1alpha1.IntegrationPhaseInitial || integration.Status.Phase == v1alpha1.IntegrationPhaseWaitingForPlatform
 }
 
 // Handle handles the integrations
 func (action *initializeAction) Handle(ctx context.Context, integration *v1alpha1.Integration) error {
+	pl, err := platform.GetCurrentPlatform(ctx, action.client, integration.Namespace)
+
 	// The integration platform needs to be ready before starting to create integrations
-	if pl, err := platform.GetCurrentPlatform(ctx, action.client, integration.Namespace); err != nil || pl.Status.Phase != v1alpha1.IntegrationPlatformPhaseReady {
+	if err != nil || pl.Status.Phase != v1alpha1.IntegrationPlatformPhaseReady {
 		logrus.Info("Waiting for a integration platform to be ready")
+
+		if integration.Status.Phase != v1alpha1.IntegrationPhaseWaitingForPlatform {
+			target := integration.DeepCopy()
+			target.Status.Phase = v1alpha1.IntegrationPhaseWaitingForPlatform
+
+			logrus.Info("Integration ", target.Name, " transitioning to state ", target.Status.Phase)
+
+			return action.client.Update(ctx, target)
+		}
+
 		return nil
 	}
 
-	target := integration.DeepCopy()
+	dgst, err := digest.ComputeForIntegration(integration)
+	if err != nil {
+		return err
+	}
+
+	//
+	// restore phase to initial phase ase traits are not aware of
+	// WaitingForPlatform phase
+	//
+	if integration.Status.Phase == v1alpha1.IntegrationPhaseWaitingForPlatform {
+		target := integration.DeepCopy()
+		target.Status.Phase = v1alpha1.IntegrationPhaseInitial
+		target.Status.Digest = dgst
+
+		return action.client.Update(ctx, target)
+	}
+
 	// better not changing the spec section of the target because it may be used for comparison by a
 	// higher level controller (e.g. Knative source controller)
 
+	target := integration.DeepCopy()
+
 	// execute custom initialization
 	if _, err := trait.Apply(ctx, action.client, target, nil); err != nil {
 		return err
 	}
 
-	// update the status
-	dgst, err := digest.ComputeForIntegration(integration)
-	if err != nil {
-		return err
-	}
-
 	target.Status.Phase = v1alpha1.IntegrationPhaseBuildingContext
 	target.Status.Digest = dgst
 	target.Status.Context = integration.Spec.Context