Skip to content

Commit

Permalink
Speedup deploy when building a new context
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro authored and lburgazzoli committed Sep 18, 2018
1 parent 0f9503d commit 1a40993
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
2 changes: 0 additions & 2 deletions pkg/apis/camel/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ const (

// IntegrationContextPhaseBuilding --
IntegrationContextPhaseBuilding IntegrationContextPhase = "Building"
// IntegrationContextPhaseDeploying --
IntegrationContextPhaseDeploying IntegrationContextPhase = "Deploying"
// IntegrationContextPhaseReady --
IntegrationContextPhaseReady IntegrationContextPhase = "Ready"
// IntegrationContextPhaseError --
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/camel/v1alpha1/types_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ func (spec ConfigurationSpec) String() string {
//
// **********************************

// NewIntegrationList --
func NewIntegrationList() IntegrationList {
return IntegrationList{
TypeMeta: metav1.TypeMeta{
APIVersion: SchemeGroupVersion.String(),
Kind: IntegrationKind,
},
}
}

// NewIntegrationContext --
func NewIntegrationContext(namespace string, name string) IntegrationContext {
return IntegrationContext{
Expand Down
33 changes: 32 additions & 1 deletion pkg/stub/action/context/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package action

import (
"context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/operator-framework/operator-sdk/pkg/sdk"
"github.com/sirupsen/logrus"
Expand All @@ -29,6 +30,7 @@ import (
"github.com/apache/camel-k/pkg/build"
)

// NewIntegrationContextBuildAction creates a new build handling action for the context
func NewIntegrationContextBuildAction(ctx context.Context, namespace string) IntegrationContextAction {
return &integrationContextBuildAction{
buildManager: build.NewManager(ctx, namespace),
Expand Down Expand Up @@ -68,8 +70,37 @@ func (action *integrationContextBuildAction) Handle(context *v1alpha1.Integratio
target := context.DeepCopy()
target.Status.Image = buildResult.Image
target.Status.Phase = v1alpha1.IntegrationContextPhaseReady
return sdk.Update(target)
if err := sdk.Update(target); err != nil {
return err
}
if err := action.informIntegrations(target); err != nil {
return err
}
}

return nil
}

// informIntegrations triggers the processing of all integrations waiting for this context to be built
func (action *integrationContextBuildAction) informIntegrations(context *v1alpha1.IntegrationContext) error {
list := v1alpha1.NewIntegrationList()
err := sdk.List(context.Namespace, &list, sdk.WithListOptions(&metav1.ListOptions{}))
if err != nil {
return err
}
for _, integration := range list.Items {
if integration.Spec.Context != context.Name {
continue
}

if integration.Annotations == nil {
integration.Annotations = make(map[string]string)
}
integration.Annotations["camel.apache.org/context.digest"] = context.Status.Digest
err = sdk.Update(&integration)
if err != nil {
return err
}
}
return nil
}
3 changes: 3 additions & 0 deletions pkg/stub/action/integration/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ func getDeploymentFor(ctx *v1alpha1.IntegrationContext, integration *v1alpha1.In
// has been changed
environment["CAMEL_K_DIGEST"] = integration.Status.Digest

// optimizations
environment["AB_JOLOKIA_OFF"] = "true"

labels := map[string]string{
"camel.apache.org/integration": integration.Name,
}
Expand Down

0 comments on commit 1a40993

Please sign in to comment.