Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ The container trait is able to customize the container specification with follow
| PullPolicy
| The pull policy: Always\|Never\|IfNotPresent

| container.image-pull-secrets
| string[]
| The pull secrets for private registries

| container.image-push
| boolean
| Enable image push to the registry

| container.request-cpu
| string
| The minimum amount of CPU required.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,13 @@
<version>${camel.main.jkube.version}</version>
<configuration>
<imagePullPolicy>${camel.main.kubernetes.image-pull-policy}</imagePullPolicy>
<buildStrategy>docker</buildStrategy>
<buildStrategy>${jkube.build.strategy}</buildStrategy>
<images>
<image>
<name>${camel.main.kubernetes.image-name}</name>
<build>
<from>eclipse-temurin:{{ .JavaVersion }}</from>
<!-- Supported only when using the jib build strategy -->
<createImageOptions>
<platform>linux/amd64</platform>
<platform>linux/arm64</platform>
Expand All @@ -158,6 +159,7 @@
<goals>
<goal>build</goal>
<goal>resource</goal>
<goal>push</goal>
</goals>
<phase>package</phase>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@
<version>${camel.springboot.jkube.version}</version>
<configuration>
<imagePullPolicy>${camel.springboot.kubernetes.image-pull-policy}</imagePullPolicy>
<buildStrategy>docker</buildStrategy>
<buildStrategy>${jkube.build.strategy}</buildStrategy>
<images>
<image>
<name>${camel.springboot.kubernetes.image-name}</name>
<build>
<from>eclipse-temurin:{{ .JavaVersion }}</from>
<!-- Supported only when using the jib build strategy -->
<createImageOptions>
<platform>linux/amd64</platform>
<platform>linux/arm64</platform>
Expand All @@ -109,6 +110,7 @@
<goals>
<goal>build</goal>
<goal>resource</goal>
<goal>push</goal>
</goals>
<phase>package</phase>
</execution>
Expand Down
12 changes: 12 additions & 0 deletions dsl/camel-jbang/camel-jbang-plugin-kubernetes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@
<artifactId>camel-jbang-core</artifactId>
</dependency>

