Skip to content

Commit

Permalink
feat(trait): jvm refactoring
Browse files Browse the repository at this point in the history
* add more unit test
* enable the trait for synthetic Kits
* add documentation on the jvm trait usage

Closes apache#5476
  • Loading branch information
squakez committed May 28, 2024
1 parent ea28e55 commit 6fff6a4
Show file tree
Hide file tree
Showing 23 changed files with 634 additions and 199 deletions.
11 changes: 10 additions & 1 deletion docs/modules/ROOT/partials/apis/camel-k-crds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6234,7 +6234,8 @@ string
|
Specify a base image
Specify a base image. In order to have the application working properly it must be a container image which has a Java JDK
installed and ready to use on path (ie `/usr/bin/java`).
|`incrementalImageBuild` +
bool
Expand Down Expand Up @@ -7306,6 +7307,7 @@ bool
Prints the command used the start the JVM in the container logs (default `true`)
Deprecated: no longer in use.
|`debugAddress` +
string
Expand All @@ -7328,6 +7330,13 @@ string
Additional JVM classpath (use `Linux` classpath separator)
|`jar` +
string
|
The Jar dependency which will run the application. Leave it empty for managed Integrations.
|===
Expand Down
3 changes: 2 additions & 1 deletion docs/modules/traits/pages/builder.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ Deprecated no longer in use

| builder.base-image
| string
| Specify a base image
| Specify a base image. In order to have the application working properly it must be a container image which has a Java JDK
installed and ready to use on path (ie `/usr/bin/java`).

| builder.incremental-image-build
| bool
Expand Down
18 changes: 17 additions & 1 deletion docs/modules/traits/pages/jvm.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The following configuration options are available:
| jvm.print-command
| bool
| Prints the command used the start the JVM in the container logs (default `true`)
Deprecated: no longer in use.

| jvm.debug-address
| string
Expand All @@ -53,11 +54,26 @@ The following configuration options are available:
| string
| Additional JVM classpath (use `Linux` classpath separator)

| jvm.jar
| string
| The Jar dependency which will run the application. Leave it empty for managed Integrations.

|===

// End of autogenerated code - DO NOT EDIT! (configuration)

== Examples
== Usage of jar parameters

The `jar` parameter is something the user should not worry about, unless that, for any reason, he wants to specify which is the executable dependency to use. Mind that, in order to do that, the base image used to build the container require a java binary executable from path (ie, `/usr/bin/java`).

This parameters enables also the possibility to use the trait when running a synthetic IntegrationKit (ie, "sourceless" Integrations). In such circumstances, the user can run a Camel application built externally and make use of the trait configuration as well as for example:

[source,console]
$ kamel run --image docker.io/squakez/my-camel-sb:1.0.0 -t jvm.jar=/deployments/my-camel-app.jar -t jvm.options=-Xmx1024M

The above command would allow the execution of the JVM trait given that the user specify the path to the jar to execute.

== Other examples

