Skip to content

Commit

Permalink
Add a state to integrations waiting for platform to be ready #136
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli authored and nicolaferraro committed Jan 16, 2019
1 parent 3f32342 commit 0087d1b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
4 changes: 4 additions & 0 deletions pkg/apis/camel/v1alpha1/integration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ const (
// IntegrationKind --
IntegrationKind string = "Integration"

// IntegrationPhaseInitial --
IntegrationPhaseInitial IntegrationPhase = ""
// IntegrationPhaseWaitingForPlatform --
IntegrationPhaseWaitingForPlatform IntegrationPhase = "Waiting For Platform"
// IntegrationPhaseBuildingContext --
IntegrationPhaseBuildingContext IntegrationPhase = "Building Context"
// IntegrationPhaseBuildingImage --
Expand Down
42 changes: 33 additions & 9 deletions pkg/controller/integration/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0087d1b

Please sign in to comment.