From a29620dfc7b7e03daf32fefcc8bb24829e158fc3 Mon Sep 17 00:00:00 2001 From: Ioannis Canellos Date: Tue, 11 Jul 2023 16:02:42 +0300 Subject: [PATCH] fix: don't mask deployment target. --- .../main/java/io/quarkus/cli/deploy/Kind.java | 9 ++++-- .../io/quarkus/cli/deploy/Kubernetes.java | 8 +++-- .../java/io/quarkus/cli/deploy/Minikube.java | 8 +++-- .../java/io/quarkus/cli/deploy/Openshift.java | 8 +++-- .../cli/deploy/CliDeployGradleTest.java | 30 +++++++++++++++---- .../cli/deploy/CliDeployMavenTest.java | 26 ++++++++++++---- 6 files changed, 68 insertions(+), 21 deletions(-) diff --git a/devtools/cli/src/main/java/io/quarkus/cli/deploy/Kind.java b/devtools/cli/src/main/java/io/quarkus/cli/deploy/Kind.java index 43b45bd396254..7ed69a6a910c1 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/deploy/Kind.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/deploy/Kind.java @@ -1,5 +1,7 @@ package io.quarkus.cli.deploy; +import java.util.Optional; + import io.quarkus.cli.BuildToolContext; import picocli.CommandLine; @@ -20,15 +22,16 @@ public enum DeploymentKind { } @CommandLine.Option(names = { "--deployment-kind" }, description = "The kind of resource to generate and deploy") - public DeploymentKind kind = DeploymentKind.Deployment; + public Optional kind; @Override public void populateContext(BuildToolContext context) { super.populateContext(context); context.getPropertiesOptions().properties.put(String.format(QUARKUS_DEPLOY_FORMAT, KIND), "true"); - context.getPropertiesOptions().properties.put(DEPLOYMENT_KIND, kind.name()); context.getForcedExtensions().add(KIND_EXTENSION); context.getForcedExtensions().add(CONTAINER_IMAGE_EXTENSION); + kind.ifPresent(k -> { + context.getPropertiesOptions().properties.put(DEPLOYMENT_KIND, k.name()); + }); } - } diff --git a/devtools/cli/src/main/java/io/quarkus/cli/deploy/Kubernetes.java b/devtools/cli/src/main/java/io/quarkus/cli/deploy/Kubernetes.java index a365d84adf370..44275ca0a8673 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/deploy/Kubernetes.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/deploy/Kubernetes.java @@ -1,5 +1,7 @@ package io.quarkus.cli.deploy; +import java.util.Optional; + import io.quarkus.cli.BuildToolContext; import picocli.CommandLine; @@ -20,17 +22,19 @@ public enum DeploymentKind { } @CommandLine.Option(names = { "--deployment-kind" }, description = "The kind of resource to generate and deploy") - public DeploymentKind kind = DeploymentKind.Deployment; + public Optional kind; @Override public void populateContext(BuildToolContext context) { super.populateContext(context); context.getPropertiesOptions().properties.put(String.format(QUARKUS_DEPLOY_FORMAT, KUBERNETES), "true"); - context.getPropertiesOptions().properties.put(DEPLOYMENT_KIND, kind.name()); context.getForcedExtensions().add(KUBERNETES_EXTENSION); context.getForcedExtensions().add(CONTAINER_IMAGE_EXTENSION); kubernetesOptions.imageBuilder.or(implicitImageBuilder()).ifPresent(imageBuilder -> { context.getForcedExtensions().add(CONTAINER_IMAGE_EXTENSION + "-" + imageBuilder); }); + kind.ifPresent(k -> { + context.getPropertiesOptions().properties.put(DEPLOYMENT_KIND, k.name()); + }); } } diff --git a/devtools/cli/src/main/java/io/quarkus/cli/deploy/Minikube.java b/devtools/cli/src/main/java/io/quarkus/cli/deploy/Minikube.java index a18c3b7a4fec3..b39483d6e8188 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/deploy/Minikube.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/deploy/Minikube.java @@ -1,5 +1,7 @@ package io.quarkus.cli.deploy; +import java.util.Optional; + import io.quarkus.cli.BuildToolContext; import picocli.CommandLine; @@ -20,14 +22,16 @@ public enum DeploymentKind { } @CommandLine.Option(names = { "--deployment-kind" }, description = "The kind of resource to generate and deploy") - public DeploymentKind kind = DeploymentKind.Deployment; + public Optional kind; @Override public void populateContext(BuildToolContext context) { super.populateContext(context); context.getPropertiesOptions().properties.put(String.format(QUARKUS_DEPLOY_FORMAT, MINIKUBE), "true"); - context.getPropertiesOptions().properties.put(DEPLOYMENT_KIND, kind.name()); context.getForcedExtensions().add(MINIKUBE_EXTENSION); context.getForcedExtensions().add(CONTAINER_IMAGE_EXTENSION); + kind.ifPresent(k -> { + context.getPropertiesOptions().properties.put(DEPLOYMENT_KIND, k.name()); + }); } } diff --git a/devtools/cli/src/main/java/io/quarkus/cli/deploy/Openshift.java b/devtools/cli/src/main/java/io/quarkus/cli/deploy/Openshift.java index 9677ca65aec35..fcfd245e51f07 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/deploy/Openshift.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/deploy/Openshift.java @@ -1,5 +1,7 @@ package io.quarkus.cli.deploy; +import java.util.Optional; + import io.quarkus.cli.BuildToolContext; import picocli.CommandLine; @@ -20,14 +22,16 @@ public enum DeploymentKind { } @CommandLine.Option(names = { "--deployment-kind" }, description = "The kind of resource to generate and deploy") - public DeploymentKind kind = DeploymentKind.DeploymentConfig; + public Optional kind; @Override public void populateContext(BuildToolContext context) { super.populateContext(context); context.getPropertiesOptions().properties.put(String.format(QUARKUS_DEPLOY_FORMAT, OPENSHIFT), "true"); - context.getPropertiesOptions().properties.put(DEPLOYMENT_KIND, kind.name()); context.getForcedExtensions().add(OPENSHIFT_EXTENSION); + kind.ifPresent(k -> { + context.getPropertiesOptions().properties.put(DEPLOYMENT_KIND, k.name()); + }); } @Override diff --git a/devtools/cli/src/test/java/io/quarkus/cli/deploy/CliDeployGradleTest.java b/devtools/cli/src/test/java/io/quarkus/cli/deploy/CliDeployGradleTest.java index 71ee0f49e645c..6bc80ab4b8585 100644 --- a/devtools/cli/src/test/java/io/quarkus/cli/deploy/CliDeployGradleTest.java +++ b/devtools/cli/src/test/java/io/quarkus/cli/deploy/CliDeployGradleTest.java @@ -1,6 +1,7 @@ package io.quarkus.cli.deploy; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; @@ -97,14 +98,15 @@ public void testUsage() throws Exception { assertTrue(result.getStdout().contains("--no-daemon")); assertTrue(result.getStdout().contains("--no-build-cache")); - testDeployer("kubernetes", "docker"); - testDeployer("knative", "docker"); - testDeployer("minikube", "docker"); - testDeployer("kind", "docker"); - testDeployer("openshift", "openshift"); + testDeployer("kubernetes", "kubernetes", "docker"); + testDeployer("minikube", "kubernetes", "docker"); + testDeployer("kind", "kubernetes", "docker"); + testDeployer("openshift", "openshift", "openshift"); + testDeployer("knative", "knative", "docker"); + } - protected void testDeployer(String deployer, String defaultImageBuilder) throws Exception { + protected void testDeployer(String deployer, String configGroup, String defaultImageBuilder) throws Exception { CliDriver.Result result = CliDriver.execute(project, "deploy", deployer, "--dry-run"); assertEquals(CommandLine.ExitCode.OK, result.getExitCode(), "Expected OK return code." + result); assertTrue(result.getStdout().contains("deploy")); @@ -112,6 +114,7 @@ protected void testDeployer(String deployer, String defaultImageBuilder) throws assertTrue(result.getStdout().contains("--no-build-cache")); assertTrue(result.getStdout().contains("-Dquarkus." + deployer + ".deploy=true")); assertTrue(result.getStdout().contains("--init-script=")); + assertFalse(result.getStdout().contains("-Dquarkus." + configGroup + ".deployment-kind")); result = CliDriver.execute(project, "deploy", deployer, "--image-build", "--dry-run"); assertEquals(CommandLine.ExitCode.OK, result.getExitCode(), "Expected OK return code." + result); @@ -121,6 +124,7 @@ protected void testDeployer(String deployer, String defaultImageBuilder) throws assertTrue(result.getStdout().contains("-Dquarkus." + deployer + ".deploy=true")); assertTrue(result.getStdout().contains("--init-script=")); assertTrue(result.getStdout().contains("--image-builder=" + defaultImageBuilder)); + assertFalse(result.getStdout().contains("-Dquarkus." + configGroup + ".deployment-kind")); result = CliDriver.execute(project, "deploy", deployer, "--image-builder=jib", "--dry-run"); assertEquals(CommandLine.ExitCode.OK, result.getExitCode(), "Expected OK return code." + result); @@ -130,5 +134,19 @@ protected void testDeployer(String deployer, String defaultImageBuilder) throws assertTrue(result.getStdout().contains("-Dquarkus." + deployer + ".deploy=true")); assertTrue(result.getStdout().contains("--init-script=")); assertTrue(result.getStdout().contains("--image-builder=jib")); + assertFalse(result.getStdout().contains("-Dquarkus." + configGroup + ".deployment-kind")); + + if ("knative".equals(deployer)) { + return; + } + result = CliDriver.execute(project, "deploy", deployer, "--deployment-kind", "Deployment", + "--dry-run"); + assertEquals(CommandLine.ExitCode.OK, result.getExitCode(), "Expected OK return code." + result); + assertTrue(result.getStdout().contains("deploy")); + assertTrue(result.getStdout().contains("--no-daemon")); + assertTrue(result.getStdout().contains("--no-build-cache")); + assertTrue(result.getStdout().contains("-Dquarkus." + deployer + ".deploy=true")); + assertTrue(result.getStdout().contains("--init-script=")); + assertTrue(result.getStdout().contains("-Dquarkus." + configGroup + ".deployment-kind=Deployment")); } } diff --git a/devtools/cli/src/test/java/io/quarkus/cli/deploy/CliDeployMavenTest.java b/devtools/cli/src/test/java/io/quarkus/cli/deploy/CliDeployMavenTest.java index 0603e63ecf9aa..16822cf820caa 100644 --- a/devtools/cli/src/test/java/io/quarkus/cli/deploy/CliDeployMavenTest.java +++ b/devtools/cli/src/test/java/io/quarkus/cli/deploy/CliDeployMavenTest.java @@ -1,6 +1,7 @@ package io.quarkus.cli.image; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import java.nio.file.Path; @@ -48,19 +49,20 @@ public void testUsage() throws Exception { result = CliDriver.execute(project, "deploy", "--dry-run"); assertEquals(CommandLine.ExitCode.OK, result.getExitCode(), "Expected OK return code." + result); - testDeployer("kubernetes", "docker"); - testDeployer("knative", "docker"); - testDeployer("minikube", "docker"); - testDeployer("kind", "docker"); - testDeployer("openshift", "openshift"); + testDeployer("kubernetes", "kubernetes", "docker"); + testDeployer("minikube", "kubernetes", "docker"); + testDeployer("kind", "kubernetes", "docker"); + testDeployer("openshift", "openshift", "openshift"); + testDeployer("knative", "knative", "docker"); } - protected void testDeployer(String deployer, String defaultImageBuilder) throws Exception { + protected void testDeployer(String deployer, String configGroup, String defaultImageBuilder) throws Exception { CliDriver.Result result = CliDriver.execute(project, "deploy", deployer, "--dry-run"); assertEquals(CommandLine.ExitCode.OK, result.getExitCode(), "Expected OK return code." + result); assertTrue(result.getStdout().contains("quarkus:deploy")); assertTrue(result.getStdout().contains("-Dquarkus." + deployer + ".deploy=true")); assertTrue(result.getStdout().contains("-Dquarkus.container-image.build=false")); + assertFalse(result.getStdout().contains("-Dquarkus." + configGroup + ".deployment-kind")); result = CliDriver.execute(project, "deploy", deployer, "--image-build", "--dry-run"); assertEquals(CommandLine.ExitCode.OK, result.getExitCode(), "Expected OK return code." + result); @@ -68,6 +70,7 @@ protected void testDeployer(String deployer, String defaultImageBuilder) throws assertTrue(result.getStdout().contains("-Dquarkus." + deployer + ".deploy=true")); assertTrue(result.getStdout().contains("-Dquarkus.container-image.builder=" + defaultImageBuilder)); assertTrue(result.getStdout().contains("-Dquarkus.container-image.build=true")); + assertFalse(result.getStdout().contains("-Dquarkus." + configGroup + ".deployment-kind")); result = CliDriver.execute(project, "deploy", deployer, "--image-builder=jib", "--dry-run"); assertEquals(CommandLine.ExitCode.OK, result.getExitCode(), "Expected OK return code." + result); @@ -75,5 +78,16 @@ protected void testDeployer(String deployer, String defaultImageBuilder) throws assertTrue(result.getStdout().contains("-Dquarkus." + deployer + ".deploy=true")); assertTrue(result.getStdout().contains("-Dquarkus.container-image.builder=jib")); assertTrue(result.getStdout().contains("-Dquarkus.container-image.build=true")); + assertFalse(result.getStdout().contains("-Dquarkus." + configGroup + ".deployment-kind")); + + if ("knative".equals(deployer)) { + return; + } + result = CliDriver.execute(project, "deploy", deployer, "--deployment-kind", "Deployment", "--dry-run"); + assertEquals(CommandLine.ExitCode.OK, result.getExitCode(), "Expected OK return code." + result); + assertTrue(result.getStdout().contains("quarkus:deploy")); + assertTrue(result.getStdout().contains("-Dquarkus." + deployer + ".deploy=true")); + assertTrue(result.getStdout().contains("-Dquarkus.container-image.build=false")); + assertTrue(result.getStdout().contains("-Dquarkus." + configGroup + ".deployment-kind=Deployment")); } }