* Include an additional classpath to the `Integration`:
+
Expand Down
6 changes: 3 additions & 3 deletions e2e/common/runtimes/runtimes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestSourceLessIntegrations(t *testing.T) {
g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "--image", "docker.io/squakez/my-camel-main:1.0.0", "--resource", "configmap:my-cm-sourceless@/tmp/app/data").Execute()).To(Succeed())
g.Eventually(IntegrationPodPhase(t, ctx, ns, itName), TestTimeoutShort).Should(Equal(corev1.PodRunning))
g.Eventually(IntegrationConditionStatus(t, ctx, ns, itName, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
g.Eventually(IntegrationCondition(t, ctx, ns, itName, v1.IntegrationConditionType("JVMTraitInfo"))().Message).Should(Equal("explicitly disabled by the platform: integration kit was not created via Camel K operator"))
g.Eventually(IntegrationCondition(t, ctx, ns, itName, v1.IntegrationConditionType("JVMTraitInfo"))().Message).Should(ContainSubstring("explicitly disabled by the platform"))
g.Eventually(IntegrationLogs(t, ctx, ns, itName), TestTimeoutShort).Should(ContainSubstring(cmData["my-file.txt"]))
g.Eventually(IntegrationLogs(t, ctx, ns, itName), TestTimeoutShort).Should(ContainSubstring("Apache Camel (Main)"))
})
Expand All @@ -64,7 +64,7 @@ func TestSourceLessIntegrations(t *testing.T) {
g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "--image", "docker.io/squakez/my-camel-sb:1.0.0", "--resource", "configmap:my-cm-sourceless@/tmp/app/data").Execute()).To(Succeed())
g.Eventually(IntegrationPodPhase(t, ctx, ns, itName), TestTimeoutShort).Should(Equal(corev1.PodRunning))
g.Eventually(IntegrationConditionStatus(t, ctx, ns, itName, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
g.Eventually(IntegrationCondition(t, ctx, ns, itName, v1.IntegrationConditionType("JVMTraitInfo"))().Message).Should(Equal("explicitly disabled by the platform: integration kit was not created via Camel K operator"))
g.Eventually(IntegrationCondition(t, ctx, ns, itName, v1.IntegrationConditionType("JVMTraitInfo"))().Message).Should(ContainSubstring("explicitly disabled by the platform"))
g.Eventually(IntegrationLogs(t, ctx, ns, itName), TestTimeoutShort).Should(ContainSubstring(cmData["my-file.txt"]))
g.Eventually(IntegrationLogs(t, ctx, ns, itName), TestTimeoutShort).Should(ContainSubstring("Spring Boot"))
})
Expand All @@ -74,7 +74,7 @@ func TestSourceLessIntegrations(t *testing.T) {
g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "--image", "docker.io/squakez/my-camel-quarkus:1.0.0", "--resource", "configmap:my-cm-sourceless@/tmp/app/data").Execute()).To(Succeed())
g.Eventually(IntegrationPodPhase(t, ctx, ns, itName), TestTimeoutShort).Should(Equal(corev1.PodRunning))
g.Eventually(IntegrationConditionStatus(t, ctx, ns, itName, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
g.Eventually(IntegrationCondition(t, ctx, ns, itName, v1.IntegrationConditionType("JVMTraitInfo"))().Message).Should(Equal("explicitly disabled by the platform: integration kit was not created via Camel K operator"))
g.Eventually(IntegrationCondition(t, ctx, ns, itName, v1.IntegrationConditionType("JVMTraitInfo"))().Message).Should(ContainSubstring("explicitly disabled by the platform"))
g.Eventually(IntegrationLogs(t, ctx, ns, itName), TestTimeoutShort).Should(ContainSubstring(cmData["my-file.txt"]))
g.Eventually(IntegrationLogs(t, ctx, ns, itName), TestTimeoutShort).Should(ContainSubstring("powered by Quarkus"))
})
Expand Down
13 changes: 13 additions & 0 deletions e2e/common/traits/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,19 @@ func TestBuilderTrait(t *testing.T) {
g.Expect(TestClient(t).Delete(ctx, mavenProfile1Cm)).To(Succeed())
g.Expect(TestClient(t).Delete(ctx, mavenProfile2Cm)).To(Succeed())
})

t.Run("Run distroless container image", func(t *testing.T) {
name := RandomizedSuffixName("java")
g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "builder.base-image=gcr.io/distroless/java17-debian12").Execute()).To(Succeed())

g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning))
g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
integrationKitName := IntegrationKit(t, ctx, ns, name)()
g.Eventually(KitRootImage(t, ctx, ns, integrationKitName), TestTimeoutShort).Should(Equal("gcr.io/distroless/java17-debian12"))

g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed())
})
})
}

Expand Down
10 changes: 10 additions & 0 deletions e2e/support/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,16 @@ func KitImage(t *testing.T, ctx context.Context, ns, name string) func() string
}
}

func KitRootImage(t *testing.T, ctx context.Context, ns, name string) func() string {
return func() string {
kit := Kit(t, ctx, ns, name)()
if kit == nil {
return ""
}
return kit.Status.RootImage
}
}

