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

Add missing classpath locations for external kits #2097

Merged
merged 1 commit into from
Mar 5, 2021
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
9 changes: 8 additions & 1 deletion pkg/trait/jvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
81 changes: 56 additions & 25 deletions pkg/trait/jvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package trait
import (
"context"
"sort"
"strings"
"testing"

"github.com/apache/camel-k/pkg/util"
Expand All @@ -40,15 +41,15 @@ import (
)

func TestConfigureJvmTraitInRightPhasesDoesSucceed(t *testing.T) {
trait, environment := createNominalJvmTest()
trait, environment := createNominalJvmTest(v1.IntegrationKitTypePlatform)

configured, err := trait.Configure(environment)
assert.Nil(t, err)
assert.True(t, configured)
}

func TestConfigureJvmTraitInWrongIntegrationPhaseDoesNotSucceed(t *testing.T) {
trait, environment := createNominalJvmTest()
trait, environment := createNominalJvmTest(v1.IntegrationKitTypePlatform)
environment.Integration.Status.Phase = v1.IntegrationPhaseError

configured, err := trait.Configure(environment)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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{
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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,
},
Expand Down