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 6c6c27ed0 test(e2e): cover Knative channel eventing (#6975)
6c6c27ed0 is described below
commit 6c6c27ed0e8ecc8fe6d2fa9f4a0a8f23eb094482
Author: Sanjeev Kumar <[email protected]>
AuthorDate: Thu Nov 19 20:02:32 2026 +0530
test(e2e): cover Knative channel eventing (#6975)
* test(e2e): cover Knative channel eventing
* test(e2e): add Knative channel fixture
* test(e2e): add Knative channel consumer route
* test(e2e): add Knative channel producer route
* test(e2e): wait for Knative channel subscription
* test(e2e): decode Knative channel event body
* test(e2e): disable deprecated Knative trait
* test(e2e): add Knative channel subscription fixture
* test(e2e): configure Knative component without deprecated trait
* test(e2e): use supported env flag for Knative config
* test(e2e): fix Knative channel eventing coverage
---
e2e/knative/files/knative-channel-consumer.yaml | 25 ++++
e2e/knative/files/knative-channel-producer.yaml | 24 ++++
.../files/knative-channel-subscription.yaml | 31 +++++
e2e/knative/files/knative-channel.yaml | 20 +++
e2e/knative/knative_eventing_test.go | 147 +++++++++++++++++++++
5 files changed, 247 insertions(+)
diff --git a/e2e/knative/files/knative-channel-consumer.yaml
b/e2e/knative/files/knative-channel-consumer.yaml
new file mode 100644
index 000000000..a02e0fedd
--- /dev/null
+++ b/e2e/knative/files/knative-channel-consumer.yaml
@@ -0,0 +1,25 @@
+# camel-k: language=yaml
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+
+- from:
+ uri: knative:channel/camel-k-eventing
+ steps:
+ - convertBodyTo:
+ type: java.lang.String
+ - log:
+ message: "Received Knative event: ${body}"
diff --git a/e2e/knative/files/knative-channel-producer.yaml
b/e2e/knative/files/knative-channel-producer.yaml
new file mode 100644
index 000000000..a60560064
--- /dev/null
+++ b/e2e/knative/files/knative-channel-producer.yaml
@@ -0,0 +1,24 @@
+# camel-k: language=yaml
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+
+- from:
+ uri: timer:tick?delay=1000&repeatCount=1
+ steps:
+ - setBody:
+ constant: camel-k-knative-eventing-e2e
+ - to: knative:channel/camel-k-eventing
diff --git a/e2e/knative/files/knative-channel-subscription.yaml
b/e2e/knative/files/knative-channel-subscription.yaml
new file mode 100644
index 000000000..fb05c4fad
--- /dev/null
+++ b/e2e/knative/files/knative-channel-subscription.yaml
@@ -0,0 +1,31 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+apiVersion: messaging.knative.dev/v1
+kind: Subscription
+metadata:
+ name: camel-k-eventing-knative-channel-consumer
+spec:
+ channel:
+ apiVersion: messaging.knative.dev/v1
+ kind: Channel
+ name: camel-k-eventing
+ subscriber:
+ ref:
+ apiVersion: v1
+ kind: Service
+ name: knative-channel-consumer
+ uri: /channels/camel-k-eventing
diff --git a/e2e/knative/files/knative-channel.yaml
b/e2e/knative/files/knative-channel.yaml
new file mode 100644
index 000000000..896d55a47
--- /dev/null
+++ b/e2e/knative/files/knative-channel.yaml
@@ -0,0 +1,20 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+apiVersion: messaging.knative.dev/v1
+kind: Channel
+metadata:
+ name: camel-k-eventing
diff --git a/e2e/knative/knative_eventing_test.go
b/e2e/knative/knative_eventing_test.go
new file mode 100644
index 000000000..f86e9a5b8
--- /dev/null
+++ b/e2e/knative/knative_eventing_test.go
@@ -0,0 +1,147 @@
+//go:build integration
+// +build integration
+
+// To enable compilation of this file in Goland, go to "Settings -> Go ->
Vendoring & Build Tags -> Custom Tags" and add "integration"
+
+/*
+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 knative
+
+import (
+ "context"
+ "encoding/json"
+ "strings"
+ "testing"
+
+ . "github.com/onsi/gomega"
+
+ . "github.com/apache/camel-k/v2/e2e/support"
+ v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
+ corev1 "k8s.io/api/core/v1"
+)
+
+type knativeChannelResource struct {
+ Name string `json:"name"`
+ Type string `json:"type"`
+ EndpointKind string `json:"endpointKind"`
+ URL string `json:"url,omitempty"`
+ Path string `json:"path,omitempty"`
+ ObjectAPIVersion string `json:"objectApiVersion"`
+ ObjectKind string `json:"objectKind"`
+ ObjectName string `json:"objectName"`
+ Reply bool `json:"reply"`
+}
+
+func knativeChannelConfiguration(channelName, endpointKind, channelURL string)
(string, error) {
+ resource := knativeChannelResource{
+ Name: channelName,
+ Type: "channel",
+ EndpointKind: endpointKind,
+ ObjectAPIVersion: "messaging.knative.dev/v1",
+ ObjectKind: "Channel",
+ ObjectName: channelName,
+ Reply: false,
+ }
+ if endpointKind == "source" {
+ resource.Path = "/channels/" + channelName
+ } else {
+ resource.URL = channelURL
+ }
+
+ configuration, err := json.Marshal(struct {
+ Resources []knativeChannelResource `json:"resources"`
+ }{
+ Resources: []knativeChannelResource{resource},
+ })
+ if err != nil {
+ return "", err
+ }
+
+ return string(configuration), nil
+}
+
+func TestKnativeEventingChannel(t *testing.T) {
+ WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
+ const (
+ channelName = "camel-k-eventing"
+ consumerName = "knative-channel-consumer"
+ producerName = "knative-channel-producer"
+ message = "camel-k-knative-eventing-e2e"
+ )
+
+ // The Knative workflow installs the in-memory channel
implementation.
+ ExpectExecSucceed(t, g, Kubectl("apply", "-f",
"files/knative-channel.yaml", "-n", ns))
+ ExpectExecSucceed(t, g, Kubectl(
+ "wait", "--for=condition=Ready",
"channel/"+channelName, "--timeout=120s", "-n", ns,
+ ))
+
+ // The Camel Knative component needs its own environment
configuration.
+ // This is deliberately supplied directly to the component, not
by the deprecated trait.
+ channelURL, err := Kubectl(
+ "get", "channels.messaging.knative.dev", channelName,
"-n", ns, "-o", "jsonpath={.status.address.url}",
+ ).Output()
+ g.Expect(err).NotTo(HaveOccurred())
+ g.Expect(strings.TrimSpace(string(channelURL))).NotTo(BeEmpty())
+
+ consumerConfiguration, err :=
knativeChannelConfiguration(channelName, "source", "")
+ g.Expect(err).NotTo(HaveOccurred())
+
+ // Start the consumer first so it is ready before the producer
sends its event.
+ // Disable the deprecated Knative trait explicitly; the route
uses Camel's component.
+ g.Expect(KamelRun(t, ctx, ns,
"files/knative-channel-consumer.yaml",
+ "--name", consumerName,
+ "-t", "knative.enabled=false",
+ "--env",
"CAMEL_KNATIVE_CONFIGURATION="+consumerConfiguration,
+ ).Execute()).To(Succeed())
+ g.Eventually(
+ IntegrationConditionStatus(t, ctx, ns, consumerName,
v1.IntegrationConditionReady),
+ TestTimeoutMedium,
+ ).Should(Equal(corev1.ConditionTrue))
+ g.Eventually(IntegrationPodPhase(t, ctx, ns, consumerName),
TestTimeoutLong).
+ Should(Equal(corev1.PodRunning))
+
+ // With the deprecated trait disabled, create the Subscription
explicitly.
+ // It targets the Kubernetes Service created for the consumer
Integration.
+ ExpectExecSucceed(t, g, Kubectl(
+ "apply", "-f",
"files/knative-channel-subscription.yaml", "-n", ns,
+ ))
+ ExpectExecSucceed(t, g, Kubectl(
+ "wait", "--for=condition=Ready",
"subscription/"+channelName+"-"+consumerName, "--timeout=120s", "-n", ns,
+ ))
+
+ producerConfiguration, err := knativeChannelConfiguration(
+ channelName, "sink",
strings.TrimSpace(string(channelURL)),
+ )
+ g.Expect(err).NotTo(HaveOccurred())
+
+ g.Expect(KamelRun(t, ctx, ns,
"files/knative-channel-producer.yaml",
+ "--name", producerName,
+ "-t", "knative.enabled=false",
+ "--env",
"CAMEL_KNATIVE_CONFIGURATION="+producerConfiguration,
+ ).Execute()).To(Succeed())
+ g.Eventually(
+ IntegrationConditionStatus(t, ctx, ns, producerName,
v1.IntegrationConditionReady),
+ ).Should(Equal(corev1.ConditionTrue))
+ g.Eventually(IntegrationPodPhase(t, ctx, ns, producerName),
TestTimeoutLong).
+ Should(Equal(corev1.PodRunning))
+
+ // Verify that the event sent to the channel reaches the
consumer Integration.
+ g.Eventually(IntegrationLogs(t, ctx, ns, consumerName),
TestTimeoutLong).
+ Should(ContainSubstring(message))
+ })
+}