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
commit 473bbd588cb904b092ae18778f9e4b59a2dcdda8 Author: Dhvani Dave <[email protected]> AuthorDate: Fri Oct 23 03:26:47 2026 -0400 review changes (#6890) --- .../ROOT/pages/contributing/keda-scaler.adoc | 2 +- e2e/arkmq/arkmq_keda_test.go | 37 ++++++++++++++++++++++ e2e/arkmq/files/keda-it-arkmq-to-log-auto.yaml | 2 +- pkg/trait/keda.go | 20 ------------ pkg/trait/keda/mapper.go | 11 +------ pkg/trait/keda/scalers/artemis.go | 2 +- pkg/trait/keda/scalers/artemis_test.go | 2 +- pkg/trait/trait.go | 20 ++++++++++++ 8 files changed, 62 insertions(+), 34 deletions(-) diff --git a/docs/modules/ROOT/pages/contributing/keda-scaler.adoc b/docs/modules/ROOT/pages/contributing/keda-scaler.adoc index 92f040176..84ecfbf95 100644 --- a/docs/modules/ROOT/pages/contributing/keda-scaler.adoc +++ b/docs/modules/ROOT/pages/contributing/keda-scaler.adoc @@ -36,7 +36,7 @@ type ScaleMapper interface { ---- `Component` returns the Camel component name used as the registry key. -`Map` receives the path part of the Camel URI, its decoded query parameters, and the Integration `camel.component.<component>.*` properties with that prefix removed, and returns the corresponding KEDA scaler type and metadata. +`Map` receives the path part of the Camel URI, its decoded query parameters, and the Integration properties, and returns the corresponding KEDA scaler type and metadata. Each implementation registers itself by calling `keda.Register` from an `init` function. The blank import of `pkg/trait/keda/scalers` in `pkg/trait/keda.go` ensures that these registration functions run when the trait package is loaded. diff --git a/e2e/arkmq/arkmq_keda_test.go b/e2e/arkmq/arkmq_keda_test.go index d782c393e..b47143aa8 100644 --- a/e2e/arkmq/arkmq_keda_test.go +++ b/e2e/arkmq/arkmq_keda_test.go @@ -25,8 +25,11 @@ import ( "testing" . "github.com/onsi/gomega" + "github.com/onsi/gomega/gstruct" + corev1 "k8s.io/api/core/v1" . "github.com/apache/camel-k/v2/e2e/support" + v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" ) func TestArkMQKedaAutoDiscovery(t *testing.T) { @@ -49,6 +52,23 @@ func TestArkMQKedaAutoDiscovery(t *testing.T) { // Merged from autoMetadata g.Expect(scaledObj.Spec.Triggers[0].Metadata["brokerName"]).To(Equal("amq-broker")) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, integrationName, v1.IntegrationConditionReady), TestTimeoutMedium). + Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, integrationName), TestTimeoutShort). + Should(gstruct.PointTo(BeNumerically("==", 1))) + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, integrationName), TestTimeoutShort). + Should(gstruct.PointTo(BeNumerically("==", 0))) + producerName := "timer-to-arkmq" + ExpectExecSucceed(t, g, Kubectl("apply", "-f", "files/timer-to-arkmq.yaml")) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, producerName, v1.IntegrationConditionReady), TestTimeoutMedium). + Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, integrationName), TestTimeoutShort). + Should(gstruct.PointTo(BeNumerically("==", 1))) + g.Eventually(IntegrationLogs(t, ctx, ns, integrationName)).Should(ContainSubstring("Body is null")) + ExpectExecSucceed(t, g, Kubectl("delete", "pipe", producerName, "-n", ns)) + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, integrationName), TestTimeoutMedium). + Should(gstruct.PointTo(BeNumerically("==", 0))) + ExpectExecSucceed(t, g, Kubectl("delete", "pipe", integrationName, "-n", ns)) }) }, "arkmq") @@ -72,6 +92,23 @@ func TestArkMQKedaAutoDiscoveryIntegration(t *testing.T) { g.Expect(scaledObj.Spec.Triggers[0].Metadata["managementEndpoint"]).To(Equal("my-broker-hdls-svc.arkmq.svc:8161")) g.Expect(scaledObj.Spec.Triggers[0].Metadata["brokerName"]).To(Equal("amq-broker")) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, integrationName, v1.IntegrationConditionReady), TestTimeoutMedium). + Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, integrationName), TestTimeoutShort). + Should(gstruct.PointTo(BeNumerically("==", 1))) + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, integrationName), TestTimeoutShort). + Should(gstruct.PointTo(BeNumerically("==", 0))) + producerName := "timer-to-arkmq" + ExpectExecSucceed(t, g, Kubectl("apply", "-f", "files/timer-to-arkmq.yaml")) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, producerName, v1.IntegrationConditionReady), TestTimeoutMedium). + Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, integrationName), TestTimeoutShort). + Should(gstruct.PointTo(BeNumerically("==", 1))) + g.Eventually(IntegrationLogs(t, ctx, ns, integrationName)).Should(ContainSubstring("Body is null")) + ExpectExecSucceed(t, g, Kubectl("delete", "pipe", producerName, "-n", ns)) + g.Eventually(IntegrationStatusReplicas(t, ctx, ns, integrationName), TestTimeoutMedium). + Should(gstruct.PointTo(BeNumerically("==", 0))) + ExpectExecSucceed(t, g, Kubectl("delete", "it", integrationName, "-n", ns)) }) }, "arkmq") diff --git a/e2e/arkmq/files/keda-it-arkmq-to-log-auto.yaml b/e2e/arkmq/files/keda-it-arkmq-to-log-auto.yaml index 003a18232..cf9118e08 100644 --- a/e2e/arkmq/files/keda-it-arkmq-to-log-auto.yaml +++ b/e2e/arkmq/files/keda-it-arkmq-to-log-auto.yaml @@ -24,7 +24,7 @@ spec: sources: - content: | from("amqp:queue:my-queue") - .log("${body}"); + .to("log:info"); name: routes.java traits: camel: diff --git a/pkg/trait/keda.go b/pkg/trait/keda.go index 27a699de4..ea7d89923 100644 --- a/pkg/trait/keda.go +++ b/pkg/trait/keda.go @@ -28,7 +28,6 @@ import ( "github.com/apache/camel-k/v2/pkg/metadata" kedamapper "github.com/apache/camel-k/v2/pkg/trait/keda" _ "github.com/apache/camel-k/v2/pkg/trait/keda/scalers" - "github.com/apache/camel-k/v2/pkg/util/property" corev1 "k8s.io/api/core/v1" "k8s.io/utils/ptr" ) @@ -185,22 +184,3 @@ func (t *kedaTrait) autoDiscoverTriggers(e *Environment) error { return nil } - -func integrationProperties(e *Environment) map[string]string { - props := make(map[string]string) - for _, prop := range e.collectConfigurationPairs("property") { - props[prop.Name] = prop.Value - } - if ct := e.Catalog.GetTrait(camelTraitID); ct != nil { - if camel, ok := ct.(*camelTrait); ok { - for _, prop := range camel.Properties { - k, v := property.SplitPropertyFileEntry(prop) - if k != "" { - props[k] = v - } - } - } - } - - return props -} diff --git a/pkg/trait/keda/mapper.go b/pkg/trait/keda/mapper.go index 27b6952bd..50037170d 100644 --- a/pkg/trait/keda/mapper.go +++ b/pkg/trait/keda/mapper.go @@ -18,8 +18,6 @@ limitations under the License. package keda import ( - "strings" - traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" ) @@ -53,14 +51,7 @@ func MapToKedaTrigger(rawURI string, props map[string]string) (*traitv1.KedaTrig if !found { return nil, nil } - prefix := "camel.component." + scheme + "." - componentProps := map[string]string{} - for k, v := range props { - if strings.HasPrefix(k, prefix) { - componentProps[strings.TrimPrefix(k, prefix)] = v - } - } - kedaType, metadata := mapper.Map(pathValue, params, componentProps) + kedaType, metadata := mapper.Map(pathValue, params, props) return &traitv1.KedaTrigger{ Type: kedaType, diff --git a/pkg/trait/keda/scalers/artemis.go b/pkg/trait/keda/scalers/artemis.go index 262179e53..03f787180 100644 --- a/pkg/trait/keda/scalers/artemis.go +++ b/pkg/trait/keda/scalers/artemis.go @@ -44,7 +44,7 @@ func (a *ArtemisScaler) Map(pathValue string, params map[string]string, props ma // For anycast queues created by ArkMQ, the address name matches the queue name. metadata["brokerAddress"] = queueName } - if brokerURL, ok := props["broker-url"]; ok { + if brokerURL, ok := props["camel.component.amqp.broker-url"]; ok { if u, err := url.Parse(brokerURL); err == nil && u.Hostname() != "" { metadata["managementEndpoint"] = net.JoinHostPort(u.Hostname(), "8161") } diff --git a/pkg/trait/keda/scalers/artemis_test.go b/pkg/trait/keda/scalers/artemis_test.go index c295eb466..92b143b12 100644 --- a/pkg/trait/keda/scalers/artemis_test.go +++ b/pkg/trait/keda/scalers/artemis_test.go @@ -74,7 +74,7 @@ func TestArtemisScalerMap(t *testing.T) { name: "broker url sets management endpoint", pathValue: "queue:orders", params: map[string]string{}, - props: map[string]string{"broker-url": "amqp://my-broker-hdls-svc.arkmq.svc:61616"}, + props: map[string]string{"camel.component.amqp.broker-url": "amqp://my-broker-hdls-svc.arkmq.svc:61616"}, expectedType: "artemis-queue", expectedMeta: map[string]string{ "queueName": "orders", diff --git a/pkg/trait/trait.go b/pkg/trait/trait.go index 301dbebc9..1f39477c9 100644 --- a/pkg/trait/trait.go +++ b/pkg/trait/trait.go @@ -30,6 +30,7 @@ import ( "github.com/apache/camel-k/v2/pkg/platform" "github.com/apache/camel-k/v2/pkg/util/kubernetes" "github.com/apache/camel-k/v2/pkg/util/log" + "github.com/apache/camel-k/v2/pkg/util/property" ctrl "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -154,3 +155,22 @@ func newEnvironment(ctx context.Context, c client.Client, integration *v1.Integr return &env, nil } + +func integrationProperties(e *Environment) map[string]string { + props := make(map[string]string) + for _, prop := range e.collectConfigurationPairs("property") { + props[prop.Name] = prop.Value + } + if ct := e.Catalog.GetTrait(camelTraitID); ct != nil { + if camel, ok := ct.(*camelTrait); ok { + for _, prop := range camel.Properties { + k, v := property.SplitPropertyFileEntry(prop) + if k != "" { + props[k] = v + } + } + } + } + + return props +}
