You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2020/01/24 17:09:06 UTC

[camel-k] 05/07: chore(trait): Merge Debug trait into the JVM trait

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 387ae53fcc42dfefb801ac9eec68f7cf7af17544
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Jan 23 15:19:45 2020 +0100

    chore(trait): Merge Debug trait into the JVM trait
---
 docs/modules/ROOT/nav.adoc                 |   1 -
 docs/modules/ROOT/pages/traits/jvm.adoc    |   4 ++
 docs/modules/ROOT/pages/traits/traits.adoc |   1 -
 pkg/trait/debug.go                         |  58 ---------------
 pkg/trait/debug_test.go                    | 111 -----------------------------
 pkg/trait/jvm.go                           |   8 ++-
 pkg/trait/trait_catalog.go                 |   6 --
 7 files changed, 11 insertions(+), 178 deletions(-)

diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc
index 1251e0a..318f21a 100644
--- a/docs/modules/ROOT/nav.adoc
+++ b/docs/modules/ROOT/nav.adoc
@@ -21,7 +21,6 @@
 ** xref:traits/camel.adoc[Camel]
 ** xref:traits/container.adoc[Container]
 ** xref:traits/cron.adoc[Cron]
-** xref:traits/debug.adoc[Debug]
 ** xref:traits/dependencies.adoc[Dependencies]
 ** xref:traits/deployer.adoc[Deployer]
 ** xref:traits/deployment.adoc[Deployment]
diff --git a/docs/modules/ROOT/pages/traits/jvm.adoc b/docs/modules/ROOT/pages/traits/jvm.adoc
index 530c1a7..bdbe13c 100755
--- a/docs/modules/ROOT/pages/traits/jvm.adoc
+++ b/docs/modules/ROOT/pages/traits/jvm.adoc
@@ -26,6 +26,10 @@ The following configuration options are available:
 | bool
 | Can be used to enable or disable a trait. All traits share this common property.
 
+| jvm.debug
+| bool
+| Activates remote debugging, so that a debugger can be attached to the JVM, e.g., using port-forwarding
+
 | jvm.options
 | string
 | A comma-separated list of JVM options
diff --git a/docs/modules/ROOT/pages/traits/traits.adoc b/docs/modules/ROOT/pages/traits/traits.adoc
index efb3465..f0c4b24 100644
--- a/docs/modules/ROOT/pages/traits/traits.adoc
+++ b/docs/modules/ROOT/pages/traits/traits.adoc
@@ -39,7 +39,6 @@ See the trait description pages for more information on a specific trait:
 * xref:traits/camel.adoc[Camel Trait]
 * xref:traits/container.adoc[Container Trait]
 * xref:traits/cron.adoc[Cron Trait]
-* xref:traits/debug.adoc[Debug Trait]
 * xref:traits/dependencies.adoc[Dependencies Trait]
 * xref:traits/deployer.adoc[Deployer Trait]
 * xref:traits/deployment.adoc[Deployment Trait]
