This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 57cfaac52d2d8b2ea9bcd9609bec3997791fa6a4
Author: Antonin Stefanutti <[email protected]>
AuthorDate: Mon Oct 21 14:55:40 2019 +0200

    chore(build): Load Camel catalog as builder step
---
 pkg/builder/builder.go         | 10 ----------
 pkg/builder/builder_steps.go   | 19 ++++++++++++++++++-
 pkg/builder/runtime/main.go    | 11 -----------
 pkg/builder/runtime/quarkus.go | 11 -----------
 pkg/trait/builder_test.go      |  4 ++--
 5 files changed, 20 insertions(+), 35 deletions(-)

diff --git a/pkg/builder/builder.go b/pkg/builder/builder.go
index 872c3df..6e9f63f 100644
--- a/pkg/builder/builder.go
+++ b/pkg/builder/builder.go
@@ -28,7 +28,6 @@ import (
 
        "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
        "github.com/apache/camel-k/pkg/client"
-       "github.com/apache/camel-k/pkg/util/camel"
        "github.com/apache/camel-k/pkg/util/cancellable"
        "github.com/apache/camel-k/pkg/util/log"
 )
@@ -71,17 +70,8 @@ func (b *defaultBuilder) Build(build v1alpha1.BuildSpec) 
v1alpha1.BuildStatus {
 
        defer os.RemoveAll(builderPath)
 
-       catalog, err := camel.LoadCatalog(b.ctx, b.client, 
build.Meta.Namespace, build.CamelVersion, build.RuntimeVersion)
-       if err != nil {
-               log.Error(err, "Error while loading Camel catalog")
-
-               result.Phase = v1alpha1.BuildPhaseFailed
-               result.Error = err.Error()
-       }
-
        c := Context{
                Client:    b.client,
-               Catalog:   catalog,
                Path:      builderPath,
                Namespace: build.Meta.Namespace,
                Build:     build,
diff --git a/pkg/builder/builder_steps.go b/pkg/builder/builder_steps.go
index 3e935e3..d6b1f3f 100644
--- a/pkg/builder/builder_steps.go
+++ b/pkg/builder/builder_steps.go
@@ -27,6 +27,7 @@ import (
        k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
 
        "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+       "github.com/apache/camel-k/pkg/util/camel"
        "github.com/apache/camel-k/pkg/util/kubernetes"
        "github.com/apache/camel-k/pkg/util/maven"
        "github.com/apache/camel-k/pkg/util/tar"
@@ -39,6 +40,7 @@ func init() {
 }
 
 type steps struct {
+       LoadCatalog             Step
        GenerateProjectSettings Step
        InjectDependencies      Step
        SanitizeDependencies    Step
@@ -48,6 +50,10 @@ type steps struct {
 
 // Steps --
 var Steps = steps{
+       LoadCatalog: NewStep(
+               InitPhase,
+               loadCatalog,
+       ),
        GenerateProjectSettings: NewStep(
                ProjectGenerationPhase+1,
                generateProjectSettings,
@@ -72,6 +78,7 @@ var Steps = steps{
 
 // DefaultSteps --
 var DefaultSteps = []Step{
+       Steps.LoadCatalog,
        Steps.GenerateProjectSettings,
        Steps.InjectDependencies,
        Steps.SanitizeDependencies,
@@ -104,7 +111,17 @@ func registerStep(steps ...Step) {
        }
 }
 
-// generateProjectSettings --
+func loadCatalog(ctx *Context) error {
+       catalog, err := camel.LoadCatalog(ctx.C, ctx.Client, 
ctx.Build.Meta.Namespace, ctx.Build.CamelVersion, ctx.Build.RuntimeVersion)
+       if err != nil {
+               return err
+       }
+
+       ctx.Catalog = catalog
+
+       return nil
+}
+
 func generateProjectSettings(ctx *Context) error {
        val, err := kubernetes.ResolveValueSource(ctx.C, ctx.Client, 
ctx.Namespace, &ctx.Build.Platform.Build.Maven.Settings)
        if err != nil {
diff --git a/pkg/builder/runtime/main.go b/pkg/builder/runtime/main.go
index dbf6668..4b363a0 100644
--- a/pkg/builder/runtime/main.go
+++ b/pkg/builder/runtime/main.go
@@ -27,7 +27,6 @@ import (
 
        "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
        "github.com/apache/camel-k/pkg/builder"
-       "github.com/apache/camel-k/pkg/util/camel"
        "github.com/apache/camel-k/pkg/util/defaults"
        "github.com/apache/camel-k/pkg/util/maven"
 )
@@ -39,16 +38,6 @@ var MainSteps = []builder.Step{
 }
 
 func generateProject(ctx *builder.Context) error {
-       // Catalog
-       if ctx.Catalog == nil {
-               c, err := camel.LoadCatalog(ctx.C, ctx.Client, ctx.Namespace, 
ctx.Build.Platform.Build.CamelVersion, ctx.Build.Platform.Build.RuntimeVersion)
-               if err != nil {
-                       return err
-               }
-
-               ctx.Catalog = c
-       }
-
        p := maven.NewProjectWithGAV("org.apache.camel.k.integration", 
"camel-k-integration", defaults.Version)
        p.Properties = ctx.Build.Platform.Build.Properties
        p.DependencyManagement = &maven.DependencyManagement{Dependencies: 
make([]maven.Dependency, 0)}
diff --git a/pkg/builder/runtime/quarkus.go b/pkg/builder/runtime/quarkus.go
index ddca59e..df0faf5 100644
--- a/pkg/builder/runtime/quarkus.go
+++ b/pkg/builder/runtime/quarkus.go
@@ -10,7 +10,6 @@ import (
 
        "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
        "github.com/apache/camel-k/pkg/builder"
-       "github.com/apache/camel-k/pkg/util/camel"
        "github.com/apache/camel-k/pkg/util/defaults"
        "github.com/apache/camel-k/pkg/util/maven"
 )
@@ -22,16 +21,6 @@ var QuarkusSteps = []builder.Step{
 }
 
 func generateQuarkusProject(ctx *builder.Context) error {
-       // Catalog
-       if ctx.Catalog == nil {
-               c, err := camel.LoadCatalog(ctx.C, ctx.Client, ctx.Namespace, 
ctx.Build.Platform.Build.CamelVersion, ctx.Build.Platform.Build.RuntimeVersion)
-               if err != nil {
-                       return err
-               }
-
-               ctx.Catalog = c
-       }
-
        p := maven.NewProjectWithGAV("org.apache.camel.k.integration", 
"camel-k-integration", defaults.Version)
        p.Properties = ctx.Build.Platform.Build.Properties
        p.DependencyManagement = &maven.DependencyManagement{Dependencies: 
make([]maven.Dependency, 0)}
diff --git a/pkg/trait/builder_test.go b/pkg/trait/builder_test.go
index f1153d3..e3ae69e 100644
--- a/pkg/trait/builder_test.go
+++ b/pkg/trait/builder_test.go
@@ -87,7 +87,7 @@ func TestS2IBuilderTrait(t *testing.T) {
        assert.NotEmpty(t, env.ExecutedTraits)
        assert.NotNil(t, env.GetTrait(ID("builder")))
        assert.NotEmpty(t, env.Steps)
-       assert.Len(t, env.Steps, 7)
+       assert.Len(t, env.Steps, 8)
        assert.Condition(t, func() bool {
                for _, s := range env.Steps {
                        if s == s2i.Steps.Publisher && s.Phase() == 
builder.ApplicationPublishPhase {
@@ -107,7 +107,7 @@ func TestKanikoBuilderTrait(t *testing.T) {
        assert.NotEmpty(t, env.ExecutedTraits)
        assert.NotNil(t, env.GetTrait(ID("builder")))
        assert.NotEmpty(t, env.Steps)
-       assert.Len(t, env.Steps, 7)
+       assert.Len(t, env.Steps, 8)
        assert.Condition(t, func() bool {
                for _, s := range env.Steps {
                        if s == kaniko.Steps.Publisher && s.Phase() == 
builder.ApplicationPublishPhase {

Reply via email to