You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2025/08/19 17:25:24 UTC

(camel) branch main updated: CAMEL-22335: camel k8s export - Fix to load traits defined in application.properties (#18938)

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 b700c3b735a CAMEL-22335: camel k8s export - Fix to load traits defined in application.properties (#18938)
b700c3b735a is described below

commit b700c3b735a7940364eb3ccae3651a3b200ac445
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Aug 19 19:25:16 2025 +0200

    CAMEL-22335: camel k8s export - Fix to load traits defined in application.properties (#18938)
---
 .../core/commands/kubernetes/KubernetesExport.java     | 12 ++++++++++++
 .../core/commands/kubernetes/KubernetesExportTest.java | 12 ++++++++++++
 .../commands/kubernetes/traits/TraitHelperTest.java    |  4 +++-
 .../src/test/resources/application.properties          | 18 ++++++++++++++++++
 4 files changed, 45 insertions(+), 1 deletion(-)

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 7310ab74668..83955df26d5 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
@@ -201,6 +201,9 @@ public class KubernetesExport extends Export {
                 RunHelper.dirToFiles(name, files);
             }
         }
+        if (exportBaseDir == null) {
+            exportBaseDir = Paths.get(".");
+        }
 
         printer().println("Exporting application ...");
 
@@ -290,6 +293,15 @@ public class KubernetesExport extends Export {
             // 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));
+                }
+            }
         }
 
         Traits traitsSpec = getTraitSpec(applicationProfileProperties, applicationProperties);
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 7730a93b0d2..51f21a05b5e 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
@@ -764,4 +764,16 @@ class KubernetesExportTest extends KubernetesExportBaseTest {
         }
     }
 
+    @ParameterizedTest
+    @MethodSource("runtimeProvider")
+    public void ingressTrait(RuntimeType rt) throws Exception {
+        KubernetesExport command
+                = createCommand(new String[] { "classpath:route.yaml", "src/test/resources/application.properties", },
+                        "--gav=examples:route:1.0.0", "--runtime=" + rt.runtime());
+        int exit = command.doCall();
+        Assertions.assertEquals(0, exit);
+
+        Assertions.assertTrue(hasIngress(rt));
+    }
+
 }
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 bd49ae0911b..7b773bc7aa4 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
@@ -74,11 +74,13 @@ public class TraitHelperTest {
         Properties properties = new Properties();
         properties.setProperty("camel.jbang.trait.container.port", "8080");
         properties.setProperty("camel.jbang.trait.container.port-name", "custom");
+        properties.setProperty("camel.jbang.trait.environment.FOO", "my value");
         properties.setProperty("camel.jbang.name", "MyRoute");
         String[] result = TraitHelper.extractTraitsFromProperties(properties);
         Assertions.assertNotNull(result);
-        Assertions.assertEquals(2, result.length);
+        Assertions.assertEquals(3, result.length);
         Assertions.assertTrue(Arrays.asList(result).contains("container.port-name=custom"));
+        Assertions.assertTrue(Arrays.asList(result).contains("environment.FOO=my value"));
 
         String[] resultEmpty = TraitHelper.extractTraitsFromProperties(new Properties());
         Assertions.assertNotNull(resultEmpty);
diff --git a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/resources/application.properties b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/resources/application.properties
new file mode 100644
index 00000000000..c1ff17b8e05
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/resources/application.properties
@@ -0,0 +1,18 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+camel.jbang.trait.ingress.enabled = true
\ No newline at end of file