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 b327f7de7238648b89b664e60df6b281fdd64b1b
Author: Antonin Stefanutti <[email protected]>
AuthorDate: Fri Mar 19 12:00:03 2021 +0100

    chore: Add constants for image layout directories
---
 pkg/builder/image.go    |  8 ++++++--
 pkg/builder/quarkus.go  |  2 +-
 pkg/builder/spectrum.go |  4 ++--
 pkg/trait/jvm.go        | 26 +++++++++++++-------------
 pkg/trait/jvm_test.go   |  8 ++++----
 5 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/pkg/builder/image.go b/pkg/builder/image.go
index 9ec8bf1..ce01bff 100644
--- a/pkg/builder/image.go
+++ b/pkg/builder/image.go
@@ -31,7 +31,11 @@ import (
        "github.com/apache/camel-k/pkg/util/controller"
 )
 
-const ContextDir = "context"
+const (
+       ContextDir      = "context"
+       DeploymentDir   = "/deployments"
+       DependenciesDir = "dependencies"
+)
 
 type artifactsSelector func(ctx *builderContext) error
 
@@ -110,7 +114,7 @@ func imageContext(ctx *builderContext, selector 
artifactsSelector) error {
        // #nosec G202
        dockerfile := []byte(`
                FROM ` + ctx.BaseImage + `
-               ADD . /deployments
+               ADD . ` + DeploymentDir + `
                USER 1000
        `)
 
diff --git a/pkg/builder/quarkus.go b/pkg/builder/quarkus.go
index e20422e..23ef90a 100644
--- a/pkg/builder/quarkus.go
+++ b/pkg/builder/quarkus.go
@@ -215,7 +215,7 @@ func ProcessQuarkusTransitiveDependencies(mc maven.Context) 
([]v1.Artifact, erro
                        artifacts = append(artifacts, v1.Artifact{
                                ID:       filepath.Base(fileRelPath),
                                Location: filePath,
-                               Target:   path.Join("dependencies", 
fileRelPath),
+                               Target:   path.Join(DependenciesDir, 
fileRelPath),
                                Checksum: "sha1:" + sha1,
                        })
                }
diff --git a/pkg/builder/spectrum.go b/pkg/builder/spectrum.go
index 32e8ca6..beb5b25 100644
--- a/pkg/builder/spectrum.go
+++ b/pkg/builder/spectrum.go
@@ -50,7 +50,7 @@ func (t *spectrumTask) Do(ctx context.Context) v1.BuildStatus 
{
                status.BaseImage = baseImage
        }
 
-       libraryPath := path.Join(t.task.ContextDir /*, "context"*/, 
"dependencies")
+       libraryPath := path.Join(t.task.ContextDir, DependenciesDir)
        _, err := os.Stat(libraryPath)
        if err != nil && os.IsNotExist(err) {
                // this can only indicate that there are no more libraries to 
add to the base image,
@@ -95,7 +95,7 @@ func (t *spectrumTask) Do(ctx context.Context) v1.BuildStatus 
{
                Recursive:     true,
        }
 
-       digest, err := spectrum.Build(options, 
libraryPath+":/deployments/dependencies")
+       digest, err := spectrum.Build(options, 
libraryPath+":"+path.Join(DeploymentDir, DependenciesDir))
        if err != nil {
                return status.Failed(err)
        }
diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index c7605ba..2d722e2 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -19,18 +19,24 @@ package trait
 
 import (
        "fmt"
+       "path"
        "sort"
        "strings"
 
-       v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
-       "github.com/apache/camel-k/pkg/util"
        "github.com/pkg/errors"
        "github.com/scylladb/go-set/strset"
+
        infp "gopkg.in/inf.v0"
+
        corev1 "k8s.io/api/core/v1"
        "k8s.io/apimachinery/pkg/api/resource"
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
-       k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
+
+       ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+
+       v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+       "github.com/apache/camel-k/pkg/builder"
+       "github.com/apache/camel-k/pkg/util"
 )
 
 // The JVM trait is used to configure the JVM that runs the integration.
@@ -74,15 +80,9 @@ func (t *jvmTrait) Apply(e *Environment) error {
                name := e.Integration.Status.IntegrationKit.Name
                ns := e.Integration.GetIntegrationKitNamespace(e.Platform)
                k := v1.NewIntegrationKit(ns, name)
-               key := k8sclient.ObjectKey{
-                       Namespace: ns,
-                       Name:      name,
-               }
-
-               if err := t.Client.Get(t.Ctx, key, &k); err != nil {
+               if err := t.Client.Get(t.Ctx, ctrl.ObjectKeyFromObject(&k), 
&k); err != nil {
                        return errors.Wrapf(err, "unable to find integration 
kit %s/%s, %s", ns, name, err)
                }
-
                kit = &k
        }
 
@@ -95,7 +95,7 @@ func (t *jvmTrait) Apply(e *Environment) error {
 
        classpath := strset.New()
 
-       classpath.Add("/etc/camel/resources")
+       classpath.Add(resourcesMountPath)
        classpath.Add("./resources")
 
        for _, artifact := range kit.Status.Artifacts {
@@ -106,7 +106,7 @@ func (t *jvmTrait) Apply(e *Environment) error {
                // In case of an external created kit, we do not have any 
information about
                // the classpath so we assume the all jars in 
/deployments/dependencies/ have
                // to be taken into account
-               dependencies := "/deployments/dependencies"
+               dependencies := path.Join(builder.DeploymentDir, 
builder.DependenciesDir)
                classpath.Add(
                        dependencies+"/*",
                        dependencies+"/app/*",
@@ -188,7 +188,7 @@ func (t *jvmTrait) Apply(e *Environment) error {
                container.Args = args
        }
 
-       container.WorkingDir = "/deployments"
+       container.WorkingDir = builder.DeploymentDir
 
        return nil
 }
diff --git a/pkg/trait/jvm_test.go b/pkg/trait/jvm_test.go
index 5b55b18..2572dc1 100644
--- a/pkg/trait/jvm_test.go
+++ b/pkg/trait/jvm_test.go
@@ -23,9 +23,6 @@ import (
        "strings"
        "testing"
 
-       "github.com/apache/camel-k/pkg/util"
-       "github.com/apache/camel-k/pkg/util/camel"
-
        "github.com/scylladb/go-set/strset"
        "github.com/stretchr/testify/assert"
 
@@ -36,6 +33,9 @@ import (
        serving "knative.dev/serving/pkg/apis/serving/v1"
 
        v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+       "github.com/apache/camel-k/pkg/builder"
+       "github.com/apache/camel-k/pkg/util"
+       "github.com/apache/camel-k/pkg/util/camel"
        "github.com/apache/camel-k/pkg/util/kubernetes"
        "github.com/apache/camel-k/pkg/util/test"
 )
@@ -209,7 +209,7 @@ func TestApplyJvmTraitWithExternalKitType(t *testing.T) {
 
        // classpath JAR location segments must be wildcarded for an external 
kit
        for _, cp := range strings.Split(container.Args[1], ":") {
-               if strings.HasPrefix(cp, "/deployments") {
+               if strings.HasPrefix(cp, builder.DeploymentDir) {
                        assert.True(t, strings.HasSuffix(cp, "/*"))
                }
        }

Reply via email to