This is an automated email from the ASF dual-hosted git repository. lburgazzoli pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/master by this push: new 027eaf0 Jolokia trait initial implementation 027eaf0 is described below commit 027eaf0aced6856a913752ce2c7376c63a4576cf Author: Antonin Stefanutti <anto...@stefanutti.fr> AuthorDate: Thu Jan 24 16:33:16 2019 +0100 Jolokia trait initial implementation Fixes #369 --- docs/traits.adoc | 24 ++++++++++++++ pkg/trait/catalog.go | 5 +++ pkg/trait/deployment.go | 3 -- pkg/trait/jolokia.go | 86 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 3 deletions(-) diff --git a/docs/traits.adoc b/docs/traits.adoc index fc86524..40bac81 100644 --- a/docs/traits.adoc +++ b/docs/traits.adoc @@ -151,6 +151,30 @@ The following is a list of common traits that can be configured by the end users + It's disabled by default. +| jolokia +| Kubernetes, OpenShift +| Activate and configures the Jolokia Java agent. + + + + + It's disabled by default. + +[cols="m,"] +!=== + +! jolokia.port +! The Jolokia endpoint port (default `8778`). + +! jolokia.openshiftSSLAuth +! Configures OpenShift proxy SSL client authentication (only applicable for the OpenShift profile, default `true`) + +! jolokia.options +! A comma-separared list of Jolokia options as defined in https://jolokia.org/reference/html/agents.html#agent-jvm-config[JVM agent configuration options], e.g.: `protocol=https,extendedClientCheck=false` + +! jolokia.randomPassword +! Generates a random password for basic authentication + +!=== + | prometheus | Kubernetes, OpenShift | Exposes the integration with a Service and a ServiceMonitor resources so that the Prometheus endpoint can be scraped. diff --git a/pkg/trait/catalog.go b/pkg/trait/catalog.go index 763aebd..93596e7 100644 --- a/pkg/trait/catalog.go +++ b/pkg/trait/catalog.go @@ -38,6 +38,7 @@ type Catalog struct { tService Trait tRoute Trait tIngress Trait + tJolokia Trait tPrometheus Trait tOwner Trait tImages Trait @@ -61,6 +62,7 @@ func NewCatalog(ctx context.Context, c client.Client) *Catalog { tService: newServiceTrait(), tRoute: newRouteTrait(), tIngress: newIngressTrait(), + tJolokia: newJolokiaTrait(), tPrometheus: newPrometheusTrait(), tOwner: newOwnerTrait(), tImages: newImagesTrait(), @@ -93,6 +95,7 @@ func (c *Catalog) allTraits() []Trait { c.tService, c.tRoute, c.tIngress, + c.tJolokia, c.tPrometheus, c.tOwner, c.tImages, @@ -118,6 +121,7 @@ func (c *Catalog) traitsFor(environment *Environment) []Trait { c.tEnvironment, c.tClasspath, c.tSpringBoot, + c.tJolokia, c.tPrometheus, c.tDeployment, c.tService, @@ -134,6 +138,7 @@ func (c *Catalog) traitsFor(environment *Environment) []Trait { c.tEnvironment, c.tClasspath, c.tSpringBoot, + c.tJolokia, c.tPrometheus, c.tDeployment, c.tService, diff --git a/pkg/trait/deployment.go b/pkg/trait/deployment.go index eee4295..00de1fc 100644 --- a/pkg/trait/deployment.go +++ b/pkg/trait/deployment.go @@ -261,9 +261,6 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment { // has been changed envvar.SetVal(&environment, "CAMEL_K_DIGEST", e.Integration.Status.Digest) - // optimizations - envvar.SetVal(&environment, "AB_JOLOKIA_OFF", True) - // add env vars from traits for _, envVar := range e.EnvVars { envvar.SetVar(&environment, envVar) diff --git a/pkg/trait/jolokia.go b/pkg/trait/jolokia.go new file mode 100644 index 0000000..01c7cfd --- /dev/null +++ b/pkg/trait/jolokia.go @@ -0,0 +1,86 @@ +/* +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 ( + "strconv" + + "github.com/apache/camel-k/pkg/apis/camel/v1alpha1" + "github.com/apache/camel-k/pkg/util/envvar" + "github.com/sirupsen/logrus" +) + +type jolokiaTrait struct { + BaseTrait `property:",squash"` + + OpenShiftSSLAuth *bool `property:"openshiftSSLAuth"` + Options *string `property:"options"` + Port int `property:"port"` + RandomPassword *bool `property:"randomPassword"` +} + +// The Jolokia trait must be executed prior to the deployment trait +// as it mutates environment variables +func newJolokiaTrait() *jolokiaTrait { + return &jolokiaTrait{ + BaseTrait: BaseTrait{ + id: ID("jolokia"), + }, + Port: 8778, + } +} + +func (t *jolokiaTrait) Configure(e *Environment) (bool, error) { + return e.IntegrationInPhase(v1alpha1.IntegrationPhaseDeploying), nil +} + +// Configure the Jolokia Java agent +func (t *jolokiaTrait) Apply(e *Environment) (err error) { + if t.Enabled == nil || !*t.Enabled { + // Deactivate the Jolokia Java agent + // Note: the AB_JOLOKIA_OFF environment variable acts as an option flag + envvar.SetVal(&e.EnvVars, "AB_JOLOKIA_OFF", "true") + return nil + } + + // OpenShift proxy SSL client authentication + if e.DetermineProfile() == v1alpha1.TraitProfileOpenShift { + if t.OpenShiftSSLAuth != nil && !*t.OpenShiftSSLAuth { + envvar.SetVal(&e.EnvVars, "AB_JOLOKIA_AUTH_OPENSHIFT", "false") + } else { + envvar.SetVal(&e.EnvVars, "AB_JOLOKIA_AUTH_OPENSHIFT", "true") + } + } else { + if t.OpenShiftSSLAuth != nil { + logrus.Warn("Jolokia trait property [openshiftSSLAuth] is only applicable for the OpenShift profile!") + } + envvar.SetVal(&e.EnvVars, "AB_JOLOKIA_AUTH_OPENSHIFT", "false") + } + // Jolokia options + if t.Options != nil { + envvar.SetVal(&e.EnvVars, "AB_JOLOKIA_OPTS", *t.Options) + } + // Agent port + envvar.SetVal(&e.EnvVars, "AB_JOLOKIA_PORT", strconv.Itoa(t.Port)) + // Random password + if t.RandomPassword != nil { + envvar.SetVal(&e.EnvVars, "AB_JOLOKIA_PASSWORD_RANDOM", strconv.FormatBool(*t.RandomPassword)) + } + + return nil +}