This is an automated email from the ASF dual-hosted git repository.
acosentino 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 db1d54fb164 CAMEL-21812: camel-jbang - Provide an option in camel k8s
to trust a given cert (#17416)
db1d54fb164 is described below
commit db1d54fb164a0745548423877c2edd8ee70617b3
Author: Thomas Diesler <[email protected]>
AuthorDate: Fri Mar 21 10:38:40 2025 +0100
CAMEL-21812: camel-jbang - Provide an option in camel k8s to trust a given
cert (#17416)
---
.../dsl/jbang/core/commands/ExportBaseCommand.java | 87 +++++++++++++++-------
.../apache/camel/dsl/jbang/core/commands/Run.java | 33 +++++++-
.../resources/templates/main-kubernetes-pom.tmpl | 30 +++++++-
.../templates/quarkus-kubernetes-pom.tmpl | 34 +++++++--
.../src/main/resources/templates/run-java.sh | 57 +++++++++++++-
.../templates/spring-boot-kubernetes-pom.tmpl | 30 +++++++-
.../core/commands/kubernetes/KubernetesExport.java | 44 +++++++++--
.../commands/kubernetes/KubernetesExportTest.java | 4 +-
8 files changed, 263 insertions(+), 56 deletions(-)
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java
index 71ea0c9fa3f..444b387760c 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java
@@ -30,6 +30,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -75,6 +76,8 @@ public abstract class ExportBaseCommand extends CamelCommand {
"camel.component.kamelet.location",
"camel.jbang.classpathFiles",
"camel.jbang.localKameletDir",
+ "camel.jbang.scriptFiles",
+ "camel.jbang.tlsFiles",
"camel.jbang.jkubeFiles",
"kamelet"
};
@@ -546,6 +549,7 @@ public abstract class ExportBaseCommand extends
CamelCommand {
File settings, File profile, File srcJavaDirRoot, File srcJavaDir,
File srcResourcesDir, File srcCamelResourcesDir,
File srcKameletsResourcesDir, String packageName)
throws Exception {
+
// read the settings file and find the files to copy
Properties prop = new CamelCaseOrderedProperties();
RuntimeUtil.loadProperties(prop, settings);
@@ -591,43 +595,58 @@ public abstract class ExportBaseCommand extends
CamelCommand {
|| "camel.jbang.localKameletDir".equals(k) ||
"kamelet.yaml".equalsIgnoreCase(ext2);
boolean camel = !kamelet &&
"camel.main.routesIncludePattern".equals(k);
boolean jkube = "camel.jbang.jkubeFiles".equals(k);
- boolean web = "html".equals(ext) || "js".equals(ext) ||
"css".equals(ext) || "jpeg".equals(ext)
- || "jpg".equals(ext) || "png".equals(ext) ||
"ico".equals(ext);
- File srcWeb = new File(srcResourcesDir,
"META-INF/resources");
- File targetDir = java ? srcJavaDir : camel ?
srcCamelResourcesDir : kamelet ? srcKameletsResourcesDir
- : web ? srcWeb : srcResourcesDir;
+ boolean script = "camel.jbang.scriptFiles".equals(k);
+ boolean tls = "camel.jbang.tlsFiles".equals(k);
+ boolean web = ext != null && List.of("css", "html", "ico",
"jpeg", "jpg", "js", "png").contains(ext);
+ File targetDir;
+ if (java) {
+ targetDir = srcJavaDir;
+ } else if (camel) {
+ targetDir = srcCamelResourcesDir;
+ } else if (kamelet) {
+ targetDir = srcKameletsResourcesDir;
+ } else if (script) {
+ targetDir = new File(srcJavaDirRoot.getParentFile(),
"scripts");
+ } else if (tls) {
+ targetDir = new File(srcJavaDirRoot.getParentFile(),
"tls");
+ } else if (web) {
+ targetDir = new File(srcResourcesDir,
"META-INF/resources");
+ } else {
+ targetDir = srcResourcesDir;
+ }
targetDir.mkdirs();
- File source;
+ Path source;
if ("kamelet".equals(k) && localKameletDir != null) {
// source is a local kamelet
- source = new File(localKameletDir, f +
".kamelet.yaml");
+ source = Paths.get(localKameletDir, f +
".kamelet.yaml");
} else {
- source = new File(f);
+ source = Paths.get(f);
}
File out;
- if (source.isDirectory()) {
+ File srcFile = source.toFile();
+ if (srcFile.isDirectory()) {
out = targetDir;
} else {
- out = new File(targetDir, source.getName());
+ out = new File(targetDir, srcFile.getName());
}
if (!java) {
if (kamelet) {
- safeCopy(source, out, true);
+ safeCopy(srcFile, out, true);
} else if (jkube) {
// file should be renamed and moved into
src/main/jkube
f = f.replace(".jkube.yaml", ".yaml");
f = f.replace(".jkube.yml", ".yml");
out = new
File(srcCamelResourcesDir.getParentFile().getParentFile(), "jkube/" + f);
out.getParentFile().mkdirs();
- safeCopy(source, out, true);
+ safeCopy(srcFile, out, true);
} else {
out.getParentFile().mkdirs();
- safeCopy(source, out, true);
+ safeCopy(scheme, source, out, true);
}
} else {
// need to append package name in java source file
- List<String> lines =
Files.readAllLines(source.toPath());
+ List<String> lines = Files.readAllLines(source);
Optional<String> hasPackage = lines.stream().filter(l
-> l.trim().startsWith("package ")).findFirst();
FileOutputStream fos;
@@ -636,13 +655,13 @@ public abstract class ExportBaseCommand extends
CamelCommand {
if (pn != null) {
File dir = new File(srcJavaDirRoot,
pn.replace('.', File.separatorChar));
dir.mkdirs();
- out = new File(dir, source.getName());
+ out = new File(dir, srcFile.getName());
} else {
throw new IOException("Cannot determine
package name from source: " + source);
}
} else {
if (javaLiveReload) {
- out = new File(srcJavaDirRoot,
source.getName());
+ out = new File(srcJavaDirRoot,
srcFile.getName());
} else {
if (packageName != null &&
!"false".equalsIgnoreCase(packageName)) {
lines.add(0, "");
@@ -651,7 +670,7 @@ public abstract class ExportBaseCommand extends
CamelCommand {
}
}
if (javaLiveReload) {
- safeCopy(source, out, true);
+ safeCopy(srcFile, out, true);
} else {
fos = new FileOutputStream(out);
for (String line : lines) {
@@ -772,17 +791,25 @@ public abstract class ExportBaseCommand extends
CamelCommand {
}
protected void prepareUserProperties(Properties properties) {
- if (this.applicationProperties != null) {
- for (String s : this.applicationProperties) {
- String[] kv = s.split("=");
- if (kv.length != 2) {
- // likely a user mistake, we warn the user
- printer().println("WARN: property '" + s + "'' has a bad
format (should be 'key=value'), skipping.");
- } else {
- properties.put(kv[0], kv[1]);
+ properties.putAll(propertiesMap(this.applicationProperties));
+ }
+
+ protected Map<String, String> propertiesMap(String[]... propertySources) {
+ Map<String, String> result = new LinkedHashMap<>();
+ if (propertySources != null) {
+ for (String[] props : Arrays.stream(propertySources).filter((arr)
-> arr != null).toList()) {
+ for (String s : props) {
+ String[] kv = s.split("=");
+ if (kv.length != 2) {
+ // likely a user mistake, we warn the user
+ printer().println("WARN: property '" + s + "'' has a
bad format (should be 'key=value'), skipping.");
+ } else {
+ result.put(kv[0], kv[1]);
+ }
}
}
}
+ return result;
}
// Returns true if it has either an openapi spec or it uses contract-first
DSL
@@ -937,6 +964,16 @@ public abstract class ExportBaseCommand extends
CamelCommand {
return answer != null ? answer : "1.18.1";
}
+ private void safeCopy(String scheme, Path source, File target, boolean
override) throws Exception {
+ if ("classpath".equals(scheme)) {
+ try (var ins =
getClass().getClassLoader().getResourceAsStream(source.toString())) {
+ IOHelper.copy(ins, new FileOutputStream(target));
+ }
+ } else {
+ safeCopy(source.toFile(), target, override);
+ }
+ }
+
protected void safeCopy(File source, File target, boolean override) throws
Exception {
if (!source.exists()) {
return;
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
index 91a68d07957..790fa09cb9b 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
@@ -670,6 +670,8 @@ public class Run extends CamelCommand {
StringJoiner js = new StringJoiner(",");
StringJoiner sjReload = new StringJoiner(",");
StringJoiner sjClasspathFiles = new StringJoiner(",");
+ StringJoiner sjScriptFiles = new StringJoiner(",");
+ StringJoiner sjTlsFiles = new StringJoiner(",");
StringJoiner sjKamelets = new StringJoiner(",");
StringJoiner sjJKubeFiles = new StringJoiner(",");
@@ -704,12 +706,20 @@ public class Run extends CamelCommand {
file = loadFromClipboard(file);
} else if (skipFile(file)) {
continue;
+ } else if (isScriptFile(file)) {
+ // script files
+ sjScriptFiles.add(file);
+ continue;
+ } else if (isTlsFile(file)) {
+ // tls files
+ sjTlsFiles.add(file);
+ continue;
} else if (jkubeFile(file)) {
// jkube
sjJKubeFiles.add(file);
continue;
} else if (!knownFile(file) && !file.endsWith(".properties")) {
- // non known files to be added on classpath
+ // unknown files to be added on classpath
sjClasspathFiles.add(file);
continue;
}
@@ -808,6 +818,18 @@ public class Run extends CamelCommand {
} else {
writeSetting(main, profileProperties,
"camel.jbang.classpathFiles", () -> null);
}
+ if (sjScriptFiles.length() > 0) {
+ main.addInitialProperty("camel.jbang.scriptFiles",
sjScriptFiles.toString());
+ writeSettings("camel.jbang.scriptFiles", sjScriptFiles.toString());
+ } else {
+ writeSetting(main, profileProperties, "camel.jbang.scriptFiles",
() -> null);
+ }
+ if (sjTlsFiles.length() > 0) {
+ main.addInitialProperty("camel.jbang.tlsFiles",
sjTlsFiles.toString());
+ writeSettings("camel.jbang.tlsFiles", sjTlsFiles.toString());
+ } else {
+ writeSetting(main, profileProperties, "camel.jbang.tlsFiles", ()
-> null);
+ }
if (sjJKubeFiles.length() > 0) {
main.addInitialProperty("camel.jbang.jkubeFiles",
sjJKubeFiles.toString());
writeSettings("camel.jbang.jkubeFiles", sjJKubeFiles.toString());
@@ -1678,7 +1700,6 @@ public class Run extends CamelCommand {
if ("kamelet.yaml".equals(ext)) {
return true;
}
-
String ext2 = FileUtil.onlyExt(file, true);
if (ext2 != null) {
SourceScheme sourceScheme = SourceScheme.fromUri(file);
@@ -1790,6 +1811,14 @@ public class Run extends CamelCommand {
return false;
}
+ private boolean isScriptFile(String name) {
+ return name.endsWith(".sh");
+ }
+
+ private boolean isTlsFile(String name) {
+ return name.endsWith(".crt") || name.endsWith(".key") ||
name.endsWith(".pem");
+ }
+
private boolean jkubeFile(String name) {
return name.endsWith(".jkube.yaml") || name.endsWith(".jkube.yml");
}
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-kubernetes-pom.tmpl
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-kubernetes-pom.tmpl
index 1db225a66f2..aa7de71d577 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-kubernetes-pom.tmpl
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-kubernetes-pom.tmpl
@@ -132,14 +132,36 @@
<images>
<image>
<build>
- <from>${jkube.base.image}</from>
+ <from>${jkube.container-image.from}</from>
<entryPoint>
<exec>
- <arg>java</arg>
- <arg>-jar</arg>
-
<arg>/maven/${project.artifactId}-${project.version}.jar</arg>
+ <arg>/maven/run-java.sh</arg>
+ <arg>run</arg>
</exec>
</entryPoint>
+ <assembly>
+ <layers>
+ <layer>
+ <id>entrypoint</id>
+ <files>
+ <file>
+
<source>src/main/scripts/run-java.sh</source>
+
<outputDirectory>.</outputDirectory>
+ <fileMode>755</fileMode>
+ </file>
+ </files>
+ </layer>
+ <layer>
+ <id>tls</id>
+ <fileSets>
+ <fileSet>
+
<directory>src/main/tls</directory>
+
<outputDirectory>./tls</outputDirectory>
+ </fileSet>
+ </fileSets>
+ </layer>
+ </layers>
+ </assembly>
</build>
</image>
</images>
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/quarkus-kubernetes-pom.tmpl
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/quarkus-kubernetes-pom.tmpl
index 4e988d66ae3..be85e7f5a28 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/quarkus-kubernetes-pom.tmpl
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/quarkus-kubernetes-pom.tmpl
@@ -97,7 +97,13 @@
<images>
<image>
<build>
- <from>${jkube.base.image}</from>
+ <from>${jkube.container-image.from}</from>
+ <entryPoint>
+ <exec>
+ <arg>/maven/quarkus/run-java.sh</arg>
+ <arg>run</arg>
+ </exec>
+ </entryPoint>
<assembly>
<layers>
<layer>
@@ -109,15 +115,27 @@
</fileSet>
</fileSets>
</layer>
+ <layer>
+ <id>entrypoint</id>
+ <files>
+ <file>
+
<source>src/main/scripts/run-java.sh</source>
+
<outputDirectory>./quarkus</outputDirectory>
+ <fileMode>755</fileMode>
+ </file>
+ </files>
+ </layer>
+ <layer>
+ <id>tls</id>
+ <fileSets>
+ <fileSet>
+
<directory>src/main/tls</directory>
+
<outputDirectory>./quarkus/tls</outputDirectory>
+ </fileSet>
+ </fileSets>
+ </layer>
</layers>
</assembly>
- <entryPoint>
- <exec>
- <arg>java</arg>
- <arg>-jar</arg>
-
<arg>/maven/quarkus/quarkus-run.jar</arg>
- </exec>
- </entryPoint>
</build>
</image>
</images>
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/run-java.sh
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/run-java.sh
index ccaa79017e8..f71b92be4f9 100755
--- a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/run-java.sh
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/run-java.sh
@@ -29,7 +29,7 @@
#
#
# This script will pick up either a 'fat' jar which can be run with "-jar"
-# or you can sepcify a JAVA_MAIN_CLASS.
+# or you can specify a JAVA_MAIN_CLASS.
#
# Source and Documentation can be found
# at
https://github.com/fabric8io-images/run-java-sh/blob/v1.3.8/fish-pepper/run-java-sh/fp-files/run-java.sh
@@ -482,8 +482,52 @@ gc_options() {
java_default_options() {
# Echo options, trimming trailing and multiple spaces
- echo "$(memory_options) $(jit_options) $(diagnostics_options) $(cpu_options)
$(gc_options)" | awk '$1=$1'
+ echo "$(memory_options) $(jit_options) $(diagnostics_options) $(cpu_options)
$(gc_options) $(ssl_options)" | awk '$1=$1'
+}
+
+#
==============================================================================
+has_ssl_certificates() {
+ truststoreCertFiles=""
+ # Loop through each file in the CSV string
+ for file in ${SSL_TRUSTSTORE_CERTIFICATES:-}; do
+ # If file is not an absolute path, prepend the script dir
+ if [ "${file#/}" = "$file" ]; then
+ file="$(script_dir)/$file"
+ fi
+ if [ -f "$file" ] && [ "${file##*.}" = "crt" ]; then
+
truststoreCertFiles="${truststoreCertFiles:+$truststoreCertFiles,}$file"
+ found=true
+ break
+ fi
+ done
+ if [ "${found:-false}" = true ]; then
+ truststoreFile=${JAVA_TRUSTSTORE_LOCATION:-/tmp/truststore.jks}
+ truststorePass=${JAVA_TRUSTSTORE_PASSWORD:-changeit}
+ return 0
+ else
+ return 1
+ fi
+}
+
+ssl_options() {
+ local opts=""
+ if has_ssl_certificates; then
+ opts="-Djavax.net.ssl.trustStore=${truststoreFile}
-Djavax.net.ssl.trustStorePassword=${truststorePass}"
+ fi
+ echo $opts
+}
+
+ssl_truststore() {
+ IFS=','
+ if has_ssl_certificates; then
+ for crt in $truststoreCertFiles; do
+ alias=$(basename "$crt" .crt)
+ echo "Importing certificate: ${crt} to ${truststoreFile}" >&2
+ keytool -import -alias ${alias} -file ${crt} -keystore ${truststoreFile}
-storepass ${truststorePass} -noprompt >&2
+ done
+ fi
+ IFS=' '
}
#
==============================================================================
@@ -542,7 +586,7 @@ exec_args() {
# Combine all java options
java_options() {
- # Normalize spaces with awk (i.e. trim and elimate double spaces)
+ # Normalize spaces with awk (i.e. trim and eliminate double spaces)
# See e.g. https://www.physicsforums.com/threads/awk-1-1-1-file-txt.658865/
for an explanation
# of this awk idiom
echo "${JAVA_OPTIONS:-} $(run_java_options) $(debug_options)
$(proxy_options) $(java_default_options)" | awk '$1=$1'
@@ -618,6 +662,9 @@ options() {
if [ $(hasflag --gc) ]; then
ret="$ret $(gc_options)"
fi
+ if [ $(hasflag --ssl) ]; then
+ ret="$ret $(ssl_options)"
+ fi
echo $ret | awk '$1=$1'
}
@@ -637,6 +684,10 @@ run() {
echo "Either JAVA_MAIN_CLASS or JAVA_APP_JAR needs to be given"
exit 1
fi
+
+ # Optionally create an SSL truststore
+ ssl_truststore
+
# Don't put ${args} in quotes, otherwise it would be interpreted as a single
arg.
# However it could be two args (see above). zsh doesn't like this btw, but
zsh is not
# supported anyway.
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/spring-boot-kubernetes-pom.tmpl
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/spring-boot-kubernetes-pom.tmpl
index 7de1b7bc0f0..3b2390dcf8a 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/spring-boot-kubernetes-pom.tmpl
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/spring-boot-kubernetes-pom.tmpl
@@ -87,14 +87,36 @@
<images>
<image>
<build>
- <from>${jkube.base.image}</from>
+ <from>${jkube.container-image.from}</from>
<entryPoint>
<exec>
- <arg>java</arg>
- <arg>-jar</arg>
-
<arg>/maven/${project.artifactId}-${project.version}.jar</arg>
+ <arg>/maven/run-java.sh</arg>
+ <arg>run</arg>
</exec>
</entryPoint>
+ <assembly>
+ <layers>
+ <layer>
+ <id>entrypoint</id>
+ <files>
+ <file>
+
<source>src/main/scripts/run-java.sh</source>
+
<outputDirectory>.</outputDirectory>
+ <fileMode>755</fileMode>
+ </file>
+ </files>
+ </layer>
+ <layer>
+ <id>tls</id>
+ <fileSets>
+ <fileSet>
+
<directory>src/main/tls</directory>
+
<outputDirectory>./tls</outputDirectory>
+ </fileSet>
+ </fileSets>
+ </layer>
+ </layers>
+ </assembly>
</build>
</image>
</images>
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 301675cf75f..e71ec31504a 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
@@ -210,6 +210,7 @@ public class KubernetesExport extends Export {
List<Source> sources;
try {
+ addFile("classpath:templates/run-java.sh");
sources = SourceHelper.resolveSources(files);
} catch (Exception e) {
printer().printf("Project export failed: %s - %s%n",
e.getMessage(),
@@ -227,9 +228,15 @@ public class KubernetesExport extends Export {
.filter(parts -> parts.length == 2)
.collect(Collectors.toMap(parts -> parts[0], parts ->
parts[1])));
+ annotations = Optional.ofNullable(annotations).orElse(new String[0]);
+ context.addAnnotations(Arrays.stream(annotations)
+ .map(item -> item.split("="))
+ .filter(parts -> parts.length == 2)
+ .collect(Collectors.toMap(parts -> parts[0], parts ->
parts[1])));
+
// Add labels to TraitContext
//
- // Generated by quarkus/jkube
+ // Generated by jkube
// app.kubernetes.io/name
// app.kubernetes.io/version
//
@@ -247,17 +254,20 @@ public class KubernetesExport extends Export {
context.setServiceAccount(serviceAccount);
}
- // application.properties
- String[] applicationProperties = extractPropertiesTraits(new
File("application.properties"));
-
// application-{profile}.properties
- String[] applicationProfileProperties = null;
+ var applicationProfileProperties = new String[0];
if (this.profile != null) {
// override from profile specific configuration
applicationProfileProperties = extractPropertiesTraits(new
File("application-" + profile + ".properties"));
}
- Traits traitsSpec = getTraitSpec(applicationProperties,
applicationProfileProperties);
+ Traits traitsSpec = getTraitSpec(applicationProfileProperties,
applicationProperties);
+
+ // Map properties to env variables (where needed)
+ var propsMap = propertiesMap(applicationProfileProperties,
applicationProperties);
+ if (propsMap.containsKey("ssl.truststore.certificates")) {
+ addEnvVar("SSL_TRUSTSTORE_CERTIFICATES",
propsMap.get("ssl.truststore.certificates"));
+ }
TraitHelper.configureMountTrait(traitsSpec, configs, resources,
volumes);
if (openapi != null && openapi.startsWith("configmap:")) {
@@ -309,7 +319,7 @@ public class KubernetesExport extends Export {
baseImage = "%s/%s".formatted(registryMirror, baseImage);
}
- buildProperties.add("jkube.base.image=%s".formatted(baseImage));
+
buildProperties.add("jkube.container-image.from=%s".formatted(baseImage));
buildProperties.add("jkube.build.strategy=%s".formatted(imageBuilder));
if ("jib".equals(imageBuilder)) {
@@ -387,7 +397,7 @@ public class KubernetesExport extends Export {
return super.export(cmd);
}
- protected Traits getTraitSpec(String[] applicationProperties, String[]
applicationProfileProperties) {
+ protected Traits getTraitSpec(String[] applicationProfileProperties,
String[] applicationProperties) {
var annotationsTraits =
TraitHelper.extractTraitsFromAnnotations(this.annotations);
var allTraits = TraitHelper.mergeTraits(traits, annotationsTraits,
applicationProfileProperties, applicationProperties);
@@ -402,6 +412,24 @@ public class KubernetesExport extends Export {
return traitsSpec;
}
+ private void addFile(String file) {
+ if (!files.contains(file)) {
+ // ensure mutability
+ files = new ArrayList<>(files);
+ files.add(file);
+ }
+ }
+
+ private void addEnvVar(String key, String value) {
+ var envArray = Optional.ofNullable(envVars).orElse(new String[0]);
+ var envList = new ArrayList<>(Arrays.asList(envArray));
+ var envEntry = "%s=%s".formatted(key, value);
+ if (!envList.contains(envEntry)) {
+ envList.add(envEntry);
+ envVars = envList.toArray(new String[0]);
+ }
+ }
+
private void addLabel(String key, String value) {
var labelArray = Optional.ofNullable(labels).orElse(new String[0]);
var labelList = new ArrayList<>(Arrays.asList(labelArray));
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 27499e307a8..2385e78d268 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
@@ -64,7 +64,7 @@ class KubernetesExportTest extends KubernetesExportBaseTest {
Properties props = model.getProperties();
Assertions.assertEquals("examples/route:1.0.0",
props.get("jkube.image.name"));
- Assertions.assertEquals("eclipse-temurin:17",
props.get("jkube.base.image"));
+ Assertions.assertEquals("eclipse-temurin:17",
props.get("jkube.container-image.from"));
Assertions.assertEquals("jib", props.get("jkube.build.strategy"));
Assertions.assertNull(props.get("jkube.docker.push.registry"));
Assertions.assertNull(props.get("jkube.container-image.registry"));
@@ -106,7 +106,7 @@ class KubernetesExportTest extends KubernetesExportBaseTest
{
Properties props = model.getProperties();
Assertions.assertEquals("quay.io/camel-riders/route:1.0-SNAPSHOT",
props.get("jkube.image.name"));
- Assertions.assertEquals("mirror.gcr.io/my-base-image:latest",
props.get("jkube.base.image"));
+ Assertions.assertEquals("mirror.gcr.io/my-base-image:latest",
props.get("jkube.container-image.from"));
Assertions.assertEquals("docker", props.get("jkube.build.strategy"));
Assertions.assertEquals("quay.io",
props.get("jkube.docker.push.registry"));
Assertions.assertEquals("quay.io",
props.get("jkube.container-image.registry"));