From cb21db0e53cb874d6f11a78c01bbbb284950a556 Mon Sep 17 00:00:00 2001 From: Gaelle Fournier Date: Wed, 2 Oct 2024 14:24:12 +0200 Subject: [PATCH 1/3] CAMEL-21295: refactor knative kubernetes export test --- .../kubernetes/KubernetesExportBaseTest.java | 120 ++++++ .../KubernetesExportKnativeTest.java | 293 +++++++++++++++ .../kubernetes/KubernetesExportTest.java | 344 +----------------- 3 files changed, 414 insertions(+), 343 deletions(-) create mode 100644 dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportBaseTest.java create mode 100644 dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportKnativeTest.java diff --git a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportBaseTest.java b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportBaseTest.java new file mode 100644 index 0000000000000..712272adbd5ac --- /dev/null +++ b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportBaseTest.java @@ -0,0 +1,120 @@ +/* + * 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 org.apache.camel.dsl.jbang.core.commands.kubernetes; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.Properties; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.Service; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain; +import org.apache.camel.dsl.jbang.core.common.RuntimeType; +import org.apache.camel.util.IOHelper; +import org.junit.jupiter.api.BeforeEach; +import picocli.CommandLine; + +public class KubernetesExportBaseTest extends KubernetesBaseTest { + + protected File workingDir; + protected String[] defaultArgs; + + @BeforeEach + public void setup() { + super.setup(); + + try { + Path base = Paths.get("target"); + workingDir = Files.createTempDirectory(base, "camel-k8s-export").toFile(); + workingDir.deleteOnExit(); + } catch (IOException e) { + throw new RuntimeCamelException(e); + } + + defaultArgs = new String[] { "--dir=" + workingDir, "--quiet" }; + } + + protected KubernetesExport createCommand(String[] files, String... args) { + var argsArr = Optional.ofNullable(args).orElse(new String[0]); + var argsLst = new ArrayList<>(Arrays.asList(argsArr)); + argsLst.addAll(Arrays.asList(defaultArgs)); + KubernetesExport command = new KubernetesExport(new CamelJBangMain(), files); + CommandLine.populateCommand(command, argsLst.toArray(new String[0])); + return command; + } + + protected boolean hasService(RuntimeType rt) throws IOException { + return getResource(rt, Service.class).isPresent(); + } + + protected boolean hasKnativeService(RuntimeType rt) throws IOException { + return getResource(rt, io.fabric8.knative.serving.v1.Service.class).isPresent(); + } + + protected Optional getResource(RuntimeType rt, Class type) throws IOException { + if (rt == RuntimeType.quarkus) { + try (FileInputStream fis + = new FileInputStream( + KubernetesHelper.getKubernetesManifest(ClusterType.KUBERNETES.name(), + new File(workingDir, "/src/main/kubernetes")))) { + List resources = kubernetesClient.load(fis).items(); + return resources.stream() + .filter(it -> type.isAssignableFrom(it.getClass())) + .map(type::cast) + .findFirst(); + } + } + if (rt == RuntimeType.springBoot || rt == RuntimeType.main) { + var kind = type.getSimpleName().toLowerCase(); + File file = new File(workingDir, "src/main/jkube/%s.yml".formatted(kind)); + if (file.isFile()) { + try (FileInputStream fis = new FileInputStream(file)) { + List resources = kubernetesClient.load(fis).items(); + return resources.stream() + .filter(it -> type.isAssignableFrom(it.getClass())) + .map(type::cast) + .findFirst(); + } + } + } + return Optional.empty(); + } + + protected String readResource(File workingDir, String path) throws IOException { + try (FileInputStream fis = new FileInputStream(workingDir.toPath().resolve(path).toFile())) { + return IOHelper.loadText(fis); + } + } + + protected Properties getApplicationProperties(File workingDir) throws IOException { + String content = readResource(workingDir, "src/main/resources/application.properties"); + Properties applicationProperties = new Properties(); + applicationProperties.load(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))); + return applicationProperties; + } +} diff --git a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportKnativeTest.java b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportKnativeTest.java new file mode 100644 index 0000000000000..e06ac35976ab6 --- /dev/null +++ b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportKnativeTest.java @@ -0,0 +1,293 @@ +/* + * 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 org.apache.camel.dsl.jbang.core.commands.kubernetes; + +import java.io.File; +import java.io.IOException; +import java.util.Properties; +import java.util.stream.Stream; + +import io.fabric8.knative.eventing.v1.Trigger; +import io.fabric8.knative.messaging.v1.Subscription; +import io.fabric8.knative.sources.v1.SinkBinding; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.BaseTrait; +import org.apache.camel.dsl.jbang.core.common.RuntimeType; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +public class KubernetesExportKnativeTest extends KubernetesExportBaseTest { + + private static Stream runtimeProvider() { + return Stream.of( + Arguments.of(RuntimeType.main), + Arguments.of(RuntimeType.springBoot), + Arguments.of(RuntimeType.quarkus)); + } + + @ParameterizedTest + @MethodSource("runtimeProvider") + public void shouldAddKnativeServiceSpec(RuntimeType rt) throws Exception { + KubernetesExport command = createCommand(new String[] { "classpath:route-service.yaml" }, + "--image-group=camel-test", "--runtime=" + rt.runtime()); + + command.traits = new String[] { + "knative-service.enabled=true", + "knative-service.class=hpa.autoscaling.knative.dev", + "knative-service.autoscaling-metric=cpu", + "knative-service.autoscaling-target=80", + "knative-service.min-scale=1", + "knative-service.max-scale=10", + "knative-service.rollout-duration=60", + "knative-service.visibility=cluster-local" }; + command.doCall(); + + Assertions.assertFalse(hasService(rt)); + Assertions.assertTrue(hasKnativeService(rt)); + + io.fabric8.knative.serving.v1.Service service = getResource(rt, io.fabric8.knative.serving.v1.Service.class) + .orElseThrow(() -> new RuntimeCamelException("Missing Knative service in Kubernetes manifest")); + + Assertions.assertEquals("route-service", service.getMetadata().getName()); + Assertions.assertEquals(3, service.getMetadata().getLabels().size()); + Assertions.assertEquals("route-service", service.getMetadata().getLabels().get(BaseTrait.INTEGRATION_LABEL)); + Assertions.assertEquals("true", service.getMetadata().getLabels().get("bindings.knative.dev/include")); + Assertions.assertEquals("cluster-local", service.getMetadata().getLabels().get("networking.knative.dev/visibility")); + Assertions.assertEquals(1, service.getMetadata().getAnnotations().size()); + Assertions.assertEquals("60", service.getMetadata().getAnnotations().get("serving.knative.dev/rolloutDuration")); + Assertions.assertEquals(1, service.getSpec().getTemplate().getMetadata().getLabels().size()); + Assertions.assertEquals("route-service", + service.getSpec().getTemplate().getMetadata().getLabels().get(BaseTrait.INTEGRATION_LABEL)); + Assertions.assertEquals(5, service.getSpec().getTemplate().getMetadata().getAnnotations().size()); + Assertions.assertEquals("cpu", + service.getSpec().getTemplate().getMetadata().getAnnotations().get("autoscaling.knative.dev/metric")); + Assertions.assertEquals("hpa.autoscaling.knative.dev", + service.getSpec().getTemplate().getMetadata().getAnnotations().get("autoscaling.knative.dev/class")); + Assertions.assertEquals("80", + service.getSpec().getTemplate().getMetadata().getAnnotations().get("autoscaling.knative.dev/target")); + Assertions.assertEquals("1", + service.getSpec().getTemplate().getMetadata().getAnnotations().get("autoscaling.knative.dev/minScale")); + Assertions.assertEquals("10", + service.getSpec().getTemplate().getMetadata().getAnnotations().get("autoscaling.knative.dev/maxScale")); + } + + @ParameterizedTest + @MethodSource("runtimeProvider") + public void shouldAddKnativeTrigger(RuntimeType rt) throws Exception { + KubernetesExport command = createCommand(new String[] { "classpath:knative-event-source.yaml" }, + "--image-group=camel-test", "--runtime=" + rt.runtime()); + command.doCall(); + + Assertions.assertTrue(hasService(rt)); + Assertions.assertFalse(hasKnativeService(rt)); + + Trigger trigger = getResource(rt, Trigger.class) + .orElseThrow(() -> new RuntimeCamelException("Missing Knative trigger in Kubernetes manifest")); + + Assertions.assertEquals("my-broker-knative-event-source-camel-event", trigger.getMetadata().getName()); + Assertions.assertEquals("my-broker", trigger.getSpec().getBroker()); + Assertions.assertEquals(1, trigger.getSpec().getFilter().getAttributes().size()); + Assertions.assertEquals("camel-event", trigger.getSpec().getFilter().getAttributes().get("type")); + Assertions.assertEquals("knative-event-source", trigger.getSpec().getSubscriber().getRef().getName()); + Assertions.assertEquals("Service", trigger.getSpec().getSubscriber().getRef().getKind()); + Assertions.assertEquals("v1", trigger.getSpec().getSubscriber().getRef().getApiVersion()); + Assertions.assertEquals("/events/camel-event", trigger.getSpec().getSubscriber().getUri()); + + Properties applicationProperties = getApplicationProperties(workingDir); + Assertions.assertEquals("classpath:knative.json", applicationProperties.get("camel.component.knative.environmentPath")); + + Assertions.assertEquals(""" + { + "resources" : [ { + "name" : "camel-event", + "type" : "event", + "endpointKind" : "source", + "path" : "/events/camel-event", + "objectApiVersion" : "eventing.knative.dev/v1", + "objectKind" : "Broker", + "objectName" : "my-broker", + "reply" : false + } ] + } + """, getKnativeResourceConfiguration(workingDir)); + } + + @ParameterizedTest + @MethodSource("runtimeProvider") + public void shouldAddKnativeSubscription(RuntimeType rt) throws Exception { + KubernetesExport command = createCommand(new String[] { "classpath:knative-channel-source.yaml" }, + "--image-group=camel-test", "--runtime=" + rt.runtime()); + command.doCall(); + + Assertions.assertTrue(hasService(rt)); + Assertions.assertFalse(hasKnativeService(rt)); + + Subscription subscription = getResource(rt, Subscription.class) + .orElseThrow(() -> new RuntimeCamelException("Missing Knative subscription in Kubernetes manifest")); + + Assertions.assertEquals("my-channel-knative-channel-source", subscription.getMetadata().getName()); + Assertions.assertEquals("my-channel", subscription.getSpec().getChannel().getName()); + Assertions.assertEquals("knative-channel-source", subscription.getSpec().getSubscriber().getRef().getName()); + Assertions.assertEquals("Service", subscription.getSpec().getSubscriber().getRef().getKind()); + Assertions.assertEquals("v1", subscription.getSpec().getSubscriber().getRef().getApiVersion()); + Assertions.assertEquals("/channels/my-channel", subscription.getSpec().getSubscriber().getUri()); + + Properties applicationProperties = getApplicationProperties(workingDir); + Assertions.assertEquals("classpath:knative.json", applicationProperties.get("camel.component.knative.environmentPath")); + + Assertions.assertEquals(""" + { + "resources" : [ { + "name" : "my-channel", + "type" : "channel", + "endpointKind" : "source", + "path" : "/channels/my-channel", + "objectApiVersion" : "messaging.knative.dev/v1", + "objectKind" : "Channel", + "objectName" : "my-channel", + "reply" : false + } ] + } + """, getKnativeResourceConfiguration(workingDir)); + } + + @ParameterizedTest + @MethodSource("runtimeProvider") + public void shouldAddKnativeBrokerSinkBinding(RuntimeType rt) throws Exception { + KubernetesExport command = createCommand(new String[] { "classpath:knative-event-sink.yaml" }, + "--image-group=camel-test", "--runtime=" + rt.runtime()); + command.doCall(); + + Assertions.assertTrue(hasService(rt)); + Assertions.assertFalse(hasKnativeService(rt)); + + SinkBinding sinkBinding = getResource(rt, SinkBinding.class) + .orElseThrow(() -> new RuntimeCamelException("Missing Knative sinkBinding in Kubernetes manifest")); + + Assertions.assertEquals("knative-event-sink", sinkBinding.getMetadata().getName()); + Assertions.assertEquals("my-broker", sinkBinding.getSpec().getSink().getRef().getName()); + Assertions.assertEquals("Broker", sinkBinding.getSpec().getSink().getRef().getKind()); + Assertions.assertEquals("eventing.knative.dev/v1", sinkBinding.getSpec().getSink().getRef().getApiVersion()); + Assertions.assertEquals("knative-event-sink", sinkBinding.getSpec().getSubject().getName()); + Assertions.assertEquals("Deployment", sinkBinding.getSpec().getSubject().getKind()); + Assertions.assertEquals("apps/v1", sinkBinding.getSpec().getSubject().getApiVersion()); + + Properties applicationProperties = getApplicationProperties(workingDir); + Assertions.assertEquals("classpath:knative.json", applicationProperties.get("camel.component.knative.environmentPath")); + + Assertions.assertEquals(""" + { + "resources" : [ { + "name" : "my-broker", + "type" : "event", + "endpointKind" : "sink", + "url" : "{{k.sink:http://localhost:8080}}", + "objectApiVersion" : "eventing.knative.dev/v1", + "objectKind" : "Broker", + "objectName" : "my-broker", + "reply" : false + } ] + } + """, getKnativeResourceConfiguration(workingDir)); + } + + @ParameterizedTest + @MethodSource("runtimeProvider") + public void shouldAddKnativeChannelSinkBinding(RuntimeType rt) throws Exception { + KubernetesExport command = createCommand(new String[] { "classpath:knative-channel-sink.yaml" }, + "--image-group=camel-test", "--runtime=" + rt.runtime()); + command.doCall(); + + Assertions.assertTrue(hasService(rt)); + Assertions.assertFalse(hasKnativeService(rt)); + + SinkBinding sinkBinding = getResource(rt, SinkBinding.class) + .orElseThrow(() -> new RuntimeCamelException("Missing Knative sinkBinding in Kubernetes manifest")); + + Assertions.assertEquals("knative-channel-sink", sinkBinding.getMetadata().getName()); + Assertions.assertEquals("my-channel", sinkBinding.getSpec().getSink().getRef().getName()); + Assertions.assertEquals("Channel", sinkBinding.getSpec().getSink().getRef().getKind()); + Assertions.assertEquals("messaging.knative.dev/v1", sinkBinding.getSpec().getSink().getRef().getApiVersion()); + Assertions.assertEquals("knative-channel-sink", sinkBinding.getSpec().getSubject().getName()); + Assertions.assertEquals("Deployment", sinkBinding.getSpec().getSubject().getKind()); + Assertions.assertEquals("apps/v1", sinkBinding.getSpec().getSubject().getApiVersion()); + + Properties applicationProperties = getApplicationProperties(workingDir); + Assertions.assertEquals("classpath:knative.json", applicationProperties.get("camel.component.knative.environmentPath")); + + Assertions.assertEquals(""" + { + "resources" : [ { + "name" : "my-channel", + "type" : "channel", + "endpointKind" : "sink", + "url" : "{{k.sink:http://localhost:8080}}", + "objectApiVersion" : "messaging.knative.dev/v1", + "objectKind" : "Channel", + "objectName" : "my-channel", + "reply" : false + } ] + } + """, getKnativeResourceConfiguration(workingDir)); + } + + @ParameterizedTest + @MethodSource("runtimeProvider") + public void shouldAddKnativeEndpointSinkBinding(RuntimeType rt) throws Exception { + KubernetesExport command = createCommand(new String[] { "classpath:knative-endpoint-sink.yaml" }, + "--image-group=camel-test", "--runtime=" + rt.runtime()); + command.doCall(); + + Assertions.assertTrue(hasService(rt)); + Assertions.assertFalse(hasKnativeService(rt)); + + SinkBinding sinkBinding = getResource(rt, SinkBinding.class) + .orElseThrow(() -> new RuntimeCamelException("Missing Knative sinkBinding in Kubernetes manifest")); + + Assertions.assertEquals("knative-endpoint-sink", sinkBinding.getMetadata().getName()); + Assertions.assertEquals("my-endpoint", sinkBinding.getSpec().getSink().getRef().getName()); + Assertions.assertEquals("Service", sinkBinding.getSpec().getSink().getRef().getKind()); + Assertions.assertEquals("serving.knative.dev/v1", sinkBinding.getSpec().getSink().getRef().getApiVersion()); + Assertions.assertEquals("knative-endpoint-sink", sinkBinding.getSpec().getSubject().getName()); + Assertions.assertEquals("Deployment", sinkBinding.getSpec().getSubject().getKind()); + Assertions.assertEquals("apps/v1", sinkBinding.getSpec().getSubject().getApiVersion()); + + Properties applicationProperties = getApplicationProperties(workingDir); + Assertions.assertEquals("classpath:knative.json", applicationProperties.get("camel.component.knative.environmentPath")); + + Assertions.assertEquals(""" + { + "resources" : [ { + "name" : "my-endpoint", + "type" : "endpoint", + "endpointKind" : "sink", + "url" : "{{k.sink:http://localhost:8080}}", + "objectApiVersion" : "serving.knative.dev/v1", + "objectKind" : "Service", + "objectName" : "my-endpoint", + "reply" : false + } ] + } + """, getKnativeResourceConfiguration(workingDir)); + } + + private String getKnativeResourceConfiguration(File workingDir) throws IOException { + return readResource(workingDir, "src/main/resources/knative.json"); + } +} diff --git a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportTest.java b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportTest.java index 12818e034b138..89665bce12739 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportTest.java +++ b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportTest.java @@ -17,66 +17,33 @@ package org.apache.camel.dsl.jbang.core.commands.kubernetes; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Properties; import java.util.stream.Stream; -import io.fabric8.knative.eventing.v1.Trigger; -import io.fabric8.knative.messaging.v1.Subscription; -import io.fabric8.knative.sources.v1.SinkBinding; import io.fabric8.kubernetes.api.model.Container; -import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.api.model.ServicePort; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.networking.v1.Ingress; import io.fabric8.openshift.api.model.Route; import org.apache.camel.RuntimeCamelException; -import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain; import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.BaseTrait; import org.apache.camel.dsl.jbang.core.common.RuntimeType; import org.apache.camel.util.IOHelper; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import picocli.CommandLine; -class KubernetesExportTest extends KubernetesBaseTest { - - private File workingDir; - private String[] defaultArgs; - - @BeforeEach - public void setup() { - super.setup(); - - try { - Path base = Paths.get("target"); - workingDir = Files.createTempDirectory(base, "camel-k8s-export").toFile(); - workingDir.deleteOnExit(); - } catch (IOException e) { - throw new RuntimeCamelException(e); - } - - defaultArgs = new String[] { "--dir=" + workingDir, "--quiet" }; - } +class KubernetesExportTest extends KubernetesExportBaseTest { private static Stream runtimeProvider() { return Stream.of( @@ -344,252 +311,6 @@ public void shouldAddContainerSpec(RuntimeType rt) throws Exception { Assertions.assertEquals("custom", service.getSpec().getPorts().get(0).getTargetPort().getStrVal()); } - @ParameterizedTest - @MethodSource("runtimeProvider") - public void shouldAddKnativeServiceSpec(RuntimeType rt) throws Exception { - KubernetesExport command = createCommand(new String[] { "classpath:route-service.yaml" }, - "--image-group=camel-test", "--runtime=" + rt.runtime()); - - command.traits = new String[] { - "knative-service.enabled=true", - "knative-service.class=hpa.autoscaling.knative.dev", - "knative-service.autoscaling-metric=cpu", - "knative-service.autoscaling-target=80", - "knative-service.min-scale=1", - "knative-service.max-scale=10", - "knative-service.rollout-duration=60", - "knative-service.visibility=cluster-local" }; - command.doCall(); - - Assertions.assertFalse(hasService(rt)); - Assertions.assertTrue(hasKnativeService(rt)); - - io.fabric8.knative.serving.v1.Service service = getResource(rt, io.fabric8.knative.serving.v1.Service.class) - .orElseThrow(() -> new RuntimeCamelException("Missing Knative service in Kubernetes manifest")); - - Assertions.assertEquals("route-service", service.getMetadata().getName()); - Assertions.assertEquals(3, service.getMetadata().getLabels().size()); - Assertions.assertEquals("route-service", service.getMetadata().getLabels().get(BaseTrait.INTEGRATION_LABEL)); - Assertions.assertEquals("true", service.getMetadata().getLabels().get("bindings.knative.dev/include")); - Assertions.assertEquals("cluster-local", service.getMetadata().getLabels().get("networking.knative.dev/visibility")); - Assertions.assertEquals(1, service.getMetadata().getAnnotations().size()); - Assertions.assertEquals("60", service.getMetadata().getAnnotations().get("serving.knative.dev/rolloutDuration")); - Assertions.assertEquals(1, service.getSpec().getTemplate().getMetadata().getLabels().size()); - Assertions.assertEquals("route-service", - service.getSpec().getTemplate().getMetadata().getLabels().get(BaseTrait.INTEGRATION_LABEL)); - Assertions.assertEquals(5, service.getSpec().getTemplate().getMetadata().getAnnotations().size()); - Assertions.assertEquals("cpu", - service.getSpec().getTemplate().getMetadata().getAnnotations().get("autoscaling.knative.dev/metric")); - Assertions.assertEquals("hpa.autoscaling.knative.dev", - service.getSpec().getTemplate().getMetadata().getAnnotations().get("autoscaling.knative.dev/class")); - Assertions.assertEquals("80", - service.getSpec().getTemplate().getMetadata().getAnnotations().get("autoscaling.knative.dev/target")); - Assertions.assertEquals("1", - service.getSpec().getTemplate().getMetadata().getAnnotations().get("autoscaling.knative.dev/minScale")); - Assertions.assertEquals("10", - service.getSpec().getTemplate().getMetadata().getAnnotations().get("autoscaling.knative.dev/maxScale")); - } - - @ParameterizedTest - @MethodSource("runtimeProvider") - public void shouldAddKnativeTrigger(RuntimeType rt) throws Exception { - KubernetesExport command = createCommand(new String[] { "classpath:knative-event-source.yaml" }, - "--image-group=camel-test", "--runtime=" + rt.runtime()); - command.doCall(); - - Assertions.assertTrue(hasService(rt)); - Assertions.assertFalse(hasKnativeService(rt)); - - Trigger trigger = getResource(rt, Trigger.class) - .orElseThrow(() -> new RuntimeCamelException("Missing Knative trigger in Kubernetes manifest")); - - Assertions.assertEquals("my-broker-knative-event-source-camel-event", trigger.getMetadata().getName()); - Assertions.assertEquals("my-broker", trigger.getSpec().getBroker()); - Assertions.assertEquals(1, trigger.getSpec().getFilter().getAttributes().size()); - Assertions.assertEquals("camel-event", trigger.getSpec().getFilter().getAttributes().get("type")); - Assertions.assertEquals("knative-event-source", trigger.getSpec().getSubscriber().getRef().getName()); - Assertions.assertEquals("Service", trigger.getSpec().getSubscriber().getRef().getKind()); - Assertions.assertEquals("v1", trigger.getSpec().getSubscriber().getRef().getApiVersion()); - Assertions.assertEquals("/events/camel-event", trigger.getSpec().getSubscriber().getUri()); - - Properties applicationProperties = getApplicationProperties(workingDir); - Assertions.assertEquals("classpath:knative.json", applicationProperties.get("camel.component.knative.environmentPath")); - - Assertions.assertEquals(""" - { - "resources" : [ { - "name" : "camel-event", - "type" : "event", - "endpointKind" : "source", - "path" : "/events/camel-event", - "objectApiVersion" : "eventing.knative.dev/v1", - "objectKind" : "Broker", - "objectName" : "my-broker", - "reply" : false - } ] - } - """, getKnativeResourceConfiguration(workingDir)); - } - - @ParameterizedTest - @MethodSource("runtimeProvider") - public void shouldAddKnativeSubscription(RuntimeType rt) throws Exception { - KubernetesExport command = createCommand(new String[] { "classpath:knative-channel-source.yaml" }, - "--image-group=camel-test", "--runtime=" + rt.runtime()); - command.doCall(); - - Assertions.assertTrue(hasService(rt)); - Assertions.assertFalse(hasKnativeService(rt)); - - Subscription subscription = getResource(rt, Subscription.class) - .orElseThrow(() -> new RuntimeCamelException("Missing Knative subscription in Kubernetes manifest")); - - Assertions.assertEquals("my-channel-knative-channel-source", subscription.getMetadata().getName()); - Assertions.assertEquals("my-channel", subscription.getSpec().getChannel().getName()); - Assertions.assertEquals("knative-channel-source", subscription.getSpec().getSubscriber().getRef().getName()); - Assertions.assertEquals("Service", subscription.getSpec().getSubscriber().getRef().getKind()); - Assertions.assertEquals("v1", subscription.getSpec().getSubscriber().getRef().getApiVersion()); - Assertions.assertEquals("/channels/my-channel", subscription.getSpec().getSubscriber().getUri()); - - Properties applicationProperties = getApplicationProperties(workingDir); - Assertions.assertEquals("classpath:knative.json", applicationProperties.get("camel.component.knative.environmentPath")); - - Assertions.assertEquals(""" - { - "resources" : [ { - "name" : "my-channel", - "type" : "channel", - "endpointKind" : "source", - "path" : "/channels/my-channel", - "objectApiVersion" : "messaging.knative.dev/v1", - "objectKind" : "Channel", - "objectName" : "my-channel", - "reply" : false - } ] - } - """, getKnativeResourceConfiguration(workingDir)); - } - - @ParameterizedTest - @MethodSource("runtimeProvider") - public void shouldAddKnativeBrokerSinkBinding(RuntimeType rt) throws Exception { - KubernetesExport command = createCommand(new String[] { "classpath:knative-event-sink.yaml" }, - "--image-group=camel-test", "--runtime=" + rt.runtime()); - command.doCall(); - - Assertions.assertTrue(hasService(rt)); - Assertions.assertFalse(hasKnativeService(rt)); - - SinkBinding sinkBinding = getResource(rt, SinkBinding.class) - .orElseThrow(() -> new RuntimeCamelException("Missing Knative sinkBinding in Kubernetes manifest")); - - Assertions.assertEquals("knative-event-sink", sinkBinding.getMetadata().getName()); - Assertions.assertEquals("my-broker", sinkBinding.getSpec().getSink().getRef().getName()); - Assertions.assertEquals("Broker", sinkBinding.getSpec().getSink().getRef().getKind()); - Assertions.assertEquals("eventing.knative.dev/v1", sinkBinding.getSpec().getSink().getRef().getApiVersion()); - Assertions.assertEquals("knative-event-sink", sinkBinding.getSpec().getSubject().getName()); - Assertions.assertEquals("Deployment", sinkBinding.getSpec().getSubject().getKind()); - Assertions.assertEquals("apps/v1", sinkBinding.getSpec().getSubject().getApiVersion()); - - Properties applicationProperties = getApplicationProperties(workingDir); - Assertions.assertEquals("classpath:knative.json", applicationProperties.get("camel.component.knative.environmentPath")); - - Assertions.assertEquals(""" - { - "resources" : [ { - "name" : "my-broker", - "type" : "event", - "endpointKind" : "sink", - "url" : "{{k.sink:http://localhost:8080}}", - "objectApiVersion" : "eventing.knative.dev/v1", - "objectKind" : "Broker", - "objectName" : "my-broker", - "reply" : false - } ] - } - """, getKnativeResourceConfiguration(workingDir)); - } - - @ParameterizedTest - @MethodSource("runtimeProvider") - public void shouldAddKnativeChannelSinkBinding(RuntimeType rt) throws Exception { - KubernetesExport command = createCommand(new String[] { "classpath:knative-channel-sink.yaml" }, - "--image-group=camel-test", "--runtime=" + rt.runtime()); - command.doCall(); - - Assertions.assertTrue(hasService(rt)); - Assertions.assertFalse(hasKnativeService(rt)); - - SinkBinding sinkBinding = getResource(rt, SinkBinding.class) - .orElseThrow(() -> new RuntimeCamelException("Missing Knative sinkBinding in Kubernetes manifest")); - - Assertions.assertEquals("knative-channel-sink", sinkBinding.getMetadata().getName()); - Assertions.assertEquals("my-channel", sinkBinding.getSpec().getSink().getRef().getName()); - Assertions.assertEquals("Channel", sinkBinding.getSpec().getSink().getRef().getKind()); - Assertions.assertEquals("messaging.knative.dev/v1", sinkBinding.getSpec().getSink().getRef().getApiVersion()); - Assertions.assertEquals("knative-channel-sink", sinkBinding.getSpec().getSubject().getName()); - Assertions.assertEquals("Deployment", sinkBinding.getSpec().getSubject().getKind()); - Assertions.assertEquals("apps/v1", sinkBinding.getSpec().getSubject().getApiVersion()); - - Properties applicationProperties = getApplicationProperties(workingDir); - Assertions.assertEquals("classpath:knative.json", applicationProperties.get("camel.component.knative.environmentPath")); - - Assertions.assertEquals(""" - { - "resources" : [ { - "name" : "my-channel", - "type" : "channel", - "endpointKind" : "sink", - "url" : "{{k.sink:http://localhost:8080}}", - "objectApiVersion" : "messaging.knative.dev/v1", - "objectKind" : "Channel", - "objectName" : "my-channel", - "reply" : false - } ] - } - """, getKnativeResourceConfiguration(workingDir)); - } - - @ParameterizedTest - @MethodSource("runtimeProvider") - public void shouldAddKnativeEndpointSinkBinding(RuntimeType rt) throws Exception { - KubernetesExport command = createCommand(new String[] { "classpath:knative-endpoint-sink.yaml" }, - "--image-group=camel-test", "--runtime=" + rt.runtime()); - command.doCall(); - - Assertions.assertTrue(hasService(rt)); - Assertions.assertFalse(hasKnativeService(rt)); - - SinkBinding sinkBinding = getResource(rt, SinkBinding.class) - .orElseThrow(() -> new RuntimeCamelException("Missing Knative sinkBinding in Kubernetes manifest")); - - Assertions.assertEquals("knative-endpoint-sink", sinkBinding.getMetadata().getName()); - Assertions.assertEquals("my-endpoint", sinkBinding.getSpec().getSink().getRef().getName()); - Assertions.assertEquals("Service", sinkBinding.getSpec().getSink().getRef().getKind()); - Assertions.assertEquals("serving.knative.dev/v1", sinkBinding.getSpec().getSink().getRef().getApiVersion()); - Assertions.assertEquals("knative-endpoint-sink", sinkBinding.getSpec().getSubject().getName()); - Assertions.assertEquals("Deployment", sinkBinding.getSpec().getSubject().getKind()); - Assertions.assertEquals("apps/v1", sinkBinding.getSpec().getSubject().getApiVersion()); - - Properties applicationProperties = getApplicationProperties(workingDir); - Assertions.assertEquals("classpath:knative.json", applicationProperties.get("camel.component.knative.environmentPath")); - - Assertions.assertEquals(""" - { - "resources" : [ { - "name" : "my-endpoint", - "type" : "endpoint", - "endpointKind" : "sink", - "url" : "{{k.sink:http://localhost:8080}}", - "objectApiVersion" : "serving.knative.dev/v1", - "objectKind" : "Service", - "objectName" : "my-endpoint", - "reply" : false - } ] - } - """, getKnativeResourceConfiguration(workingDir)); - } - @ParameterizedTest @MethodSource("runtimeProvider") public void shouldAddVolumes(RuntimeType rt) throws Exception { @@ -750,15 +471,6 @@ public void shouldUseImage(RuntimeType rt) throws Exception { deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage()); } - private KubernetesExport createCommand(String[] files, String... args) { - var argsArr = Optional.ofNullable(args).orElse(new String[0]); - var argsLst = new ArrayList<>(Arrays.asList(argsArr)); - argsLst.addAll(Arrays.asList(defaultArgs)); - KubernetesExport command = new KubernetesExport(new CamelJBangMain(), files); - CommandLine.populateCommand(command, argsLst.toArray(new String[0])); - return command; - } - private Deployment getDeployment(RuntimeType rt) throws IOException { return getResource(rt, Deployment.class) .orElseThrow(() -> new RuntimeCamelException("Cannot find deployment for: %s".formatted(rt.runtime()))); @@ -787,60 +499,6 @@ private boolean hasRoute(RuntimeType rt) throws IOException { return getResource(rt, Route.class).isPresent(); } - private boolean hasService(RuntimeType rt) throws IOException { - return getResource(rt, Service.class).isPresent(); - } - - private boolean hasKnativeService(RuntimeType rt) throws IOException { - return getResource(rt, io.fabric8.knative.serving.v1.Service.class).isPresent(); - } - - private Optional getResource(RuntimeType rt, Class type) throws IOException { - if (rt == RuntimeType.quarkus) { - try (FileInputStream fis - = new FileInputStream( - KubernetesHelper.getKubernetesManifest(ClusterType.KUBERNETES.name(), - new File(workingDir, "/src/main/kubernetes")))) { - List resources = kubernetesClient.load(fis).items(); - return resources.stream() - .filter(it -> type.isAssignableFrom(it.getClass())) - .map(type::cast) - .findFirst(); - } - } - if (rt == RuntimeType.springBoot || rt == RuntimeType.main) { - var kind = type.getSimpleName().toLowerCase(); - File file = new File(workingDir, "src/main/jkube/%s.yml".formatted(kind)); - if (file.isFile()) { - try (FileInputStream fis = new FileInputStream(file)) { - List resources = kubernetesClient.load(fis).items(); - return resources.stream() - .filter(it -> type.isAssignableFrom(it.getClass())) - .map(type::cast) - .findFirst(); - } - } - } - return Optional.empty(); - } - - private String readResource(File workingDir, String path) throws IOException { - try (FileInputStream fis = new FileInputStream(workingDir.toPath().resolve(path).toFile())) { - return IOHelper.loadText(fis); - } - } - - private Properties getApplicationProperties(File workingDir) throws IOException { - String content = readResource(workingDir, "src/main/resources/application.properties"); - Properties applicationProperties = new Properties(); - applicationProperties.load(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))); - return applicationProperties; - } - - private String getKnativeResourceConfiguration(File workingDir) throws IOException { - return readResource(workingDir, "src/main/resources/knative.json"); - } - private Model readMavenModel() throws Exception { File f = workingDir.toPath().resolve("pom.xml").toFile(); Assertions.assertTrue(f.isFile(), "Not a pom.xml file: " + f); From 78abb5f78b6c6e1c8bd3569bade078ce137a87f8 Mon Sep 17 00:00:00 2001 From: Gaelle Fournier Date: Wed, 2 Oct 2024 16:27:13 +0200 Subject: [PATCH 2/3] CAMEL-21295: Add Knative Trigger filter to camel-jbang-kubernetes plugin --- .../traits/knative/KnativeTrait.java | 41 ++++++++++--------- .../kubernetes/traits/model/Knative.java | 12 +++--- .../KubernetesExportKnativeTest.java | 5 ++- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/knative/KnativeTrait.java b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/knative/KnativeTrait.java index 929d649ce0953..3935597dc9e8b 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/knative/KnativeTrait.java +++ b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/knative/KnativeTrait.java @@ -38,6 +38,7 @@ import io.fabric8.knative.internal.pkg.tracker.ReferenceBuilder; import io.fabric8.knative.messaging.v1.SubscriptionBuilder; import io.fabric8.knative.sources.v1.SinkBindingBuilder; +import org.apache.camel.RuntimeCamelException; import org.apache.camel.dsl.jbang.core.commands.kubernetes.KubernetesHelper; import org.apache.camel.dsl.jbang.core.commands.kubernetes.support.SourceMetadata; import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.ServiceTrait; @@ -119,7 +120,7 @@ public void apply(Traits traitConfig, TraitContext context) { Knative knativeTrait = Optional.ofNullable(traitConfig.getKnative()).orElseGet(Knative::new); configureChannels(knativeTrait, context); - configureEndpoints(knativeTrait, context); + configureEndpoints(knativeTrait); configureEvents(knativeTrait, context); if (knativeTrait.getSinkBinding() != null && knativeTrait.getSinkBinding()) { @@ -145,7 +146,7 @@ public void apply(Traits traitConfig, TraitContext context) { private void configureChannels(Knative knativeTrait, TraitContext context) { for (String uri : knativeTrait.getChannelSources()) { - createSubscription(toKnativeUri(KnativeResourceType.CHANNEL, uri), knativeTrait, context); + createSubscription(toKnativeUri(KnativeResourceType.CHANNEL, uri), context); } for (String uri : knativeTrait.getChannelSinks()) { @@ -161,7 +162,7 @@ private void configureChannels(Knative knativeTrait, TraitContext context) { } } - private void configureEndpoints(Knative knativeTrait, TraitContext context) { + private void configureEndpoints(Knative knativeTrait) { for (String uri : knativeTrait.getEndpointSources()) { String endpointName = extractKnativeResource(uri); addKnativeResourceConfiguration(new KnativeResourceConfiguration( @@ -207,7 +208,7 @@ private void configureEvents(Knative knativeTrait, TraitContext context) { } } - private void createSubscription(String uri, Knative knativeTrait, TraitContext context) { + private void createSubscription(String uri, TraitContext context) { String channelName = extractKnativeResource(uri); String subscriptionName = createSubscriptionName(context.getName(), channelName); @@ -286,21 +287,23 @@ private void createTrigger(String uri, Knative knativeTrait, TraitContext contex private Map getFilterAttributes(Knative knativeTrait, String eventType) { Map filterAttributes = new HashMap<>(); - filterAttributes.put("type", eventType); - - // TODO: use this as soon as new Camel K CRD model has been released - // for (String filterExpression : knativeTrait.getFilters()) { - // String[] keyValue = filterExpression.split("=", 2); - // if (keyValue.length != 2) { - // throw new RuntimeCamelException("Invalid Knative trigger filter expression: %s".formatted(filterExpression)); - // } - // filterAttributes.put(keyValue[0].trim(), keyValue[1].trim()); - // } - // - // if (!filterAttributes.containsKey("type") && Optional.ofNullable(knativeTrait.getFilterEventType()).orElse(true) && ObjectHelper.isNotEmpty(eventType)) { - // // Apply default trigger filter attribute for the event type - // filterAttributes.put("type", eventType); - // } + + if (knativeTrait.getFilters() != null) { + for (String filterExpression : knativeTrait.getFilters()) { + String[] keyValue = filterExpression.split("=", 2); + if (keyValue.length != 2) { + throw new RuntimeCamelException( + "Invalid Knative trigger filter expression: %s".formatted(filterExpression)); + } + filterAttributes.put(keyValue[0].trim(), keyValue[1].trim()); + } + } + + if (!filterAttributes.containsKey("type") && Optional.ofNullable(knativeTrait.getFilterEventType()).orElse(true) + && ObjectHelper.isNotEmpty(eventType)) { + // Apply default trigger filter attribute for the event type + filterAttributes.put("type", eventType); + } return filterAttributes; } diff --git a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/model/Knative.java b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/model/Knative.java index 3410f64b3bee1..71ec3cc806f8b 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/model/Knative.java +++ b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/model/Knative.java @@ -28,7 +28,7 @@ @JsonInclude(JsonInclude.Include.NON_NULL) @JsonPropertyOrder({ - "auto", "channelSinks", "channelSources", "config", "enabled", "endpointSinks", "endpointSources", + "auto", "channelSinks", "channelSources", "configuration", "enabled", "endpointSinks", "endpointSources", "eventSinks", "eventSources", "filterEventType", "filterSourceChannels", "filters", "namespaceLabel", "sinkBinding" }) public class Knative { @JsonProperty("auto") @@ -50,7 +50,7 @@ public class Knative { @JsonPropertyDescription("Can be used to inject a Knative complete configuration in JSON format.") @JsonSetter( nulls = Nulls.SKIP) - private String config; + private String configuration; @JsonProperty("enabled") @JsonPropertyDescription("Can be used to enable or disable a trait. All traits share this common property.") @JsonSetter( @@ -129,12 +129,12 @@ public void setChannelSources(List channelSources) { this.channelSources = channelSources; } - public String getConfig() { - return this.config; + public String getConfiguration() { + return this.configuration; } - public void setConfig(String config) { - this.config = config; + public void setConfiguration(String configuration) { + this.configuration = configuration; } public Boolean getEnabled() { diff --git a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportKnativeTest.java b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportKnativeTest.java index e06ac35976ab6..36282cf07b47c 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportKnativeTest.java +++ b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportKnativeTest.java @@ -92,6 +92,8 @@ public void shouldAddKnativeServiceSpec(RuntimeType rt) throws Exception { public void shouldAddKnativeTrigger(RuntimeType rt) throws Exception { KubernetesExport command = createCommand(new String[] { "classpath:knative-event-source.yaml" }, "--image-group=camel-test", "--runtime=" + rt.runtime()); + command.traits = new String[] { + "knative.filters=source=my-source" }; command.doCall(); Assertions.assertTrue(hasService(rt)); @@ -102,8 +104,9 @@ public void shouldAddKnativeTrigger(RuntimeType rt) throws Exception { Assertions.assertEquals("my-broker-knative-event-source-camel-event", trigger.getMetadata().getName()); Assertions.assertEquals("my-broker", trigger.getSpec().getBroker()); - Assertions.assertEquals(1, trigger.getSpec().getFilter().getAttributes().size()); + Assertions.assertEquals(2, trigger.getSpec().getFilter().getAttributes().size()); Assertions.assertEquals("camel-event", trigger.getSpec().getFilter().getAttributes().get("type")); + Assertions.assertEquals("my-source", trigger.getSpec().getFilter().getAttributes().get("source")); Assertions.assertEquals("knative-event-source", trigger.getSpec().getSubscriber().getRef().getName()); Assertions.assertEquals("Service", trigger.getSpec().getSubscriber().getRef().getKind()); Assertions.assertEquals("v1", trigger.getSpec().getSubscriber().getRef().getApiVersion()); From 4132df55a05d1fc2879fddc50ab4d380e64522e8 Mon Sep 17 00:00:00 2001 From: Gaelle Fournier Date: Wed, 2 Oct 2024 16:27:57 +0200 Subject: [PATCH 3/3] CAMEL-21295: Add knative trait doc to camel-jbang-kubernetes plugin --- .../ROOT/pages/camel-jbang-kubernetes.adoc | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-kubernetes.adoc b/docs/user-manual/modules/ROOT/pages/camel-jbang-kubernetes.adoc index 8fd117330e696..ea09be6145992 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-jbang-kubernetes.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-kubernetes.adoc @@ -514,7 +514,64 @@ Apache Camel also provides a Knative component that makes you easily interact wi The Knative component enables you to exchange data with the Knative eventing broker and other Knative services deployed on Kubernetes. The Camel JBang Kubernetes plugin provides some autoconfiguration options when connecting with the Knative component. -The export command assists you in configuring both the Knative component and the Kubernetes manifest for connecting to Knative resources on the Kubenretes cluster. +The export command assists you in configuring both the Knative component and the Kubernetes manifest for connecting to Knative resources on the Kubernetes cluster. + +You can configure the Knative component with the Knative trait. + +The trait offers following options for customization: + +[cols="2m,1m,5a"] +|=== +|Property | Type | Description + +| knative.enabled +| bool +| Can be used to enable or disable a trait. (default: true) + +| knative.configuration +| string +| Can be used to inject a Knative complete configuration in JSON format + +| knative.channel-sinks +| []string +| List of channels used as destination of camel routes. Can contain simple channel names or full Camel URIs. + +Refer to the Knative documentation for more information. + +| knative.channel-sources +| []string +| List of channels used as source of camel routes. Can contain simple channel names or full Camel URIs. + +| knative.endpoint-sinks +| []string +| List of endpoints used as destination of camel routes. Can contain simple endpoint names or full Camel URIs. + +| knative.endpoint-sources +| []string +| List of endpoints used as sources of camel routes. Can contain simple endpoint names or full Camel URIs. + +| knative.event-sinks +| []string +| List of endpoints used as destination of integration routes. Can contain simple endpoint names or full Camel URIs. + +| knative.event-sources +| []string +| List of event types that the integration will be subscribed to. Can contain simple event types or full Camel URIs (to use a specific broker different from "default"). + +| knative.sink-binding +| bool +| Allows binding the integration to a sink via a Knative SinkBinding resource. This can be used when the integration targets a single sink. It’s enabled by default when the integration targets a single sink (except when the integration is owned by a Knative source). + +| knative.filters +| []string +| Sets filter attributes on the event stream (such as event type, source, subject and so on). A list of key-value pairs that represent filter attributes and its values. The syntax is KEY=VALUE, e.g., source="my.source". Filter attributes get set on the Knative trigger that is being created as part of this integration. + +| knative.filter-event-type +| bool +| Enables the default filtering for the Knative trigger using the event type If this is true, the created Knative trigger uses the event type as a filter on the event stream when no other filter criteria is given. (default: true) + +|=== + === Knative trigger