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


The following commit(s) were added to refs/heads/master by this push:
     new b7e6b9d  Add missing classpath locations for external kits
b7e6b9d is described below

commit b7e6b9d51519173b6ed7c00edd73270354d25edc
Author: James Netherton <[email protected]>
AuthorDate: Fri Mar 5 08:19:06 2021 +0000

    Add missing classpath locations for external kits
    
    Fixes #2090
---
 pkg/trait/jvm.go      |  9 +++++-
 pkg/trait/jvm_test.go | 81 +++++++++++++++++++++++++++++++++++----------------
 2 files changed, 64 insertions(+), 26 deletions(-)

diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index c4167f7..c7605ba 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -106,7 +106,14 @@ 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
-               classpath.Add("/deployments/dependencies/*")
+               dependencies := "/deployments/dependencies"
+               classpath.Add(
+                       dependencies+"/*",
+                       dependencies+"/app/*",
+                       dependencies+"/lib/boot/*",
+                       dependencies+"/lib/main/*",
+                       dependencies+"/quarkus/*",
+               )
        }
 
        container := e.getIntegrationContainer()
diff --git a/pkg/trait/jvm_test.go b/pkg/trait/jvm_test.go
index cd6acc4..5b55b18 100644
--- a/pkg/trait/jvm_test.go
+++ b/pkg/trait/jvm_test.go
@@ -20,6 +20,7 @@ package trait
 import (
        "context"
        "sort"
+       "strings"
        "testing"
 
        "github.com/apache/camel-k/pkg/util"
@@ -40,7 +41,7 @@ import (
 )
 
 func TestConfigureJvmTraitInRightPhasesDoesSucceed(t *testing.T) {
-       trait, environment := createNominalJvmTest()
+       trait, environment := 
createNominalJvmTest(v1.IntegrationKitTypePlatform)
 
        configured, err := trait.Configure(environment)
        assert.Nil(t, err)
@@ -48,7 +49,7 @@ func TestConfigureJvmTraitInRightPhasesDoesSucceed(t 
*testing.T) {
 }
 
 func TestConfigureJvmTraitInWrongIntegrationPhaseDoesNotSucceed(t *testing.T) {
-       trait, environment := createNominalJvmTest()
+       trait, environment := 
createNominalJvmTest(v1.IntegrationKitTypePlatform)
        environment.Integration.Status.Phase = v1.IntegrationPhaseError
 
        configured, err := trait.Configure(environment)
@@ -57,7 +58,7 @@ func 
TestConfigureJvmTraitInWrongIntegrationPhaseDoesNotSucceed(t *testing.T) {
 }
 
 func TestConfigureJvmTraitInWrongIntegrationKitPhaseDoesNotSucceed(t 
*testing.T) {
-       trait, environment := createNominalJvmTest()
+       trait, environment := 
createNominalJvmTest(v1.IntegrationKitTypePlatform)
        environment.IntegrationKit.Status.Phase = 
v1.IntegrationKitPhaseWaitingForPlatform
 
        configured, err := trait.Configure(environment)
@@ -66,7 +67,7 @@ func 
TestConfigureJvmTraitInWrongIntegrationKitPhaseDoesNotSucceed(t *testing.T)
 }
 
 func TestConfigureJvmDisabledTraitDoesNotSucceed(t *testing.T) {
-       trait, environment := createNominalJvmTest()
+       trait, environment := 
createNominalJvmTest(v1.IntegrationKitTypePlatform)
        trait.Enabled = new(bool)
 
        configured, err := trait.Configure(environment)
@@ -75,7 +76,7 @@ func TestConfigureJvmDisabledTraitDoesNotSucceed(t 
*testing.T) {
 }
 
 func TestApplyJvmTraitWithDeploymentResource(t *testing.T) {
-       trait, environment := createNominalJvmTest()
+       trait, environment := 
createNominalJvmTest(v1.IntegrationKitTypePlatform)
 
        d := appsv1.Deployment{
                Spec: appsv1.DeploymentSpec{
@@ -113,7 +114,7 @@ func TestApplyJvmTraitWithDeploymentResource(t *testing.T) {
 }
 
 func TestApplyJvmTraitWithKNativeResource(t *testing.T) {
-       trait, environment := createNominalJvmTest()
+       trait, environment := 
createNominalJvmTest(v1.IntegrationKitTypePlatform)
 
        s := serving.Service{}
        s.Spec.ConfigurationSpec.Template = serving.RevisionTemplateSpec{}
@@ -145,7 +146,7 @@ func TestApplyJvmTraitWithKNativeResource(t *testing.T) {
 }
 
 func TestApplyJvmTraitWithDebugEnabled(t *testing.T) {
-       trait, environment := createNominalJvmTest()
+       trait, environment := 
createNominalJvmTest(v1.IntegrationKitTypePlatform)
        trait.Debug = util.BoolP(true)
        trait.DebugSuspend = util.BoolP(true)
 
@@ -179,28 +180,47 @@ func TestApplyJvmTraitWithDebugEnabled(t *testing.T) {
        )
 }
 
-func createNominalJvmTest() (*jvmTrait, *Environment) {
-       return createJvmTestWithKitType(v1.IntegrationKitTypePlatform)
-}
-
-func createJvmTestWithKitType(kitType string) (*jvmTrait, *Environment) {
-       catalog, _ := camel.DefaultCatalog()
+func TestApplyJvmTraitWithExternalKitType(t *testing.T) {
+       trait, environment := 
createNominalJvmTest(v1.IntegrationKitTypeExternal)
 
-       client, _ := test.NewFakeClient(
-               &v1.IntegrationKit{
-                       TypeMeta: metav1.TypeMeta{
-                               APIVersion: v1.SchemeGroupVersion.String(),
-                               Kind:       v1.IntegrationKitKind,
-                       },
-                       ObjectMeta: metav1.ObjectMeta{
-                               Namespace: "kit-namespace",
-                               Name:      "kit-name",
-                               Labels: map[string]string{
-                                       "camel.apache.org/kit.type": kitType,
+       d := appsv1.Deployment{
+               Spec: appsv1.DeploymentSpec{
+                       Template: corev1.PodTemplateSpec{
+                               Spec: corev1.PodSpec{
+                                       Containers: []corev1.Container{
+                                               {
+                                                       Name: 
defaultContainerName,
+                                               },
+                                       },
                                },
                        },
                },
-       )
+       }
+
+       environment.Resources.Add(&d)
+
+       err := trait.Apply(environment)
+       assert.Nil(t, err)
+
+       container := environment.getIntegrationContainer()
+
+       assert.Equal(t, 3, len(container.Args))
+       assert.Equal(t, "-cp", container.Args[0])
+
+       // classpath JAR location segments must be wildcarded for an external 
kit
+       for _, cp := range strings.Split(container.Args[1], ":") {
+               if strings.HasPrefix(cp, "/deployments") {
+                       assert.True(t, strings.HasSuffix(cp, "/*"))
+               }
+       }
+
+       assert.Equal(t, "io.quarkus.bootstrap.runner.QuarkusEntryPoint", 
container.Args[2])
+}
+
+func createNominalJvmTest(kitType string) (*jvmTrait, *Environment) {
+       catalog, _ := camel.DefaultCatalog()
+
+       client, _ := test.NewFakeClient()
 
        trait := newJvmTrait().(*jvmTrait)
        trait.Enabled = util.BoolP(true)
@@ -217,6 +237,17 @@ func createJvmTestWithKitType(kitType string) (*jvmTrait, 
*Environment) {
                        },
                },
                IntegrationKit: &v1.IntegrationKit{
+                       TypeMeta: metav1.TypeMeta{
+                               APIVersion: v1.SchemeGroupVersion.String(),
+                               Kind:       v1.IntegrationKitKind,
+                       },
+                       ObjectMeta: metav1.ObjectMeta{
+                               Namespace: "kit-namespace",
+                               Name:      "kit-name",
+                               Labels: map[string]string{
+                                       "camel.apache.org/kit.type": kitType,
+                               },
+                       },
                        Status: v1.IntegrationKitStatus{
                                Phase: v1.IntegrationKitPhaseReady,
                        },

Reply via email to