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/08/05 12:55:14 UTC

(camel-k) branch main updated: feat(trait): Add metricType support to the KEDA trait triggers

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

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


The following commit(s) were added to refs/heads/main by this push:
     new 2dd450478 feat(trait): Add metricType support to the KEDA trait triggers
2dd450478 is described below

commit 2dd450478bc3be72f6639d281c3ca959709383e9
Author: Wojciech_Grazawski <Wo...@ah.nl>
AuthorDate: Wed Aug 5 09:53:01 2026 +0200

    feat(trait): Add metricType support to the KEDA trait triggers
    
    Add an optional trigger-level `metricType` field to the KEDA trait
    (`Utilization`, `AverageValue` or `Value`), mapping to KEDA's
    ScaleTriggers.metricType. Required by the cpu/memory scalers in KEDA
    v2.18+ where the deprecated metadata.type was removed.
    
    Regenerated CRDs, Helm CRDs and API docs.
    
    Co-Authored-By: Claude Opus 4.8 (1M context) <no...@anthropic.com>
---
 docs/modules/ROOT/partials/apis/camel-k-crds.adoc  |  8 +++
 helm/camel-k/crds/camel-k-crds.yaml                | 72 ++++++++++++++++++++++
 pkg/apis/camel/v1/trait/keda.go                    |  5 ++
 pkg/apis/duck/keda/v1alpha1/duck_types.go          |  6 +-
 .../camel.apache.org_integrationplatforms.yaml     | 18 ++++++
 .../camel.apache.org_integrationprofiles.yaml      | 18 ++++++
 .../crd/bases/camel.apache.org_integrations.yaml   | 18 ++++++
 .../config/crd/bases/camel.apache.org_pipes.yaml   | 18 ++++++
 pkg/trait/keda.go                                  |  5 +-
 pkg/trait/keda_test.go                             | 29 +++++++++
 10 files changed, 193 insertions(+), 4 deletions(-)

diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
index 22f3ae244..ac08ea3c1 100644
--- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
+++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
@@ -8362,6 +8362,14 @@ string
 
 The autoscaler type.
 
+|`metricType` +
+string
+|
+*(Optional)*
+
+The metric type for this trigger, mapping to KEDA's trigger-level `metricType`
+(`Utilization`, `AverageValue` or `Value`).
+
 |`metadata` +
 map[string]string
 |
diff --git a/helm/camel-k/crds/camel-k-crds.yaml b/helm/camel-k/crds/camel-k-crds.yaml
index 9328938d3..6930c372c 100644
--- a/helm/camel-k/crds/camel-k-crds.yaml
+++ b/helm/camel-k/crds/camel-k-crds.yaml
@@ -5015,6 +5015,15 @@ spec:
                               description: The trigger metadata (see Keda documentation
                                 to learn how to fill for each type).
                               type: object
+                            metricType:
+                              description: |-
+                                The metric type for this trigger, mapping to KEDA's trigger-level `metricType`
+                                (`Utilization`, `AverageValue` or `Value`).
+                              enum:
+                              - Utilization
+                              - AverageValue
+                              - Value
+                              type: string
                             secrets:
                               description: The secrets mapping to use. Keda allows
                                 the possibility to use values coming from different
@@ -7559,6 +7568,15 @@ spec:
                               description: The trigger metadata (see Keda documentation
                                 to learn how to fill for each type).
                               type: object
+                            metricType:
+                              description: |-
+                                The metric type for this trigger, mapping to KEDA's trigger-level `metricType`
+                                (`Utilization`, `AverageValue` or `Value`).
+                              enum:
+                              - Utilization
+                              - AverageValue
+                              - Value
+                              type: string
                             secrets:
                               description: The secrets mapping to use. Keda allows
                                 the possibility to use values coming from different
@@ -9997,6 +10015,15 @@ spec:
                               description: The trigger metadata (see Keda documentation
                                 to learn how to fill for each type).
                               type: object
+                            metricType:
+                              description: |-
+                                The metric type for this trigger, mapping to KEDA's trigger-level `metricType`
+                                (`Utilization`, `AverageValue` or `Value`).
+                              enum:
+                              - Utilization
+                              - AverageValue
+                              - Value
+                              type: string
                             secrets:
                               description: The secrets mapping to use. Keda allows
                                 the possibility to use values coming from different
