From ec6b28e54b8ab056a7a0b40198ffd1f281d6dab6 Mon Sep 17 00:00:00 2001 From: James Netherton Date: Fri, 5 Mar 2021 08:19:06 +0000 Subject: [PATCH] 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 c4167f7ad7..c7605ba9d2 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 cd6acc4250..5b55b18c0b 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, },