You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2026/02/18 11:59:34 UTC

(camel-k) 01/03: feat: enable Camel Dashboard monitoring

This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 994822d973d3ab3b2d0dd79eb2e501deab750f05
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Tue Feb 17 12:51:24 2026 +0100

    feat: enable Camel Dashboard monitoring
    
    This change is required to include an operator env var which we can use to enable the monitoring from Camel Dashboard project
    
    Closes https://github.com/camel-tooling/camel-dashboard-operator/issues/90
---
 .../ROOT/pages/installation/advanced/advanced.adoc |  4 +++
 .../config/manager/operator-deployment.yaml        |  5 +++
 pkg/trait/cron.go                                  |  9 +++--
 pkg/trait/deployment.go                            |  9 +++--
 pkg/trait/deployment_test.go                       | 14 +++++++-
 pkg/trait/knative_service.go                       | 22 ++++++------
 pkg/util/kubernetes/labels.go                      | 41 ++++++++++++++++++++++
 7 files changed, 82 insertions(+), 22 deletions(-)

diff --git a/docs/modules/ROOT/pages/installation/advanced/advanced.adoc b/docs/modules/ROOT/pages/installation/advanced/advanced.adoc
index 4ee021a18..b648e9dba 100644
--- a/docs/modules/ROOT/pages/installation/advanced/advanced.adoc
+++ b/docs/modules/ROOT/pages/installation/advanced/advanced.adoc
@@ -67,6 +67,10 @@ The following environment variables can be configured on the operator Deployment
 |`false`
 |When set to `true`, enables synthetic Integration support for managing external workloads.
 
+|`CAMEL_DASHBOARD_APP_LABEL`
+|`camel.apache.org/app`
+|If it exists, the operator add this label beside regular Camel K labels in order to let the Camel Dashboard discover and monitor the application.
+
 |`LOG_LEVEL`
 |`info`
 |The log level for the operator. Valid values: `debug`, `info`, `warn`, `error`.
diff --git a/pkg/resources/config/manager/operator-deployment.yaml b/pkg/resources/config/manager/operator-deployment.yaml
index e95501896..470230b77 100644
--- a/pkg/resources/config/manager/operator-deployment.yaml
+++ b/pkg/resources/config/manager/operator-deployment.yaml
@@ -72,6 +72,11 @@ spec:
               valueFrom:
                 fieldRef:
                   fieldPath: metadata.namespace
+            # Used to automatically enable Camel Dashboard project monitoring
+            # Keep the default value or change it to the same label used by the dashboard
+            # Note: remove the variable to disable the feature.
+            - name: CAMEL_DASHBOARD_APP_LABEL
+              value: "camel.apache.org/app"
           livenessProbe:
             httpGet:
               path: /healthz
diff --git a/pkg/trait/cron.go b/pkg/trait/cron.go
index 7c87348c2..dc9088058 100644
--- a/pkg/trait/cron.go
+++ b/pkg/trait/cron.go
@@ -34,6 +34,7 @@ import (
 	traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait"
 	"github.com/apache/camel-k/v2/pkg/metadata"
 	"github.com/apache/camel-k/v2/pkg/util"
+	"github.com/apache/camel-k/v2/pkg/util/kubernetes"
 	"github.com/apache/camel-k/v2/pkg/util/source"
 	"github.com/apache/camel-k/v2/pkg/util/uri"
 )