@@ -12421,6 +12448,15 @@ spec:
                               description: The trigger metadata (see Keda documentation
                                 to learn how to fill for each type).
                               type: object
+                            metricType:
+                              description: |-
+                                The metric type for this trigger, mapping to KEDA's trigger-level `metricType`
+                                (`Utilization`, `AverageValue` or `Value`).
+                              enum:
+                              - Utilization
+                              - AverageValue
+                              - Value
+                              type: string
                             secrets:
                               description: The secrets mapping to use. Keda allows
                                 the possibility to use values coming from different
@@ -21707,6 +21743,15 @@ spec:
                               description: The trigger metadata (see Keda documentation
                                 to learn how to fill for each type).
                               type: object
+                            metricType:
+                              description: |-
+                                The metric type for this trigger, mapping to KEDA's trigger-level `metricType`
+                                (`Utilization`, `AverageValue` or `Value`).
+                              enum:
+                              - Utilization
+                              - AverageValue
+                              - Value
+                              type: string
                             secrets:
                               description: The secrets mapping to use. Keda allows
                                 the possibility to use values coming from different
@@ -24092,6 +24137,15 @@ spec:
                               description: The trigger metadata (see Keda documentation
                                 to learn how to fill for each type).
                               type: object
+                            metricType:
+                              description: |-
+                                The metric type for this trigger, mapping to KEDA's trigger-level `metricType`
+                                (`Utilization`, `AverageValue` or `Value`).
+                              enum:
+                              - Utilization
+                              - AverageValue
+                              - Value
+                              type: string
                             secrets:
                               description: The secrets mapping to use. Keda allows
                                 the possibility to use values coming from different
@@ -34744,6 +34798,15 @@ spec:
                                   description: The trigger metadata (see Keda documentation
                                     to learn how to fill for each type).
                                   type: object
+                                metricType:
+                                  description: |-
+                                    The metric type for this trigger, mapping to KEDA's trigger-level `metricType`
+                                    (`Utilization`, `AverageValue` or `Value`).
+                                  enum:
+                                  - Utilization
+                                  - AverageValue
+                                  - Value
+                                  type: string
                                 secrets:
                                   description: The secrets mapping to use. Keda allows
                                     the possibility to use values coming from different
@@ -37048,6 +37111,15 @@ spec:
                               description: The trigger metadata (see Keda documentation
                                 to learn how to fill for each type).
                               type: object
+                            metricType:
+                              description: |-
+                                The metric type for this trigger, mapping to KEDA's trigger-level `metricType`
+                                (`Utilization`, `AverageValue` or `Value`).
+                              enum:
+                              - Utilization
+                              - AverageValue
+                              - Value
+                              type: string
                             secrets:
                               description: The secrets mapping to use. Keda allows
                                 the possibility to use values coming from different
