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 2ae078de7162 CAMEL-26934: camel-jbang-plugin-kubernetes - a profile
keeps the traits of application.properties, annotations take key=value, and the
mount path is a Linux path (#30036)
2ae078de7162 is described below
commit 2ae078de71621edc36e87f43e95c544e55b7f265
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 15 17:02:26 2026 +0100
CAMEL-26934: camel-jbang-plugin-kubernetes - a profile keeps the traits of
application.properties, annotations take key=value, and the mount path is a
Linux path (#30036)
- With --profile, the traits of application.properties were left out: only
those of application-<profile>.properties
applied, although the docs give both, the profile over
application.properties. They are now merged that way.
- --trait ingress.annotations=k=v (and route, knative-service) was a string
where the trait takes a map, which exited
with 70; the form of the docs,
route.annotations.'haproxy.router.openshift.io/balance'=true, was not read
either. Both
give an annotation now, and annotations of several options add up. The
docs and the trait descriptions show --trait
instead of -t, which is not an option.
- The mount path of a config or resource was joined with the separator of
the OS (backslashes on Windows); it is a
path in the container, joined with /.
- The export no longer prints "Custom container name ... not supported" on
stdout: the container trait applies it.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../pages/camel-jbang-kubernetes-advanced.adoc | 2 +-
.../core/commands/kubernetes/KubernetesExport.java | 30 ++++++++--------------
.../commands/kubernetes/traits/MountTrait.java | 5 ++--
.../commands/kubernetes/traits/TraitHelper.java | 29 +++++++++++++++++++--
.../kubernetes/traits/model/KnativeService.java | 2 +-
.../commands/kubernetes/traits/model/Route.java | 2 +-
.../commands/kubernetes/KubernetesExportTest.java | 17 ++++++++++++
.../kubernetes/traits/TraitHelperTest.java | 19 ++++++++++++++
8 files changed, 79 insertions(+), 27 deletions(-)
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-jbang-kubernetes-advanced.adoc
b/docs/user-manual/modules/ROOT/pages/camel-jbang-kubernetes-advanced.adoc
index 773ba395f08e..f13c5aced045 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-kubernetes-advanced.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-kubernetes-advanced.adoc
@@ -375,7 +375,7 @@ NOTE: Disabled by default — enable with `--trait
knative-service.enabled=true`
| map[string]string
| The annotations added to route.
This can be used to set knative service-specific annotations
-CLI usage example: -t
"knative-service.annotations.'haproxy.router.openshift.io/balance'=true"
+CLI usage example: --trait
"knative-service.annotations.'haproxy.router.openshift.io/balance'=true"
| knative-service.class
| string
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExport.java
b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExport.java
index d1c64a47ac3b..cc597f922f24 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExport.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExport.java
@@ -44,7 +44,6 @@ import org.apache.camel.dsl.jbang.core.commands.RunHelper;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.TraitCatalog;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.TraitContext;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.TraitHelper;
-import
org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.Container;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.Traits;
import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
import org.apache.camel.dsl.jbang.run.RunPipeline;
@@ -291,22 +290,18 @@ public class KubernetesExport extends Export {
context.setServiceAccount(serviceAccount);
}
- // application-{profile}.properties
- var applicationProfileProperties = new String[0];
- if (this.profile != null) {
- // override from profile specific configuration
- applicationProfileProperties
- =
extractPropertiesTraits(exportBaseDir.resolve("application-" + profile +
".properties"));
- } else {
- for (String f : files) {
- String name = FileUtil.stripPath(f);
- if ("application.properties".equals(name)) {
- // load default properties configuration
- applicationProfileProperties
- =
extractPropertiesTraits(exportBaseDir.resolve(f));
- }
+ // the traits of application.properties, with those of
application-{profile}.properties over them: with a
+ // profile, the traits of application.properties were left out
(CAMEL-26934)
+ String[] defaultTraits = null;
+ for (String f : files) {
+ String name = FileUtil.stripPath(f);
+ if ("application.properties".equals(name)) {
+ defaultTraits =
extractPropertiesTraits(exportBaseDir.resolve(f));
}
}
+ String[] profileTraits = this.profile != null
+ ? extractPropertiesTraits(exportBaseDir.resolve("application-"
+ profile + ".properties")) : null;
+ var applicationProfileProperties =
TraitHelper.mergeTraits(profileTraits, defaultTraits);
Traits traitsSpec = getTraitSpec(applicationProfileProperties,
applicationProperties);
@@ -327,11 +322,6 @@ public class KubernetesExport extends Export {
TraitHelper.configureEnvVars(traitsSpec, envVars);
TraitHelper.configureConnects(traitsSpec, connects);
- Container container = traitsSpec.getContainer();
- if (container.getName() != null &&
!container.getName().equals(projectName)) {
- printer().printf("Custom container name '%s' not
supported%n".formatted(container.getName()));
- }
-
buildProperties.add("jkube.skip.push=%b".formatted(!imagePush));
if (ClusterType.OPENSHIFT.isEqualTo(clusterType)) {
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/MountTrait.java
b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/MountTrait.java
index 814794cc0606..aedf1801ebb7 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/MountTrait.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/MountTrait.java
@@ -17,7 +17,6 @@
package org.apache.camel.dsl.jbang.core.commands.kubernetes.traits;
-import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@@ -273,7 +272,9 @@ public class MountTrait extends BaseTrait {
baseMountPoint += CONFIGMAPS;
}
- return Path.of(baseMountPoint, mountResource.name).toString();
+ // a path in the container, which is a Linux path also when the CLI
runs on Windows, where Path joined it with
+ // backslashes (CAMEL-26934)
+ return baseMountPoint + "/" + mountResource.name;
}
private MountResource parseConfig(String expression,
MountResource.ContentType contentType) {
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/TraitHelper.java
b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/TraitHelper.java
index bc5c040e91bb..21e96bbacb8c 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/TraitHelper.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/TraitHelper.java
@@ -84,8 +84,22 @@ public final class TraitHelper {
// the CRD api is in CamelCase, then we have to
// convert the kebab-case to CamelCase
- final String traitKey =
StringHelper.dashToCamelCase(traitConfig[0]);
- final Object traitValue = resolveTraitValue(traitKey,
traitConfig[1].trim());
+ final String traitKey;
+ final Object traitValue;
+ if (traitConfig[0].startsWith("annotations.")) {
+ // an annotation as its own key, as the docs show:
route.annotations.'haproxy.router.openshift.io/balance'=true
+ traitKey = "annotations";
+ traitValue =
annotation(unquote(traitConfig[0].substring("annotations.".length())),
+ unquote(traitConfig[1].trim()));
+ } else if ("annotations".equals(traitConfig[0]) &&
traitConfig[1].contains("=")) {
+ // a single annotation as key=value, which was a string where
the trait takes a map (exit code 70)
+ String[] annotation = traitConfig[1].trim().split("=", 2);
+ traitKey = "annotations";
+ traitValue = annotation(unquote(annotation[0]),
unquote(annotation[1]));
+ } else {
+ traitKey = StringHelper.dashToCamelCase(traitConfig[0]);
+ traitValue = resolveTraitValue(traitKey,
traitConfig[1].trim());
+ }
if (traitConfigMap.containsKey(trait[0])) {
Map<String, Object> config = traitConfigMap.get(trait[0]);
@@ -203,6 +217,17 @@ public final class TraitHelper {
}
}
+ // a map of one annotation, so annotations of several --trait options add
up (CAMEL-26934)
+ private static Map<String, String> annotation(String key, String value) {
+ Map<String, String> map = new LinkedHashMap<>();
+ map.put(key, value);
+ return map;
+ }
+
+ private static String unquote(String value) {
+ return isQuoted(value) ? value.substring(1, value.length() - 1) :
value;
+ }
+
// one quoted value, not a list of quoted values such as 'a=1','b=2'
private static boolean isQuoted(String value) {
if (value.length() < 2) {
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/model/KnativeService.java
b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/model/KnativeService.java
index 269e7fb57676..0e05d54fa619 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/model/KnativeService.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/model/KnativeService.java
@@ -33,7 +33,7 @@ import com.fasterxml.jackson.annotation.Nulls;
"minScale", "rolloutDuration", "timeoutSeconds", "visibility" })
public class KnativeService {
@JsonProperty("annotations")
- @JsonPropertyDescription("The annotations added to route. This can be used
to set knative service specific annotations CLI usage example: -t
\"knative-service.annotations.'haproxy.router.openshift.io/balance'=true\"")
+ @JsonPropertyDescription("The annotations added to route. This can be used
to set knative service specific annotations CLI usage example: --trait
\"knative-service.annotations.'haproxy.router.openshift.io/balance'=true\"")
@JsonSetter(
nulls = Nulls.SKIP)
private Map<String, String> annotations;
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/model/Route.java
b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/model/Route.java
index 40c3785481a4..e6666619b1fc 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/model/Route.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/model/Route.java
@@ -34,7 +34,7 @@ import com.fasterxml.jackson.annotation.Nulls;
"tlsInsecureEdgeTerminationPolicy", "tlsKey", "tlsKeySecret",
"tlsTermination" })
public class Route {
@JsonProperty("annotations")
- @JsonPropertyDescription("The annotations added to route. This can be used
to set route specific annotations For annotations options see
https://docs.openshift.com/container-platform/3.11/architecture/networking/routes.html#route-specific-annotations
CLI usage example: -t
\"route.annotations.'haproxy.router.openshift.io/balance'=true\"")
+ @JsonPropertyDescription("The annotations added to route. This can be used
to set route specific annotations For annotations options see
https://docs.openshift.com/container-platform/3.11/architecture/networking/routes.html#route-specific-annotations
CLI usage example: --trait
\"route.annotations.'haproxy.router.openshift.io/balance'=true\"")
@JsonSetter(
nulls = Nulls.SKIP)
private Map<String, String> annotations;
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 1edfb5786eda..ec2a45a5fb29 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
@@ -42,6 +42,7 @@ import org.apache.maven.model.Model;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
+import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@@ -247,6 +248,22 @@ class KubernetesExportTest extends
KubernetesExportBaseTestSupport {
Assertions.assertEquals("ops",
cronjob.getMetadata().getAnnotations().get("team"));
}
+ @Test
+ public void aProfileKeepsTheTraitsOfApplicationProperties(@TempDir Path
project) throws Exception {
+ // CAMEL-26934: with --profile the traits of application.properties
were left out; the profile only overrides
+ Files.copy(Path.of("src/test/resources/myapp/route.yaml"),
project.resolve("route.yaml"));
+ Files.writeString(project.resolve("application.properties"),
+
"camel.jbang.trait.container.image-pull-policy=Always\ncamel.jbang.trait.container.port=8081\n");
+ Files.writeString(project.resolve("application-prod.properties"),
"camel.jbang.trait.container.port=9090\n");
+ KubernetesExport command = createCommand(new String[] {
project.toString() }, "--runtime=" + RuntimeType.main,
+ "--profile=prod");
+ Assertions.assertEquals(0, command.doCall());
+
+ Container container =
getDeployment(RuntimeType.main).getSpec().getTemplate().getSpec().getContainers().get(0);
+ Assertions.assertEquals("Always", container.getImagePullPolicy(), "the
trait of application.properties");
+ Assertions.assertEquals(9090,
container.getPorts().get(0).getContainerPort(), "the profile overrides");
+ }
+
@ParameterizedTest
@MethodSource("runtimeProvider")
public void shouldGenerateCronjobKubernetesManifest(RuntimeType rt) throws
Exception {
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/TraitHelperTest.java
b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/TraitHelperTest.java
index 6e7f407fec6d..5c470ae6c004 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/TraitHelperTest.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/traits/TraitHelperTest.java
@@ -17,6 +17,7 @@
package org.apache.camel.dsl.jbang.core.commands.kubernetes.traits;
import java.util.Arrays;
+import java.util.Map;
import java.util.Properties;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.Traits;
@@ -108,6 +109,24 @@ public class TraitHelperTest {
Assertions.assertNotNull(traitsSpecNull);
}
+ @Test
+ public void anAnnotationAsKeyValue() {
+ // CAMEL-26934: ingress.annotations=k=v was a string where the trait
takes a map, which exited with 70
+ Traits traits = TraitHelper.parseTraits(new String[] {
"ingress.annotations=team=ops" });
+
+ Assertions.assertEquals(Map.of("team", "ops"),
traits.getIngress().getAnnotations());
+ }
+
+ @Test
+ public void anAnnotationAsItsOwnKey() {
+ // the form of the docs, with a key that has dots in it
+ Traits traits = TraitHelper.parseTraits(new String[] {
+
"route.annotations.'haproxy.router.openshift.io/balance'=roundrobin",
"route.annotations=team=ops" });
+
+ Assertions.assertEquals(Map.of("haproxy.router.openshift.io/balance",
"roundrobin", "team", "ops"),
+ traits.getRoute().getAnnotations());
+ }
+
@Test
public void aCronScheduleWithACommaIsOneValue() {
// CAMEL-26934: the schedule was split at the comma into a list, which
failed with a Jackson error (exit 70)