diff --git a/pkg/trait/debug.go b/pkg/trait/debug.go
deleted file mode 100644
index 38d3c5f..0000000
--- a/pkg/trait/debug.go
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements.  See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to You under the Apache License, Version 2.0
-(the "License"); you may not use this file except in compliance with
-the License.  You may obtain a copy of the License at
-
-   http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package trait
-
-import (
-	"fmt"
-
-	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
-)
-
-// The Debug trait can be used to enable debugging on the integration container,
-// so that a remote debugger can be attached.
-//
-// +camel-k:trait=debug
-type debugTrait struct {
-	BaseTrait `property:",squash"`
-}
-
-func newDebugTrait() *debugTrait {
-	return &debugTrait{
-		BaseTrait: newBaseTrait("debug"),
-	}
-}
-
-func (t *debugTrait) Configure(e *Environment) (bool, error) {
-	if t.Enabled != nil && *t.Enabled {
-		return e.IntegrationInPhase(v1.IntegrationPhaseDeploying, v1.IntegrationPhaseRunning), nil
-	}
-
-	return false, nil
-}
-
-func (t *debugTrait) Apply(e *Environment) error {
-	container := e.getIntegrationContainer()
-	if container == nil {
-		return fmt.Errorf("unable to find integration container")
-	}
-
-	// TODO: Add options to configure debugging agent
-	container.Args = append(container.Args, "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005")
-
-	return nil
-}
diff --git a/pkg/trait/debug_test.go b/pkg/trait/debug_test.go
deleted file mode 100644
index 32b3e1d..0000000
--- a/pkg/trait/debug_test.go
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements.  See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to You under the Apache License, Version 2.0
-(the "License"); you may not use this file except in compliance with
-the License.  You may obtain a copy of the License at
-
-   http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package trait
-
-import (
-	"context"
-	"testing"
-
-	"github.com/stretchr/testify/assert"
-
-	appsv1 "k8s.io/api/apps/v1"
-	corev1 "k8s.io/api/core/v1"
-
-	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
-	"github.com/apache/camel-k/pkg/util/camel"
-	"github.com/apache/camel-k/pkg/util/kubernetes"
-)
-
-func TestDebugTraitApplicability(t *testing.T) {
-	catalog, err := camel.DefaultCatalog()
-	assert.Nil(t, err)
-
-	env := Environment{
-		CamelCatalog: catalog,
-		Integration: &v1.Integration{
-			Status: v1.IntegrationStatus{
-				Phase: v1.IntegrationPhaseDeploying,
-			},
-			Spec: v1.IntegrationSpec{
-				Traits: map[string]v1.TraitSpec{
-					"debug": {
-						Configuration: map[string]string{
-							"enabled": "true",
-						},
-					},
-				},
-			},
-		},
-	}
-
-	trait := newDebugTrait()
-
-	enabled, err := trait.Configure(&env)
-	assert.Nil(t, err)
-	assert.False(t, enabled)
-
-	env.Integration.Status.Phase = v1.IntegrationPhaseRunning
-
-	enabled, err = trait.Configure(&env)
-	assert.Nil(t, err)
-	assert.False(t, enabled)
-}
-
-func TestApplyDebugTrait(t *testing.T) {
-	environment := Environment{
-		Catalog: NewCatalog(context.TODO(), nil),
-		Integration: &v1.Integration{
-			Status: v1.IntegrationStatus{
-				Phase: v1.IntegrationPhaseDeploying,
-			},
-			Spec: v1.IntegrationSpec{
-				Traits: map[string]v1.TraitSpec{
-					"debug": {
-						Configuration: map[string]string{
-							"enabled": "true",
-						},
-					},
-				},
-			},
-		},
-		Resources: kubernetes.NewCollection(),
-	}
-
-	d := appsv1.Deployment{
-		Spec: appsv1.DeploymentSpec{
-			Template: corev1.PodTemplateSpec{
-				Spec: corev1.PodSpec{
-					Containers: []corev1.Container{
-						{
-							Name: defaultContainerName,
-						},
-					},
-				},
-			},
-		},
-	}
-
-	environment.Resources.Add(&d)
-
-	trait := newDebugTrait()
-
-	assert.Nil(t, trait.Apply(&environment))
-	assert.Equal(t, d.Spec.Template.Spec.Containers[0].Args, []string{
-		"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005",
-	})
-}
diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index 348e093..b5ece60 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -40,7 +40,8 @@ const (
 // +camel-k:trait=jvm
 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"`
 	// A comma-separated list of JVM options
 	Options *string `property:"options"`
 }
@@ -107,6 +108,11 @@ func (t *jvmTrait) Apply(e *Environment) error {
 		container.Command = []string{"java"}
 		container.WorkingDir = "/deployments"
 
+		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")
+		}
+
 		// Add JVM options
 		if t.Options != nil {
 			container.Args = append(container.Args, strings.Split(*t.Options, ",")...)
diff --git a/pkg/trait/trait_catalog.go b/pkg/trait/trait_catalog.go
index 81a3180..41d0fea 100644
--- a/pkg/trait/trait_catalog.go
+++ b/pkg/trait/trait_catalog.go
@@ -35,7 +35,6 @@ type Catalog struct {
 	tPlatform         Trait
 	tAffinity         Trait
 	tCamel            Trait
-	tDebug            Trait
 	tDependencies     Trait
 	tDeployer         Trait
 	tCron             Trait
@@ -67,7 +66,6 @@ func NewCatalog(ctx context.Context, c client.Client) *Catalog {
 		tPlatform:         newPlatformTrait(),
 		tAffinity:         newAffinityTrait(),
 		tCamel:            newCamelTrait(),
-		tDebug:            newDebugTrait(),
 		tRestDsl:          newRestDslTrait(),
 		tKnative:          newKnativeTrait(),
 		tDependencies:     newDependenciesTrait(),
@@ -108,7 +106,6 @@ func (c *Catalog) allTraits() []Trait {
 		c.tPlatform,
 		c.tAffinity,
 		c.tCamel,
-		c.tDebug,
 		c.tRestDsl,
 		c.tKnative,
 		c.tDependencies,
@@ -166,7 +163,6 @@ func (c *Catalog) TraitsForProfile(profile v1.TraitProfile) []Trait {
 			c.tPullSecret,
 			c.tJolokia,
 			c.tPrometheus,
-			c.tDebug,
 			c.tJvm,
 			c.tProbes,
 			c.tRoute,
@@ -192,7 +188,6 @@ func (c *Catalog) TraitsForProfile(profile v1.TraitProfile) []Trait {
 			c.tPullSecret,
 			c.tJolokia,
 			c.tPrometheus,
-			c.tDebug,
 			c.tJvm,
 			c.tProbes,
 			c.tIngress,
@@ -219,7 +214,6 @@ func (c *Catalog) TraitsForProfile(profile v1.TraitProfile) []Trait {
 			c.tPullSecret,
 			c.tJolokia,
 			c.tPrometheus,
-			c.tDebug,
 			c.tJvm,
 			c.tProbes,
 			c.tIstio,