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 c9ab8d26c32ac81676a146f9865efbe9598cd532 Author: Antonin Stefanutti <anto...@stefanutti.fr> AuthorDate: Thu Jan 23 15:56:12 2020 +0100 feat(trait): Add options to configure JVM remote debugging --- docs/modules/ROOT/pages/traits/jvm.adoc | 8 ++++++++ pkg/trait/jvm.go | 16 +++++++++++++-- pkg/trait/jvm_test.go | 35 +++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/docs/modules/ROOT/pages/traits/jvm.adoc b/docs/modules/ROOT/pages/traits/jvm.adoc index bdbe13c..8dbfad4 100755 --- a/docs/modules/ROOT/pages/traits/jvm.adoc +++ b/docs/modules/ROOT/pages/traits/jvm.adoc @@ -30,6 +30,14 @@ The following configuration options are available: | bool | Activates remote debugging, so that a debugger can be attached to the JVM, e.g., using port-forwarding +| jvm.debug-suspend +| bool +| Suspends the target JVM immediately before the main class is loaded + +| jvm.debug-address +| string +| Transport address at which to listen for the newly launched JVM + | jvm.options | string | A comma-separated list of JVM options diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go index b5ece60..b1a783b 100644 --- a/pkg/trait/jvm.go +++ b/pkg/trait/jvm.go @@ -42,6 +42,10 @@ type jvmTrait struct { BaseTrait `property:",squash"` // Activates remote debugging, so that a debugger can be attached to the JVM, e.g., using port-forwarding Debug bool `property:"debug"` + // Suspends the target JVM immediately before the main class is loaded + DebugSuspend bool `property:"debug-suspend"` + // Transport address at which to listen for the newly launched JVM + DebugAddress string `property:"debug-address"` // A comma-separated list of JVM options Options *string `property:"options"` } @@ -49,6 +53,8 @@ type jvmTrait struct { func newJvmTrait() *jvmTrait { return &jvmTrait{ BaseTrait: newBaseTrait("jvm"), + // To be defaulted to "*:5005" when upgrading the default base image to JDK9+ + DebugAddress: "5005", } } @@ -108,9 +114,15 @@ func (t *jvmTrait) Apply(e *Environment) error { container.Command = []string{"java"} container.WorkingDir = "/deployments" + // Remote debugging if t.Debug { - // TODO: Add options to configure debugging agent - container.Args = append(container.Args, "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005") + suspend := "n" + if t.DebugSuspend { + suspend = "y" + } + container.Args = append(container.Args, + fmt.Sprintf("-agentlib:jdwp=transport=dt_socket,server=y,suspend=%s,address=%s", + suspend, t.DebugAddress)) } // Add JVM options diff --git a/pkg/trait/jvm_test.go b/pkg/trait/jvm_test.go index 57260db..e180202 100644 --- a/pkg/trait/jvm_test.go +++ b/pkg/trait/jvm_test.go @@ -141,6 +141,41 @@ func TestApplyJvmTraitWithKNativeResource(t *testing.T) { }) } +func TestApplyJvmTraitWithDebugEnabled(t *testing.T) { + trait, environment := createNominalJvmTest() + trait.Debug = true + trait.DebugSuspend = true + + d := appsv1.Deployment{ + Spec: appsv1.DeploymentSpec{ + Template: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: defaultContainerName, + VolumeMounts: []corev1.VolumeMount{ + { + MountPath: "/mount/path", + }, + }, + }, + }, + }, + }, + }, + } + + environment.Resources.Add(&d) + + err := trait.Apply(environment) + + assert.Nil(t, err) + + assert.Contains(t, d.Spec.Template.Spec.Containers[0].Args, + "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005", + ) +} + func createNominalJvmTest() (*jvmTrait, *Environment) { return createJvmTestWithKitType(v1.IntegrationKitTypePlatform) }