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 707b7f4e38b9f4127a10f47360fdc7ce37125915
Author: Antonin Stefanutti <[email protected]>
AuthorDate: Mon Jan 13 14:17:48 2020 +0100

    feat(jolokia): Automatically add camel-management dependency
---
 pkg/trait/jolokia.go | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/pkg/trait/jolokia.go b/pkg/trait/jolokia.go
index 1e63040..60f6022 100644
--- a/pkg/trait/jolokia.go
+++ b/pkg/trait/jolokia.go
@@ -22,10 +22,11 @@ import (
        "strconv"
        "strings"
 
+       corev1 "k8s.io/api/core/v1"
+
        v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+       "github.com/apache/camel-k/pkg/util"
        "github.com/apache/camel-k/pkg/util/envvar"
-
-       corev1 "k8s.io/api/core/v1"
 )
 
 // The Jolokia trait activates and configures the Jolokia Java agent.
@@ -78,6 +79,10 @@ func newJolokiaTrait() *jolokiaTrait {
        }
 }
 
+func (t *jolokiaTrait) isEnabled() bool {
+       return t.Enabled != nil && *t.Enabled
+}
+
 func (t *jolokiaTrait) Configure(e *Environment) (bool, error) {
        options, err := parseCsvMap(t.Options)
        if err != nil {
@@ -95,10 +100,22 @@ func (t *jolokiaTrait) Configure(e *Environment) (bool, 
error) {
                setDefaultJolokiaOption(options, &t.UseSslClientAuthentication, 
"useSslClientAuthentication", true)
        }
 
-       return e.IntegrationInPhase(v1.IntegrationPhaseDeploying, 
v1.IntegrationPhaseRunning), nil
+       return e.IntegrationInPhase(
+               v1.IntegrationPhaseInitialization,
+               v1.IntegrationPhaseDeploying,
+               v1.IntegrationPhaseRunning,
+       ), nil
 }
 
 func (t *jolokiaTrait) Apply(e *Environment) (err error) {
+       if e.IntegrationInPhase(v1.IntegrationPhaseInitialization) {
+               if t.isEnabled() {
+                       // Add Camel management dependency
+                       
util.StringSliceUniqueAdd(&e.Integration.Status.Dependencies, 
"mvn:org.apache.camel/camel-management")
+               }
+               return nil
+       }
+
        containerName := defaultContainerName
        dt := e.Catalog.GetTrait(containerTraitID)
        if dt != nil {
@@ -116,7 +133,7 @@ func (t *jolokiaTrait) Apply(e *Environment) (err error) {
                return nil
        }
 
-       if t.Enabled == nil || !*t.Enabled {
+       if !t.isEnabled() {
                // Deactivate the Jolokia Java agent
                // Note: the AB_JOLOKIA_OFF environment variable acts as an 
option flag
                envvar.SetVal(&container.Env, "AB_JOLOKIA_OFF", "true")

Reply via email to