Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trait: add builder trait #233

Merged
merged 4 commits into from
Nov 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pkg/apis/camel/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ type IntegrationSpec struct {
Replicas *int32 `json:"replicas,omitempty"`
Source SourceSpec `json:"source,omitempty"`
Context string `json:"context,omitempty"`
Profile TraitProfile `json:"profile,omitempty"`
Dependencies []string `json:"dependencies,omitempty"`
Profile TraitProfile `json:"profile,omitempty"`
Traits map[string]IntegrationTraitSpec `json:"traits,omitempty"`
Configuration []ConfigurationSpec `json:"configuration,omitempty"`
}
Expand Down Expand Up @@ -153,8 +153,10 @@ type IntegrationContext struct {

// IntegrationContextSpec --
type IntegrationContextSpec struct {
Dependencies []string `json:"dependencies,omitempty"`
Configuration []ConfigurationSpec `json:"configuration,omitempty"`
Dependencies []string `json:"dependencies,omitempty"`
Profile TraitProfile `json:"profile,omitempty"`
Traits map[string]IntegrationTraitSpec `json:"traits,omitempty"`
Configuration []ConfigurationSpec `json:"configuration,omitempty"`
}

// IntegrationContextStatus --
Expand Down
13 changes: 13 additions & 0 deletions pkg/builder/builder_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package builder

import (
"context"
"fmt"
"time"

"github.com/apache/camel-k/pkg/util/maven"
Expand Down Expand Up @@ -56,6 +57,10 @@ type stepWrapper struct {
task func(*Context) error
}

func (s *stepWrapper) String() string {
return fmt.Sprintf("%s@%d", s.id, s.phase)
}

func (s *stepWrapper) ID() string {
return s.id
}
Expand All @@ -79,6 +84,14 @@ func NewStep(ID string, phase int, task func(*Context) error) Step {
return &s
}

// NewIdentifierForContext --
func NewIdentifierForContext(context *v1alpha1.IntegrationContext) Identifier {
return Identifier{
Name: "context-" + context.Name,
Qualifier: context.ResourceVersion,
}
}

// Identifier --
type Identifier struct {
Name string
Expand Down
73 changes: 0 additions & 73 deletions pkg/platform/build.go

This file was deleted.

17 changes: 17 additions & 0 deletions pkg/platform/get.go → pkg/platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,29 @@ limitations under the License.
package platform

import (
"context"
"errors"

"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/builder"
"github.com/operator-framework/operator-sdk/pkg/sdk"
)

// gBuilder is the current builder
// Note: it cannot be changed at runtime, needs a operator restart
var gBuilder builder.Builder

// GetPlatformBuilder --
func GetPlatformBuilder(ctx context.Context, namespace string) (builder.Builder, error) {
if gBuilder != nil {
return gBuilder, nil
}

gBuilder = builder.New(ctx, namespace)

return gBuilder, nil
}

// GetCurrentPlatform returns the currently installed platform
func GetCurrentPlatform(namespace string) (*v1alpha1.IntegrationPlatform, error) {
lst, err := ListPlatforms(namespace)
Expand Down
11 changes: 10 additions & 1 deletion pkg/stub/action/context/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package context
import (
"context"

"github.com/apache/camel-k/pkg/trait"

"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/builder"
"github.com/apache/camel-k/pkg/platform"
Expand Down Expand Up @@ -54,11 +56,18 @@ func (action *buildAction) Handle(context *v1alpha1.IntegrationContext) error {
if err != nil {
return err
}
r, err := platform.NewBuildRequest(action.Context, context)
env, err := trait.Apply(nil, context)
if err != nil {
return err
}

r := builder.Request{
Identifier: builder.NewIdentifierForContext(context),
Dependencies: context.Spec.Dependencies,
Steps: env.Steps,
Platform: env.Platform.Spec,
}

res := b.Submit(r)
if res.Status == builder.StatusSubmitted {
logrus.Info("Build submitted")
Expand Down
2 changes: 1 addition & 1 deletion pkg/stub/action/context/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (action *initializeAction) Handle(context *v1alpha1.IntegrationContext) err
target := context.DeepCopy()

// execute custom initialization
//if err := trait.Apply(nil, context); err != nil {
//if err := trait.apply(nil, context); err != nil {
// return err
//}

Expand Down
4 changes: 2 additions & 2 deletions pkg/stub/action/integration/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func (action *deployAction) CanHandle(integration *v1alpha1.Integration) bool {
}

func (action *deployAction) Handle(integration *v1alpha1.Integration) error {
resources, err := trait.Apply(integration, nil)
env, err := trait.Apply(integration, nil)
if err != nil {
return err
}
// TODO we should look for objects that are no longer present in the collection and remove them
err = kubernetes.ReplaceResources(resources)
err = kubernetes.ReplaceResources(env.Resources.Items())
if err != nil {
return err
}
Expand Down
50 changes: 50 additions & 0 deletions pkg/trait/builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package trait

import (
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/builder/kaniko"
"github.com/apache/camel-k/pkg/builder/s2i"
"github.com/apache/camel-k/pkg/platform"
)

// TODO: we should add a way to label a trait as platform so it cannot be disabled/removed
type builderTrait struct {
BaseTrait `property:",squash"`
}

func newBuilderTrait() *builderTrait {
return &builderTrait{
BaseTrait: newBaseTrait("builder"),
}
}

func (*builderTrait) appliesTo(e *Environment) bool {
return e.Context != nil && e.Context.Status.Phase == v1alpha1.IntegrationContextPhaseBuilding
}

func (*builderTrait) apply(e *Environment) error {
if platform.SupportsS2iPublishStrategy(e.Platform) {
e.Steps = s2i.DefaultSteps
} else if platform.SupportsKanikoPublishStrategy(e.Platform) {
e.Steps = kaniko.DefaultSteps
}

return nil
}
Loading