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 7992aa5b45b4 CAMEL-24662: camel-jbang: fix --cluster-type being 
silently overridden by auto-detection (#27216)
7992aa5b45b4 is described below

commit 7992aa5b45b48aeb7403901e93d90a5541f2ae43
Author: Guillaume Nodet <[email protected]>
AuthorDate: Tue Oct 6 11:22:54 2026 +0200

    CAMEL-24662: camel-jbang: fix --cluster-type being silently overridden by 
auto-detection (#27216)
    
    * CAMEL-24662: fix --cluster-type being overridden by auto-detection
    
    When the user explicitly passes --cluster-type, the detectCluster() method
    was unconditionally overwriting the field with the auto-detected value,
    since clusterType defaulted to "Kubernetes" and picocli could not
    distinguish the default from an explicit user-supplied value.
    
    Fix: set clusterType to null (matching KubernetesExport), so that
    detectCluster() skips auto-detection when the user has explicitly
    provided --cluster-type. If no explicit value is given and auto-
    detection is disabled, fall back to KUBERNETES as the default.
    
    Co-authored-by: Claude Sonnet <[email protected]>
    
    * CAMEL-24662: apply per-cluster defaults for explicit --cluster-type
    
    When --cluster-type is passed explicitly, auto-detection is skipped but
    the per-cluster defaults (minikube: imageBuilder=docker, imagePush=false;
    openshift: imageGroup=namespace) were also skipped, causing builds with
    jib + push to localhost:5000 for explicit --cluster-type=minikube.
    
    Fix: restructure detectCluster() to apply per-cluster defaults based on
    the resolved clusterType (explicit or detected), independent of the
    auto-detection step. The --disable-auto flag still suppresses both
    detection and defaults.
    
    Add test: explicit --cluster-type=minikube must set imageBuilder=docker
    and imagePush=false.
    Docs: note that --cluster-type skips detection while applying defaults.
    
    ---------
    
    Co-authored-by: Claude Sonnet <[email protected]>
---
 .../modules/ROOT/pages/camel-jbang-kubernetes.adoc |  1 +
 .../core/commands/kubernetes/KubernetesRun.java    | 23 +++++++-----
 .../kubernetes/KubernetesRunCustomTest.java        | 41 ++++++++++++++++++++++
 3 files changed, 56 insertions(+), 9 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 38a1b40118f5..094c55ed5b79 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-kubernetes.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-kubernetes.adoc
@@ -30,6 +30,7 @@ This exports a Spring Boot project named `my-app`, builds the 
container image, p
 `kubectl` is connected to. The runtime is one of `spring-boot`, `quarkus` (the 
default) or `main`.
 
 Local clusters (Kind, Minikube) and OpenShift are detected, and the image 
registry is configured for them.
+Use `--cluster-type` to set the cluster type explicitly, skipping 
auto-detection while still applying the cluster-specific defaults.
 For any other cluster, tell the plugin where to push the image:
 
 [source,bash]
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesRun.java
 
b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesRun.java
index f2355b240ac7..5b16e24f4516 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesRun.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesRun.java
@@ -164,7 +164,7 @@ public class KubernetesRun extends KubernetesBaseCommand {
                         completionCandidates = 
ClusterTypeCompletionCandidates.class,
                         converter = ClusterTypeConverter.class,
                         description = "The target cluster type 
(${COMPLETION-CANDIDATES}). Special configurations may be applied to different 
cluster types such as Kind or Minikube.")
-    String clusterType = "Kubernetes";
+    String clusterType;
 
     @CommandLine.Option(names = { "--image-build" }, defaultValue = "true",
                         description = "Whether to build container image as 
part of the run.")
@@ -807,23 +807,28 @@ public class KubernetesRun extends KubernetesBaseCommand {
     }
 
     private void detectCluster() {
-        if (!disableAuto) {
+        if (!disableAuto && clusterType == null) {
             if (verbose) {
                 printer().print("Automatic Kubernetes cluster detection... ");
             }
-            ClusterType cluster = KubernetesHelper.discoverClusterType();
-            this.clusterType = cluster.name();
-            if (ClusterType.MINIKUBE == cluster) {
+            this.clusterType = KubernetesHelper.discoverClusterType().name();
+            if (verbose) {
+                printer().println(this.clusterType);
+            }
+        }
+        if (clusterType == null) {
+            this.clusterType = ClusterType.KUBERNETES.name();
+        }
+        if (!disableAuto) {
+            // Apply per-cluster defaults for the resolved cluster type 
(explicit or detected)
+            if (ClusterType.MINIKUBE.isEqualTo(clusterType)) {
                 this.imageBuilder = "docker";
                 this.imagePush = false;
-            } else if (ClusterType.OPENSHIFT == cluster) {
+            } else if (ClusterType.OPENSHIFT.isEqualTo(clusterType)) {
                 if (ObjectHelper.isEmpty(imageGroup)) {
                     this.imageGroup = client().getNamespace();
                 }
             }
-            if (verbose) {
-                printer().println(this.clusterType);
-            }
         }
     }
 
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesRunCustomTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesRunCustomTest.java
index 712825ea4e54..02c187a7c212 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesRunCustomTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesRunCustomTest.java
@@ -160,6 +160,47 @@ class KubernetesRunCustomTest {
         Assertions.assertEquals("val-B", materializedProps.get("b"));
     }
 
+    @Test
+    @SetEnvironmentVariable(key = "MINIKUBE_ACTIVE_DOCKERD", value = "foo")
+    @SetEnvironmentVariable(key = "DOCKER_TLS_VERIFY", value = "foo")
+    public void explicitMinikubeClusterTypeShouldApplyDefaults() throws 
Exception {
+        // Even without auto-detection (minikube env vars are set but ignored 
because clusterType is explicit),
+        // passing --cluster-type=minikube should still apply the minikube 
defaults:
+        // imageBuilder=docker and imagePush=false.
+        KubernetesHelper.setKubernetesClient(client);
+        setupServerExpectsMinikube();
+        KubernetesRun command = createCommand(List.of("classpath:route.yaml"),
+                "--image-registry=quay.io", "--image-group=camel-test", 
"--output=yaml",
+                "--cluster-type=minikube");
+        int exit = command.doCall();
+
+        Assertions.assertEquals(0, exit, printer.getOutput());
+        Assertions.assertEquals(ClusterType.MINIKUBE.name().toLowerCase(), 
command.clusterType.toLowerCase(),
+                printer.getOutput());
+        // Per-cluster defaults must be applied even when cluster type is set 
explicitly
+        Assertions.assertFalse(command.imagePush, "imagePush should be false 
for explicit minikube");
+        Assertions.assertEquals("docker", command.imageBuilder, "imageBuilder 
should be docker for explicit minikube");
+    }
+
+    @Test
+    @SetEnvironmentVariable(key = "MINIKUBE_ACTIVE_DOCKERD", value = "foo")
+    @SetEnvironmentVariable(key = "DOCKER_TLS_VERIFY", value = "foo")
+    public void explicitClusterTypeShouldNotBeOverriddenByAutoDetection() 
throws Exception {
+        // Minikube env is active (MINIKUBE_ACTIVE_DOCKERD + DOCKER_TLS_VERIFY 
set),
+        // but user explicitly passes --cluster-type=openshift: the explicit 
value must win.
+        KubernetesHelper.setKubernetesClient(client);
+        setupServerExpectsMinikube();
+        KubernetesRun command = createCommand(List.of("classpath:route.yaml"),
+                "--image-registry=quay.io", "--image-group=camel-test", 
"--output=yaml",
+                "--cluster-type=openshift");
+        int exit = command.doCall();
+
+        Assertions.assertEquals(0, exit, printer.getOutput());
+        // The explicit --cluster-type must be preserved, not overridden by 
Minikube auto-detection.
+        Assertions.assertEquals(ClusterType.OPENSHIFT.name().toLowerCase(), 
command.clusterType.toLowerCase(),
+                printer.getOutput());
+    }
+
     @Test
     @SetEnvironmentVariable(key = "MINIKUBE_ACTIVE_DOCKERD", value = "foo")
     @SetEnvironmentVariable(key = "DOCKER_TLS_VERIFY", value = "foo")

Reply via email to