diff --git a/pkg/apis/camel/v1/trait/keda.go b/pkg/apis/camel/v1/trait/keda.go
index b20b6a974..a56bdf69b 100644
--- a/pkg/apis/camel/v1/trait/keda.go
+++ b/pkg/apis/camel/v1/trait/keda.go
@@ -51,6 +51,11 @@ type KedaTrait struct {
 type KedaTrigger struct {
 	// The autoscaler type.
 	Type string `json:"type,omitempty" property:"type"`
+	// The metric type for this trigger, mapping to KEDA's trigger-level `metricType`
+	// (`Utilization`, `AverageValue` or `Value`).
+	// +kubebuilder:validation:Enum=Utilization;AverageValue;Value
+	// +optional
+	MetricType string `json:"metricType,omitempty" property:"metric-type"`
 	// The trigger metadata (see Keda documentation to learn how to fill for each type).
 	Metadata map[string]string `json:"metadata,omitempty" property:"metadata"`
 	// The secrets mapping to use. Keda allows the possibility to use values coming from different secrets.
diff --git a/pkg/apis/duck/keda/v1alpha1/duck_types.go b/pkg/apis/duck/keda/v1alpha1/duck_types.go
index 112e700df..e281578a5 100644
--- a/pkg/apis/duck/keda/v1alpha1/duck_types.go
+++ b/pkg/apis/duck/keda/v1alpha1/duck_types.go
@@ -56,8 +56,10 @@ type ScaledObjectSpec struct {
 type ScaleTriggers struct {
 	Type string `json:"type"`
 	// +optional
-	Name     string            `json:"name,omitempty"`
-	Metadata map[string]string `json:"metadata"`
+	Name string `json:"name,omitempty"`
+	// +optional
+	MetricType string            `json:"metricType,omitempty"`
+	Metadata   map[string]string `json:"metadata"`
 	// +optional
 	AuthenticationRef *ScaledObjectAuthRef `json:"authenticationRef,omitempty"`
 	// +optional
diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml
index f1b0c2b26..791c2ec55 100644
--- a/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml
+++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml
@@ -1709,6 +1709,15 @@ spec:
                               description: The trigger metadata (see Keda documentation
                                 to learn how to fill for each type).
                               type: object
+                            metricType:
+                              description: |-
+                                The metric type for this trigger, mapping to KEDA's trigger-level `metricType`
+                                (`Utilization`, `AverageValue` or `Value`).
+                              enum:
+                              - Utilization
+                              - AverageValue
+                              - Value
+                              type: string
                             secrets:
                               description: The secrets mapping to use. Keda allows
                                 the possibility to use values coming from different
@@ -4253,6 +4262,15 @@ spec:
                               description: The trigger metadata (see Keda documentation
                                 to learn how to fill for each type).
                               type: object
+                            metricType:
+                              description: |-
+                                The metric type for this trigger, mapping to KEDA's trigger-level `metricType`
+                                (`Utilization`, `AverageValue` or `Value`).
+                              enum:
+                              - Utilization
+                              - AverageValue
+                              - Value
+                              type: string
                             secrets:
                               description: The secrets mapping to use. Keda allows
                                 the possibility to use values coming from different
diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml
index 80852a2e7..6925e9bfa 100644
--- a/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml
+++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml
@@ -1567,6 +1567,15 @@ spec:
                               description: The trigger metadata (see Keda documentation
                                 to learn how to fill for each type).
                               type: object
+                            metricType:
+                              description: |-
+                                The metric type for this trigger, mapping to KEDA's trigger-level `metricType`
+                                (`Utilization`, `AverageValue` or `Value`).
+                              enum:
+                              - Utilization
+                              - AverageValue
+                              - Value
+                              type: string
                             secrets:
                               description: The secrets mapping to use. Keda allows
                                 the possibility to use values coming from different
@@ -3991,6 +4000,15 @@ spec:
                               description: The trigger metadata (see Keda documentation
                                 to learn how to fill for each type).
                               type: object
+                            metricType:
+                              description: |-
+                                The metric type for this trigger, mapping to KEDA's trigger-level `metricType`
+                                (`Utilization`, `AverageValue` or `Value`).
+                              enum:
+                              - Utilization
+                              - AverageValue
+                              - Value
+                              type: string
                             secrets:
                               description: The secrets mapping to use. Keda allows
                                 the possibility to use values coming from different
diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml
index 710abc0dc..123984795 100644
--- a/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml
+++ b/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml
@@ -8418,6 +8418,15 @@ spec:
                               description: The trigger metadata (see Keda documentation
                                 to learn how to fill for each type).
                               type: object
+                            metricType:
+                              description: |-
+                                The metric type for this trigger, mapping to KEDA's trigger-level `metricType`
+                                (`Utilization`, `AverageValue` or `Value`).
+                              enum:
+                              - Utilization
+                              - AverageValue
+                              - Value
+                              type: string
                             secrets:
                               description: The secrets mapping to use. Keda allows
                                 the possibility to use values coming from different
@@ -10803,6 +10812,15 @@ spec:
                               description: The trigger metadata (see Keda documentation
                                 to learn how to fill for each type).
                               type: object
+                            metricType:
+                              description: |-
+                                The metric type for this trigger, mapping to KEDA's trigger-level `metricType`
+                                (`Utilization`, `AverageValue` or `Value`).
+                              enum:
+                              - Utilization
+                              - AverageValue
+                              - Value
+                              type: string
                             secrets:
                               description: The secrets mapping to use. Keda allows
                                 the possibility to use values coming from different
diff --git a/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml b/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml
index 56e9c3e4e..4a9c4e2ed 100644
--- a/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml
+++ b/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml
@@ -8476,6 +8476,15 @@ spec:
                                   description: The trigger metadata (see Keda documentation
                                     to learn how to fill for each type).
                                   type: object
+                                metricType:
+                                  description: |-
+                                    The metric type for this trigger, mapping to KEDA's trigger-level `metricType`
+                                    (`Utilization`, `AverageValue` or `Value`).
+                                  enum:
+                                  - Utilization
+                                  - AverageValue
+                                  - Value
+                                  type: string
                                 secrets:
                                   description: The secrets mapping to use. Keda allows
                                     the possibility to use values coming from different
@@ -10780,6 +10789,15 @@ spec:
                               description: The trigger metadata (see Keda documentation
                                 to learn how to fill for each type).
                               type: object
+                            metricType:
+                              description: |-
+                                The metric type for this trigger, mapping to KEDA's trigger-level `metricType`
+                                (`Utilization`, `AverageValue` or `Value`).
+                              enum:
+                              - Utilization
+                              - AverageValue
+                              - Value
+                              type: string
                             secrets:
                               description: The secrets mapping to use. Keda allows
                                 the possibility to use values coming from different
diff --git a/pkg/trait/keda.go b/pkg/trait/keda.go
index 66074e4b8..36ee9c621 100644
--- a/pkg/trait/keda.go
+++ b/pkg/trait/keda.go
@@ -97,8 +97,9 @@ func (t *kedaTrait) populateTriggers(itName, itNamespace string) ([]v1alpha1.Sca
 	triggers := make([]v1alpha1.ScaleTriggers, 0, len(t.Triggers))
 	for _, trigger := range t.Triggers {
 		scaleTrigger := v1alpha1.ScaleTriggers{
-			Type:     trigger.Type,
-			Metadata: trigger.Metadata,
+			Type:       trigger.Type,
+			MetricType: trigger.MetricType,
+			Metadata:   trigger.Metadata,
 		}
 		if trigger.Secrets != nil {
 			triggerAuth := populateTriggerAuth(trigger.Secrets, itName, itNamespace, trigger.Type)
diff --git a/pkg/trait/keda_test.go b/pkg/trait/keda_test.go
index 6ba20a8d4..606c315b8 100644
--- a/pkg/trait/keda_test.go
+++ b/pkg/trait/keda_test.go
@@ -57,6 +57,35 @@ func TestKeda(t *testing.T) {
 	assert.Equal(t, "10", scaledObject.Spec.Triggers[0].Metadata["lagThreshold"])
 }
 
+func TestKedaMetricType(t *testing.T) {
+	environment := nominalEnv(t)
+	// A cpu trigger with a trigger-level metricType: KEDA v2.18+ requires this for
+	// the cpu/memory scalers (the deprecated metadata.type was removed).
+	environment.Integration.Spec.Traits.Keda.Triggers = []traitv1.KedaTrigger{
+		{
+			Type:       "cpu",
+			MetricType: "Utilization",
+			Metadata: map[string]string{
+				"value": "70",
+			},
+		},
+	}
+	traitCatalog := environment.Catalog
+
+	_, _, err := traitCatalog.apply(&environment)
+
+	require.NoError(t, err)
+	assert.NotEmpty(t, environment.ExecutedTraits)
+	assert.NotNil(t, environment.GetTrait("keda"))
+
+	scaledObject := getKedaScaledObject(environment.Resources)
+	require.NotNil(t, scaledObject)
+	require.Len(t, scaledObject.Spec.Triggers, 1)
+	assert.Equal(t, "cpu", scaledObject.Spec.Triggers[0].Type)
+	assert.Equal(t, "Utilization", scaledObject.Spec.Triggers[0].MetricType)
+	assert.Equal(t, "70", scaledObject.Spec.Triggers[0].Metadata["value"])
+}
+
 func TestKedaAutoDiscovery(t *testing.T) {
 	tests := []struct {
 		name           string