@@ -261,11 +262,9 @@ func (t *cronTrait) getCronJobFor(e *Environment) *batchv1.CronJob {
 			APIVersion: batchv1.SchemeGroupVersion.String(),
 		},
 		ObjectMeta: metav1.ObjectMeta{
-			Name:      e.Integration.Name,
-			Namespace: e.Integration.Namespace,
-			Labels: map[string]string{
-				v1.IntegrationLabel: e.Integration.Name,
-			},
+			Name:        e.Integration.Name,
+			Namespace:   e.Integration.Namespace,
+			Labels:      kubernetes.DeploymentLabels(e.Integration.Name),
 			Annotations: e.Integration.Annotations,
 		},
 		Spec: batchv1.CronJobSpec{
diff --git a/pkg/trait/deployment.go b/pkg/trait/deployment.go
index 2c5ff764b..c4920f763 100644
--- a/pkg/trait/deployment.go
+++ b/pkg/trait/deployment.go
@@ -28,6 +28,7 @@ import (
 
 	v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
 	traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait"
+	"github.com/apache/camel-k/v2/pkg/util/kubernetes"
 )
 
 const (
@@ -132,11 +133,9 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment {
 			APIVersion: appsv1.SchemeGroupVersion.String(),
 		},
 		ObjectMeta: metav1.ObjectMeta{
-			Name:      e.Integration.Name,
-			Namespace: e.Integration.Namespace,
-			Labels: map[string]string{
-				v1.IntegrationLabel: e.Integration.Name,
-			},
+			Name:        e.Integration.Name,
+			Namespace:   e.Integration.Namespace,
+			Labels:      kubernetes.DeploymentLabels(e.Integration.Name),
 			Annotations: annotations,
 		},
 		Spec: appsv1.DeploymentSpec{
diff --git a/pkg/trait/deployment_test.go b/pkg/trait/deployment_test.go
index 1eb97fd63..a48740940 100644
--- a/pkg/trait/deployment_test.go
+++ b/pkg/trait/deployment_test.go
@@ -136,7 +136,7 @@ func TestApplyDeploymentTraitWithProgressDeadline(t *testing.T) {
 	assert.Equal(t, int32(120), *deployment.Spec.ProgressDeadlineSeconds)
 }
 
-func TestApplyDeploymentTraitWitRecresteStrategy(t *testing.T) {
+func TestApplyDeploymentTraitWitRecreateStrategy(t *testing.T) {
 	deploymentTrait, environment := createNominalDeploymentTest()
 	maxSurge := intstr.FromInt(10)
 
@@ -323,3 +323,15 @@ func createNominalDeploymentTest() (*deploymentTrait, *Environment) {
 
 	return trait, environment
 }
+
+func TestApplyDeploymentWithCamelDashboardLabel(t *testing.T) {
+	t.Setenv(kubernetes.CamelDashboardAppLabelEnvVar, "my-dashboard-label")
+
+	deploymentTrait, environment := createNominalDeploymentTest()
+	err := deploymentTrait.Apply(environment)
+	require.NoError(t, err)
+
+	deployment := environment.Resources.GetDeployment(func(deployment *appsv1.Deployment) bool { return true })
+	assert.NotNil(t, deployment)
+	assert.Equal(t, "integration-name", deployment.Labels["my-dashboard-label"])
+}
diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go
index 224f5b1cb..e0f1e88f9 100644
--- a/pkg/trait/knative_service.go
+++ b/pkg/trait/knative_service.go
@@ -33,6 +33,7 @@ import (
 	"github.com/apache/camel-k/v2/pkg/metadata"
 	"github.com/apache/camel-k/v2/pkg/util/boolean"
 	"github.com/apache/camel-k/v2/pkg/util/knative"
+	"github.com/apache/camel-k/v2/pkg/util/kubernetes"
 )
 
 const (
@@ -209,17 +210,16 @@ func (t *knativeServiceTrait) getServiceFor(e *Environment) (*serving.Service, e
 		revisionAnnotations[knativeServingMaxScaleAnnotation] = strconv.Itoa(*t.MaxScale)
 	}
 
-	serviceLabels := map[string]string{
-		v1.IntegrationLabel: e.Integration.Name,
-		// Make sure the Eventing webhook will select the source resource,
-		// in order to inject the sink information.
-		// This is necessary for Knative environments, that are configured
-		// with SINK_BINDING_SELECTION_MODE=inclusion.
-		// See:
-		// - https://knative.dev/v1.3-docs/eventing/custom-event-source/sinkbinding/create-a-sinkbinding/#optional-choose-sinkbinding-namespace-selection-behavior
-		// - https://github.com/knative/operator/blob/release-1.2/docs/configuration.md#specsinkbindingselectionmode
-		"bindings.knative.dev/include": boolean.TrueString,
-	}
+	serviceLabels := kubernetes.DeploymentLabels(e.Integration.Name)
+	// Make sure the Eventing webhook will select the source resource,
+	// in order to inject the sink information.
+	// This is necessary for Knative environments, that are configured
+	// with SINK_BINDING_SELECTION_MODE=inclusion.
+	// See:
+	// - https://knative.dev/v1.3-docs/eventing/custom-event-source/sinkbinding/create-a-sinkbinding/#optional-choose-sinkbinding-namespace-selection-behavior
+	// - https://github.com/knative/operator/blob/release-1.2/docs/configuration.md#specsinkbindingselectionmode
+	serviceLabels["bindings.knative.dev/include"] = boolean.TrueString
+
 	if t.Visibility != "" {
 		serviceLabels[knativeServingVisibilityLabel] = t.Visibility
 	}
diff --git a/pkg/util/kubernetes/labels.go b/pkg/util/kubernetes/labels.go
new file mode 100644
index 000000000..47fe3d213
--- /dev/null
+++ b/pkg/util/kubernetes/labels.go
@@ -0,0 +1,41 @@
+/*
+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 kubernetes
+
+import (
+	"os"
+
+	v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
+)
+
+const CamelDashboardAppLabelEnvVar = "CAMEL_DASHBOARD_APP_LABEL"
+
+// DeploymentLabels returns the fixed labels assigned to each Camel workload.
+func DeploymentLabels(integrationName string) map[string]string {
+	labels := map[string]string{
+		// Required by Camel K
+		v1.IntegrationLabel: integrationName,
+	}
+	camelDashboardLabel, ok := os.LookupEnv(CamelDashboardAppLabelEnvVar)
+	if ok && camelDashboardLabel != "" {
+		// Will automatically enable App discovery by Camel Dashboard
+		labels[camelDashboardLabel] = integrationName
+	}
+
+	return labels
+}