Skip to content

Commit

Permalink
Allow buildless direct deploy #31
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Sep 13, 2018
1 parent 51294e5 commit 50d03fd
Show file tree
Hide file tree
Showing 24 changed files with 417 additions and 256 deletions.
5 changes: 5 additions & 0 deletions deploy/resources.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/apis/camel/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Integration{},
&IntegrationList{},
&IntegrationContext{},
&IntegrationContextList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
Expand Down
45 changes: 41 additions & 4 deletions pkg/apis/camel/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ limitations under the License.
package v1alpha1

import (
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -93,25 +95,60 @@ type PropertySpec struct {
Name string
Value string
}

func (spec PropertySpec) String() string {
return fmt.Sprint("%s=%s", spec.Name, spec.Value)
}

type EnvironmentSpec struct {
Name string
Value string
}

func (spec EnvironmentSpec) String() string {
return fmt.Sprint("%s=%s", spec.Name, spec.Value)
}

type IntegrationContextStatus struct {
Phase IntegrationContextPhase `json:"phase,omitempty"`
Digest string `json:"digest,omitempty"`
Image string `json:"image,omitempty"`
From int `json:"from,omitempty"`
Digest string `json:"digest,omitempty"`
}

type IntegrationContextPhase string

const (
// IntegrationContextPhaseDraft --
IntegrationContextPhaseDraft IntegrationContextPhase = "Draft"
// IntegrationContextKind --
IntegrationContextKind string = "IntegrationContext"

// IntegrationContextPhaseBuilding --
IntegrationContextPhaseBuilding IntegrationContextPhase = "Building"
// IntegrationContextPhaseDeploying --
IntegrationContextPhaseDeploying IntegrationContextPhase = "Deploying"
// IntegrationContextPhaseReady --
IntegrationContextPhaseReady IntegrationContextPhase = "Ready"
// IntegrationContextPhaseError --
IntegrationContextPhaseError IntegrationContextPhase = "Error"
)

func NewIntegrationContext(namespace string, name string) IntegrationContext {
return IntegrationContext{
TypeMeta: metav1.TypeMeta{
APIVersion: SchemeGroupVersion.String(),
Kind: IntegrationContextKind,
},
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
},
}
}

func NewIntegrationContextList() IntegrationContextList {
return IntegrationContextList{
TypeMeta: metav1.TypeMeta{
APIVersion: SchemeGroupVersion.String(),
Kind: IntegrationContextKind,
},
}
}
4 changes: 2 additions & 2 deletions pkg/build/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ type BuildSource struct {
}

type BuildIdentifier struct {
Name string
Digest string
Name string
Qualifier string
}