<!-- Needed for TLS access to private registries -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>${bouncycastle-version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
<version>${bouncycastle-version}</version>
</dependency>

<!-- Kubernetes -->
<dependency>
<groupId>io.fabric8</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum ClusterType {
KUBERNETES,
OPENSHIFT,
KIND,
K3S,
MINIKUBE;

public static ClusterType fromName(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public class KubernetesExport extends Export {
description = "The image registry group used to push images to.")
protected String imageGroup;

@CommandLine.Option(names = { "--image-builder" },
@CommandLine.Option(names = { "--image-builder" }, defaultValue = "jib",
description = "The image builder used to build the container image (e.g. docker, jib, podman, s2i).")
protected String imageBuilder;

Expand Down Expand Up @@ -187,14 +187,17 @@ public Integer export() throws Exception {
propPrefix = runtime.runtime();
}

boolean useQuarkusPlugin = runtime == RuntimeType.quarkus;
boolean useJKubePlugin = !useQuarkusPlugin;

// Resolve image group and registry
String resolvedImageGroup = resolveImageGroup();
if (resolvedImageGroup != null) {
buildProperties.add("%s.container-image.group=%s".formatted(propPrefix, resolvedImageGroup));
}

String resolvedImageRegistry = resolveImageRegistry();
if (resolvedImageRegistry != null) {
if (useQuarkusPlugin && resolvedImageRegistry != null) {
var allowInsecure = resolvedImageRegistry.startsWith("localhost");
buildProperties.add("%s.container-image.registry=%s".formatted(propPrefix, resolvedImageRegistry));
buildProperties.add("%s.container-image.insecure=%b".formatted(propPrefix, allowInsecure));
Expand Down Expand Up @@ -289,14 +292,25 @@ public Integer export() throws Exception {
buildProperties.add("%s.kubernetes.image-pull-policy=%s".formatted(propPrefix, imagePullPolicy));
}

if (useJKubePlugin) {
if ("docker".equals(imageBuilder) || "jib".equals(imageBuilder)) {
buildProperties.add("jkube.build.strategy=%s".formatted(imageBuilder));
}
if (resolvedImageRegistry != null) {
buildProperties.add("jkube.docker.push.registry=%s".formatted(resolvedImageRegistry));
}
var skipPush = !container.getImagePush();
buildProperties.add("jkube.skip.push=%b".formatted(skipPush));
}

// Runtime specific for Main
if (runtime == RuntimeType.main) {
addDependencies("org.apache.camel:camel-health",
"org.apache.camel:camel-platform-http-main");
}

// Runtime specific for Quarkus
if (runtime == RuntimeType.quarkus) {
if (useQuarkusPlugin) {

// Quarkus specific dependencies
if (ClusterType.OPENSHIFT.isEqualTo(clusterType)) {
Expand Down Expand Up @@ -325,8 +339,8 @@ public Integer export() throws Exception {
buildProperties.add("quarkus.container-image.build=true");
}

// SpringBoot Runtime specific
if (runtime == RuntimeType.springBoot || runtime == RuntimeType.main) {
// SpringBoot/Main Runtime specific
if (useJKubePlugin) {
if (ClusterType.OPENSHIFT.isEqualTo(clusterType)) {
buildProperties.add("%s.jkube.maven.plugin=%s".formatted(propPrefix, "openshift-maven-plugin"));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

package org.apache.camel.dsl.jbang.core.commands.kubernetes.traits;

import java.util.List;
import java.util.Map;
import java.util.Optional;

import io.fabric8.kubernetes.api.model.LabelSelectorBuilder;
import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.Container;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.Traits;

public class DeploymentTrait extends BaseTrait {
Expand All @@ -46,6 +49,15 @@ public void apply(Traits traitConfig, TraitContext context) {
.build())
.endSpec();

Container containerTrait = Optional.ofNullable(traitConfig.getContainer()).orElseGet(Container::new);
Optional.ofNullable(containerTrait.getImagePullSecrets()).orElseGet(List::of).forEach(sec -> deployment.editSpec()
.editOrNewTemplate()
.editOrNewSpec()
.addNewImagePullSecret(sec)
.endSpec()
.endTemplate()
.endSpec());

if (context.getServiceAccount() != null) {
deployment.editSpec()
.editOrNewTemplate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ public TraitContext(String name, String version, Printer printer, CamelCatalog c

/**
* Adds a resource that should be created as part of the Camel app.
*
* @param resource
*/
public void add(VisitableBuilder<?, ?> resource) {
resourceRegistry.add(resource);
Expand Down Expand Up @@ -235,9 +233,8 @@ public String getServiceAccount() {
/**
* Performs source metadata inspection and uses local cache to not inspect the same source over and over again.
*
* @param source the source to inspect and create the metadata from.
* @return the metadata holding information such as components, endpoints, languages used with the source.
* @throws Exception
* @param source the source to inspect and create the metadata from.
* @return the metadata holding information such as components, endpoints, languages used with the source.
*/
public SourceMetadata inspectMetaData(Source source) throws Exception {
if (sourceMetadata.containsKey(source.name())) {
Expand All @@ -252,8 +249,6 @@ public SourceMetadata inspectMetaData(Source source) throws Exception {
/**
* Inspect all sources in this context and retrieve the source metadata. Uses internal cache for sources that have
* already been inspected.
*
* @return
*/
public List<SourceMetadata> getSourceMetadata() {
List<SourceMetadata> answer = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"allowPrivilegeEscalation", "auto", "capabilitiesAdd", "capabilitiesDrop", "enabled", "expose",
"image", "imagePullPolicy", "limitCPU", "limitMemory", "name", "port", "portName", "requestCPU", "requestMemory",
"image", "imagePullPolicy", "imagePullSecrets", "limitCPU", "limitMemory", "name", "port", "portName", "requestCPU",
"requestMemory",
"runAsNonRoot", "runAsUser", "seccompProfileType", "servicePort", "servicePortName" })
public class Container {
@JsonProperty("allowPrivilegeEscalation")
Expand Down Expand Up @@ -73,6 +74,16 @@ public class Container {
@JsonSetter(
nulls = Nulls.SKIP)
private ImagePullPolicy imagePullPolicy;
@JsonProperty("imagePullSecrets")
@JsonPropertyDescription("The pull secrets for private registries")
@JsonSetter(
nulls = Nulls.SKIP)
private List<String> imagePullSecrets;
@JsonProperty("imagePush")
@JsonPropertyDescription("Enable image push to the registry")
@JsonSetter(
nulls = Nulls.SKIP)
private boolean imagePush;
@JsonProperty("limitCPU")
@JsonPropertyDescription("The maximum amount of CPU to be provided (default 500 millicores).")
@JsonSetter(
Expand Down Expand Up @@ -201,6 +212,22 @@ public void setImagePullPolicy(ImagePullPolicy imagePullPolicy) {
this.imagePullPolicy = imagePullPolicy;
}

public List<String> getImagePullSecrets() {
return imagePullSecrets;
}

public void setImagePullSecrets(List<String> imagePullSecret) {
this.imagePullSecrets = imagePullSecret;
}

public boolean getImagePush() {
return imagePush;
}

public void setImagePush(boolean imagePush) {
this.imagePush = imagePush;
}

public String getLimitCPU() {
return this.limitCPU;
}
Expand Down