This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 51d632ae34b camel-jbang-plugin-kubernetes disable the knative by
default (#16975)
51d632ae34b is described below
commit 51d632ae34b72ae564ace9f33fabbe7dbc5b381a
Author: Claudio Miranda <[email protected]>
AuthorDate: Thu Jan 30 03:12:48 2025 -0300
camel-jbang-plugin-kubernetes disable the knative by default (#16975)
If the knative trait is enabled by default, the MetadataHelper
loads the route, resulting in the following error
IllegalStateException: Cannot find RestConsumerFactory in Registry or as a
Component to use
when there is a http consumer.
---
.../modules/ROOT/pages/camel-jbang-kubernetes.adoc | 10 +++++++++-
.../kubernetes/traits/knative/KnativeServiceTrait.java | 4 ----
.../commands/kubernetes/traits/knative/KnativeTrait.java | 12 +++++++-----
.../commands/kubernetes/KubernetesExportKnativeTest.java | 11 +++++++++++
4 files changed, 27 insertions(+), 10 deletions(-)
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 99f180c82fd..0b3eaabe6ac 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-kubernetes.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-kubernetes.adoc
@@ -449,7 +449,7 @@ https://knative.dev/docs/serving/[Knative serving] defines
a set of resources on
When Knative serving is available on the target Kubernetes cluster, you may
want to use the Knative service resource instead of an arbitrary Kubernetes
service resource.
The Knative service trait will create such a resource as part of the
Kubernetes manifest.
-NOTE: You need to enable the Knative service trait with `--trait
knative-service.enabled=true` option. Otherwise, the Camel JBang export will
always create an arbitrary Kubernetes service resource.
+NOTE: The `knative-service` trait is disabled by default, you need to enable
the Knative service trait with `--trait knative-service.enabled=true` option.
Otherwise, the Camel JBang export will always create an arbitrary Kubernetes
service resource.
The trait offers following options for customization:
@@ -532,6 +532,8 @@ The export command assists you in configuring both the
Knative component and the
You can configure the Knative component with the Knative trait.
+NOTE: The `knative` trait is disabled by default, you need to enable the
Knative trait with `--trait knative.enabled=true` option.
+
The trait offers the following options for customization:
[cols="2m,1m,5a"]
@@ -595,6 +597,8 @@ to connect your Camel application with the Knative broker.
The Camel JBang Kubernetes plugin is able to automatically create this trigger
for you.
+NOTE: The `knative` trait is disabled by default, you need to enable the
Knative trait with `--trait knative.enabled=true` option.
+
The following Camel route uses the Knative event component and references a
Knative broker by its name.
The plugin inspects the code and automatically generates the Knative trigger
as part of the Kubernetes manifest that is used
to run the Camel application on Kubernetes.
@@ -672,6 +676,8 @@ Now you can just deploy the application using the
Kubernetes manifest and see th
Knative channels represent another form of producing and consuming events from
the Knative broker.
Instead of using a trigger, you can create a subscription for a Knative
channel to consume events.
+NOTE: The `knative` trait is disabled by default, you need to enable the
Knative trait with `--trait knative.enabled=true` option.
+
The Camel route that connects to a Knative channel in order to receive events
looks like this:
[source,yaml]
@@ -750,6 +756,8 @@ The Knative eventing operator will automatically resolve
the Knative resource (e
The Camel JBang Kubernetes plugin leverages the sink binding concept for all
routes that use the Knative component as an output.
+NOTE: The `knative` trait is disabled by default, you need to enable the
Knative trait with `--trait knative.enabled=true` option.
+
The following route produces events on a Knative broker:
[source, yaml]
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/knative/KnativeServiceTrait.java
b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/knative/KnativeServiceTrait.java
index 0b0fbc8330e..0507fe5fe21 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/knative/KnativeServiceTrait.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/knative/KnativeServiceTrait.java
@@ -52,15 +52,11 @@ public class KnativeServiceTrait extends KnativeBaseTrait {
if (context.getKnativeService().isPresent()) {
return false;
}
-
// one of Knative traits needs to be explicitly enabled
boolean enabled = false;
if (traitConfig.getKnativeService() != null) {
enabled =
Optional.ofNullable(traitConfig.getKnativeService().getEnabled()).orElse(false);
- } else if (traitConfig.getKnative() != null) {
- enabled =
Optional.ofNullable(traitConfig.getKnative().getEnabled()).orElse(false);
}
-
return enabled && TraitHelper.exposesHttpService(context);
}
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 f83d2262595..187423f4c33 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
@@ -64,13 +64,15 @@ public class KnativeTrait extends KnativeBaseTrait {
@Override
public boolean configure(Traits traitConfig, TraitContext context) {
- Knative knativeTrait =
Optional.ofNullable(traitConfig.getKnative()).orElseGet(Knative::new);
-
- if (knativeTrait.getEnabled() != null && !knativeTrait.getEnabled()) {
- // Knative explicitly disabled
+ // Knative trait needs to be explicitly enabled
+ boolean enabled = false;
+ if (traitConfig.getKnative() != null) {
+ enabled =
Optional.ofNullable(traitConfig.getKnative().getEnabled()).orElse(false);
+ }
+ if (!enabled) {
return false;
}
-
+ Knative knativeTrait =
Optional.ofNullable(traitConfig.getKnative()).orElseGet(Knative::new);
List<SourceMetadata> allSourcesMetadata = context.getSourceMetadata();
if (knativeTrait.getChannelSources() == null) {
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 ea75ef881d0..c3e345198df 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
@@ -98,6 +98,7 @@ public class KubernetesExportKnativeTest extends
KubernetesExportBaseTest {
KubernetesExport command = createCommand(new String[] {
"classpath:knative-event-source.yaml" },
"--image-group=camel-test", "--runtime=" + rt.runtime());
command.traits = new String[] {
+ "knative.enabled=true",
"knative.filters=source=my-source" };
int exit = command.doCall();
Assertions.assertEquals(0, exit);
@@ -142,6 +143,8 @@ public class KubernetesExportKnativeTest extends
KubernetesExportBaseTest {
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.traits = new String[] {
+ "knative.enabled=true" };
command.doCall();
Assertions.assertTrue(hasService(rt));
@@ -181,6 +184,9 @@ public class KubernetesExportKnativeTest extends
KubernetesExportBaseTest {
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.traits = new String[] {
+ "knative.enabled=true" };
command.doCall();
Assertions.assertTrue(hasService(rt));
@@ -221,6 +227,9 @@ public class KubernetesExportKnativeTest extends
KubernetesExportBaseTest {
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.traits = new String[] {
+ "knative.enabled=true" };
command.doCall();
Assertions.assertTrue(hasService(rt));
@@ -261,6 +270,8 @@ public class KubernetesExportKnativeTest extends
KubernetesExportBaseTest {
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.traits = new String[] {
+ "knative.enabled=true" };
command.doCall();
Assertions.assertTrue(hasService(rt));