type Code struct {
Expand Down
34 changes: 12 additions & 22 deletions pkg/build/build_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,40 @@ package build

import (
"context"
"sync"

"github.com/apache/camel-k/pkg/build/api"
"github.com/apache/camel-k/pkg/build/local"
"sync"
)

// main facade to the image build system
type BuildManager struct {
builds map[api.BuildIdentifier]*api.BuildResult
mutex sync.Mutex
type Manager struct {
builds sync.Map
builder api.Builder
}

func NewBuildManager(ctx context.Context, namespace string) *BuildManager {
return &BuildManager{
builds: make(map[api.BuildIdentifier]*api.BuildResult),
func NewManager(ctx context.Context, namespace string) *Manager {
return &Manager{
builder: local.NewLocalBuilder(ctx, namespace),
}
}

func (m *BuildManager) Get(identifier api.BuildIdentifier) api.BuildResult {
m.mutex.Lock()
defer m.mutex.Unlock()

if info, present := m.builds[identifier]; !present || info == nil {
func (m *Manager) Get(identifier api.BuildIdentifier) api.BuildResult {
if info, present := m.builds.Load(identifier); !present || info == nil {
return noBuildInfo()
} else {
return *info
return *info.(*api.BuildResult)
}
}

func (m *BuildManager) Start(source api.BuildSource) {
m.mutex.Lock()
defer m.mutex.Unlock()

func (m *Manager) Start(source api.BuildSource) {
initialBuildInfo := initialBuildInfo(&source)
m.builds[source.Identifier] = &initialBuildInfo
m.builds.Store(source.Identifier, &initialBuildInfo)

resChannel := m.builder.Build(source)
go func() {
res := <-resChannel
m.mutex.Lock()
defer m.mutex.Unlock()

m.builds[res.Source.Identifier] = &res
m.builds.Store(res.Source.Identifier, &res)
}()
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/build/build_manager_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (

func TestBuild(t *testing.T) {
ctx := context.TODO()
buildManager := NewBuildManager(ctx, test.GetTargetNamespace())
buildManager := NewManager(ctx, test.GetTargetNamespace())
identifier := build.BuildIdentifier{
Name: "man-test",
Digest: digest.Random(),
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestBuild(t *testing.T) {
func TestFailedBuild(t *testing.T) {

ctx := context.TODO()
buildManager := NewBuildManager(ctx, test.GetTargetNamespace())
buildManager := NewManager(ctx, test.GetTargetNamespace())
identifier := build.BuildIdentifier{
Name: "man-test-2",
Digest: digest.Random(),
Expand Down
4 changes: 2 additions & 2 deletions pkg/build/local/local_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (b *localBuilder) publish(tarFile string, source build.BuildSource) (string
Output: buildv1.BuildOutput{
To: &v1.ObjectReference{
Kind: "ImageStreamTag",
Name: "camel-k-" + source.Identifier.Name + ":" + source.Identifier.Digest,
Name: "camel-k-" + source.Identifier.Name + ":" + source.Identifier.Qualifier,
},
},
},
Expand Down Expand Up @@ -248,7 +248,7 @@ func (b *localBuilder) publish(tarFile string, source build.BuildSource) (string
if is.Status.DockerImageRepository == "" {
return "", errors.New("dockerImageRepository not available in ImageStream")
}
return is.Status.DockerImageRepository + ":" + source.Identifier.Digest, nil
return is.Status.DockerImageRepository + ":" + source.Identifier.Qualifier, nil
}

func generateProjectDefinition(source build.BuildSource) (maven.ProjectDefinition, error) {
Expand Down
16 changes: 8 additions & 8 deletions pkg/build/local/local_builder_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func TestBuild(t *testing.T) {

execution := builder.Build(build.BuildSource{
Identifier: build.BuildIdentifier{
Name: "test0",
Digest: digest.Random(),
Name: "test0",
Qualifier: digest.Random(),
},
Code: build.Code{
Content: code(),
Expand All @@ -56,8 +56,8 @@ func TestDoubleBuild(t *testing.T) {

execution1 := builder.Build(build.BuildSource{
Identifier: build.BuildIdentifier{
Name: "test1",
Digest: digest.Random(),
Name: "test1",
Qualifier: digest.Random(),
},
Code: build.Code{
Content: code(),
Expand All @@ -66,8 +66,8 @@ func TestDoubleBuild(t *testing.T) {

execution2 := builder.Build(build.BuildSource{
Identifier: build.BuildIdentifier{
Name: "test2",
Digest: digest.Random(),
Name: "test2",
Qualifier: digest.Random(),
},
Code: build.Code{
Content: code(),
Expand All @@ -88,8 +88,8 @@ func TestFailedBuild(t *testing.T) {

execution := builder.Build(build.BuildSource{
Identifier: build.BuildIdentifier{
Name: "test3",
Digest: digest.Random(),
Name: "test3",
Qualifier: digest.Random(),
},
Code: build.Code{
Content: code() + "-",
Expand Down
8 changes: 4 additions & 4 deletions pkg/build/local/local_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
func TestProjectGeneration(t *testing.T) {
source := api.BuildSource{
Identifier: api.BuildIdentifier{
Name: "my-integration",
Digest: "",
Name: "my-integration",
Qualifier: "",
},
Code: api.Code{
Name: "my-code.js",
Expand Down Expand Up @@ -59,8 +59,8 @@ func TestProjectGeneration(t *testing.T) {
func TestProjectGenerationWithFailure(t *testing.T) {
source := api.BuildSource{
Identifier: api.BuildIdentifier{
Name: "my-integration",
Digest: "",
Name: "my-integration",
Qualifier: "",
},
Code: api.Code{
Name: "my-code.js",
Expand Down
3 changes: 2 additions & 1 deletion pkg/client/cmd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func NewCmdContext(rootCmdOptions *RootCmdOptions) *cobra.Command {
Long: `Configure an Integration Context.`,
}

cmd.AddCommand(newContextEditCmd(rootCmdOptions))
cmd.AddCommand(newContextCreateCmd(rootCmdOptions))
cmd.AddCommand(newContextDeleteCmd(rootCmdOptions))
cmd.AddCommand(newContextGetCmd(rootCmdOptions))

return &cmd
Expand Down
Loading

0 comments on commit 50d03fd

Please sign in to comment.