func KitCondition(t *testing.T, ctx context.Context, ns string, name string, conditionType v1.IntegrationKitConditionType) func() *v1.IntegrationKitCondition {
return func() *v1.IntegrationKitCondition {
kt := Kit(t, ctx, ns, name)()
Expand Down
4 changes: 3 additions & 1 deletion helm/camel-k/crds/crd-integration-kit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ spec:
for the builder pod.
type: object
baseImage:
description: Specify a base image
description: Specify a base image. In order to have the application
working properly it must be a container image which has
a Java JDK installed and ready to use on path (ie `/usr/bin/java`).
type: string
configuration:
description: 'Legacy trait configuration parameters. Deprecated:
Expand Down
26 changes: 20 additions & 6 deletions helm/camel-k/crds/crd-integration-platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,9 @@ spec:
for the builder pod.
type: object
baseImage:
description: Specify a base image
description: Specify a base image. In order to have the application
working properly it must be a container image which has
a Java JDK installed and ready to use on path (ie `/usr/bin/java`).
type: string
configuration:
description: 'Legacy trait configuration parameters. Deprecated:
Expand Down Expand Up @@ -1285,14 +1287,19 @@ spec:
description: Can be used to enable or disable a trait. All
traits share this common property.
type: boolean
jar:
description: The Jar dependency which will run the application.
Leave it empty for managed Integrations.
type: string
options:
description: A list of JVM options
items:
type: string
type: array
printCommand:
description: Prints the command used the start the JVM in
the container logs (default `true`)
description: 'Prints the command used the start the JVM in
the container logs (default `true`) Deprecated: no longer
in use.'
type: boolean
type: object
kamelets:
Expand Down Expand Up @@ -2518,7 +2525,9 @@ spec:
for the builder pod.
type: object
baseImage:
description: Specify a base image
description: Specify a base image. In order to have the application
working properly it must be a container image which has
a Java JDK installed and ready to use on path (ie `/usr/bin/java`).
type: string
configuration:
description: 'Legacy trait configuration parameters. Deprecated:
Expand Down Expand Up @@ -3275,14 +3284,19 @@ spec:
description: Can be used to enable or disable a trait. All
traits share this common property.
type: boolean
jar:
description: The Jar dependency which will run the application.
Leave it empty for managed Integrations.
type: string
options:
description: A list of JVM options
items:
type: string
type: array
printCommand:
description: Prints the command used the start the JVM in
the container logs (default `true`)
description: 'Prints the command used the start the JVM in
the container logs (default `true`) Deprecated: no longer
in use.'
type: boolean
type: object
kamelets:
Expand Down
26 changes: 20 additions & 6 deletions helm/camel-k/crds/crd-integration-profile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,9 @@ spec:
for the builder pod.
type: object
baseImage:
description: Specify a base image
description: Specify a base image. In order to have the application
working properly it must be a container image which has
a Java JDK installed and ready to use on path (ie `/usr/bin/java`).
type: string
configuration:
description: 'Legacy trait configuration parameters. Deprecated:
Expand Down Expand Up @@ -1162,14 +1164,19 @@ spec:
description: Can be used to enable or disable a trait. All
traits share this common property.
type: boolean
jar:
description: The Jar dependency which will run the application.
Leave it empty for managed Integrations.
type: string
options:
description: A list of JVM options
items:
type: string
type: array
printCommand:
description: Prints the command used the start the JVM in
the container logs (default `true`)
description: 'Prints the command used the start the JVM in
the container logs (default `true`) Deprecated: no longer
in use.'
type: boolean
type: object
kamelets:
Expand Down Expand Up @@ -2278,7 +2285,9 @@ spec:
for the builder pod.
type: object
baseImage:
description: Specify a base image
description: Specify a base image. In order to have the application
working properly it must be a container image which has
a Java JDK installed and ready to use on path (ie `/usr/bin/java`).
type: string
configuration:
description: 'Legacy trait configuration parameters. Deprecated:
Expand Down Expand Up @@ -3035,14 +3044,19 @@ spec:
description: Can be used to enable or disable a trait. All
traits share this common property.
type: boolean
jar:
description: The Jar dependency which will run the application.
Leave it empty for managed Integrations.
type: string
options:
description: A list of JVM options
items:
type: string
type: array
printCommand:
description: Prints the command used the start the JVM in
the container logs (default `true`)
description: 'Prints the command used the start the JVM in
the container logs (default `true`) Deprecated: no longer
in use.'
type: boolean
type: object
kamelets:
Expand Down
13 changes: 10 additions & 3 deletions helm/camel-k/crds/crd-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6466,7 +6466,9 @@ spec:
for the builder pod.
type: object
baseImage:
description: Specify a base image
description: Specify a base image. In order to have the application
working properly it must be a container image which has
a Java JDK installed and ready to use on path (ie `/usr/bin/java`).
type: string
configuration:
description: 'Legacy trait configuration parameters. Deprecated:
Expand Down Expand Up @@ -7223,14 +7225,19 @@ spec:
description: Can be used to enable or disable a trait. All
traits share this common property.
type: boolean
jar:
description: The Jar dependency which will run the application.
Leave it empty for managed Integrations.
type: string
options:
description: A list of JVM options
items:
type: string
type: array
printCommand:
description: Prints the command used the start the JVM in
the container logs (default `true`)
description: 'Prints the command used the start the JVM in
the container logs (default `true`) Deprecated: no longer
in use.'
type: boolean
type: object
kamelets:
Expand Down
14 changes: 11 additions & 3 deletions helm/camel-k/crds/crd-kamelet-binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6742,7 +6742,10 @@ spec:
use for the builder pod.
type: object
baseImage:
description: Specify a base image
description: Specify a base image. In order to have the
application working properly it must be a container
image which has a Java JDK installed and ready to use
on path (ie `/usr/bin/java`).
type: string
configuration:
description: 'Legacy trait configuration parameters. Deprecated:
Expand Down Expand Up @@ -7507,14 +7510,19 @@ spec:
description: Can be used to enable or disable a trait.
All traits share this common property.
type: boolean
jar:
description: The Jar dependency which will run the application.
Leave it empty for managed Integrations.
type: string
options:
description: A list of JVM options
items:
type: string
type: array
printCommand:
description: Prints the command used the start the JVM
in the container logs (default `true`)
description: 'Prints the command used the start the JVM
in the container logs (default `true`) Deprecated: no
longer in use.'
type: boolean
type: object
kamelets:
Expand Down
Loading

0 comments on commit 6fff6a4

Please sign in to comment.