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

Allow buildless direct deploy #61

Merged
merged 2 commits into from
Sep 13, 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
2 changes: 2 additions & 0 deletions deploy/crd-integration-context.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ spec:
listKind: IntegrationContextList
plural: integrationcontexts
singular: integrationcontext
shortNames:
- ictx
scope: Namespaced
version: v1alpha1
2 changes: 2 additions & 0 deletions deploy/crd-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ spec:
listKind: IntegrationList
plural: integrations
singular: integration
shortNames:
- it
scope: Namespaced
version: v1alpha1
9 changes: 9 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
13 changes: 9 additions & 4 deletions pkg/apis/camel/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,30 @@ type PropertySpec struct {
Name string
Value string
}

type EnvironmentSpec struct {
Name string
Value string
}

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"
)
66 changes: 66 additions & 0 deletions pkg/apis/camel/v1alpha1/types_support.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
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 v1alpha1

import (
"fmt"

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

// **********************************
//
// Methods
//
// **********************************

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

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

// **********************************
//
// Helpers
//
// **********************************

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