diff --git a/docs/src/main/asciidoc/deploying-to-openshift.adoc b/docs/src/main/asciidoc/deploying-to-openshift.adoc index 268d699a4b74a..e09b9d297da6a 100644 --- a/docs/src/main/asciidoc/deploying-to-openshift.adoc +++ b/docs/src/main/asciidoc/deploying-to-openshift.adoc @@ -96,8 +96,19 @@ TIP: If you want to test your application immediately then set the `quarkus.open NOTE: When using `DeploymentConfig` and xref:deploying-to-kubernetes.adoc#service_binding[Service Binding], re-deploying might remove the configuration added by OpenShift to allow service discovery. A new container image build will trigger a refresh of the Quarkus app in OpenShift: `-Dquarkus.container-image.build=true` which might be enough in most situations. If you need to update the OpenShift resources, you need to delete the binding first to create it again after new deployment. This command will build your application locally, then trigger a container image build and finally apply the generated OpenShift resources automatically. -The generated resources use OpenShift's `DeploymentConfig` that is configured to automatically trigger a redeployment when a change in the `ImageStream` is noticed. -In other words, any container image build after the initial deployment will automatically trigger redeployment, without the need to delete, update or re-apply the generated resources. +The generated resources use a Kubernetes `Deployment`, but still make use of OpenShift specific resources like `Route`, `BuildConfig` etc. + +IMPORTANT: As of OpenShift 4.14, the https://access.redhat.com/articles/7041372[`DeploymentConfig` object has been deprecated]. + +Since `Deployment` is a Kubernetes resource and not OpenShift specific, it can't possibly leverage `ImageStream` resources, as is the case with `DeploymentConfig`. This means that the image references need to include the container image registry that hosts the image. +When the image is built, using OpenShift builds (s2i binary and docker strategy) the OpenShift internal image registry `image-registry.openshift-image-registry.svc:5000` will be used, unless another registry has been explicitly specified by the user. Please note, that in the internal registry the project/namespace name is added as part of the image repository: `image-registry.openshift-image-registry.svc:5000//:`, so users will need to make sure that the target project/namespace name is aligned with the `quarkus.container-image.group`. + +The https://access.redhat.com/articles/7041372[deprecation document] contains additional information about how to set up/use automatic rollbacks, triggers, lifecycle hooks, and custom strategies. + +[source,properties] +---- +quarkus.container-image.group= +---- You can use the OpenShift web console to verify that the above command has created an image stream, a service resource and has deployed the application. Alternatively, you can run the following OpenShift CLI commands: @@ -384,30 +395,13 @@ quarkus.openshift.env.fields.foo=metadata.name ==== Changing the generated deployment resource -Beside generating a `DeploymentConfig` resource, you can also choose to get either a `Deployment`, `StatefulSet`, or a `Job`, or a `CronJob` resource instead via `application.properties`: +Beside generating a `Deployment` resource, you can also choose to get either a `DeploymentConfig`, `StatefulSet`, `Job`, or a `CronJob` resource instead via `application.properties`: [source,properties] ---- quarkus.openshift.deployment-kind=StatefulSet ---- -===== Using Deployment instead of DeploymentConfig -Out of the box the extension will generate a `DeploymentConfig` resource. Often users, prefer to use `Deployment` as the main deployment resource, but still make use of OpenShift specific resources like `Route`, `BuildConfig` etc. -This feature is enabled by setting `quarkus.openshift.deployment-kind` to `Deployment`. - -[source,properties] ----- -quarkus.openshift.deployment-kind=Deployment ----- - -Since `Deployment` is a Kubernetes resource and not OpenShift specific, it can't possibly leverage `ImageStream` resources, as is the case with `DeploymentConfig`. This means that the image references need to include the container image registry that hosts the image. -When the image is built, using OpenShift builds (s2i binary and docker strategy) the OpenShift internal image registry `image-registry.openshift-image-registry.svc:5000` will be used, unless another registry has been explicitly specified by the user. Please note, that in the internal registry the project/namespace name is added as part of the image repository: `image-registry.openshift-image-registry.svc:5000//:`, so users will need to make sure that the target project/namespace name is aligned with the `quarkus.container-image.group`. - -[source,properties] ----- -quarkus.container-image.group= ----- - ===== Generating Job resources If you want to generate a Job resource, you need to add the following property via the `application.properties`: diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/OpenshiftConfig.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/OpenshiftConfig.java index a4ed700237fcf..dd7a9a2cf01e2 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/OpenshiftConfig.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/OpenshiftConfig.java @@ -41,6 +41,7 @@ public static enum OpenshiftFlavor { public static enum DeploymentResourceKind { Deployment(DEPLOYMENT, DEPLOYMENT_GROUP, DEPLOYMENT_VERSION), + @Deprecated(since = "OpenShift 4.14", forRemoval = true) DeploymentConfig(DEPLOYMENT_CONFIG, DEPLOYMENT_CONFIG_GROUP, DEPLOYMENT_CONFIG_VERSION), StatefulSet(STATEFULSET, DEPLOYMENT_GROUP, DEPLOYMENT_VERSION), Job(JOB, BATCH_GROUP, BATCH_VERSION), @@ -67,7 +68,9 @@ public static enum DeploymentResourceKind { /** * The kind of the deployment resource to use. - * Supported values are 'Deployment', 'StatefulSet', 'Job', 'CronJob' and 'DeploymentConfig' defaulting to the latter. + * Supported values are 'Deployment', 'StatefulSet', 'Job', 'CronJob' and 'DeploymentConfig'. Defaults to 'DeploymentConfig' + * if {@code flavor == v3}, or 'Deployment' otherwise. + * DeploymentConfig is deprecated as of OpenShift 4.14. See https://access.redhat.com/articles/7041372 for details. */ @ConfigItem Optional deploymentKind; @@ -654,6 +657,8 @@ public DeploymentResourceKind getDeploymentResourceKind(Capabilities capabilitie return DeploymentResourceKind.Job; } - return DeploymentResourceKind.DeploymentConfig; + return (flavor == OpenshiftFlavor.v3) ? + DeploymentResourceKind.DeploymentConfig : + DeploymentResourceKind.Deployment; } } diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy-deploymentconfig/invoker.properties b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy-deploymentconfig/invoker.properties new file mode 100644 index 0000000000000..ebd015390fe20 --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy-deploymentconfig/invoker.properties @@ -0,0 +1,5 @@ +# invoker.goals=clean package -Dquarkus.container.build=true -Dquarkus.package.type=native +# ensure that an attempt to deploy is made, but that the attempt fails (as we don't want to deploy this test application to a cluster that the runner of test may have configured) +invoker.goals=clean package -Dquarkus.kubernetes.deploy=true ${kubernetes-client-api-server-url} +# expect a failure since there is no Kubernetes cluster to deploy to +invoker.buildResult = ${build-result} diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy-deploymentconfig/pom.xml b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy-deploymentconfig/pom.xml new file mode 100644 index 0000000000000..d59a6faae8545 --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy-deploymentconfig/pom.xml @@ -0,0 +1,119 @@ + + + 4.0.0 + org.acme + openshift-docker-build-and-deploy-deploymentconfig + 0.1-SNAPSHOT + + UTF-8 + 3.1.2 + 11 + UTF-8 + 11 + + + + + io.quarkus + quarkus-bom + @project.version@ + pom + import + + + + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-openshift + + + io.quarkus + quarkus-container-image-docker + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + + io.quarkus + quarkus-maven-plugin + @project.version@ + + + + build + + + + + + maven-surefire-plugin + ${surefire-plugin.version} + + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + native + + + native + + + + native + + + + + org.apache.maven.plugins + maven-surefire-plugin + + ${native.surefire.skip} + + + + maven-failsafe-plugin + ${surefire-plugin.version} + + + + integration-test + verify + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + + + diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy-deploymentconfig/src/main/docker/Dockerfile.jvm b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy-deploymentconfig/src/main/docker/Dockerfile.jvm new file mode 100644 index 0000000000000..53ed09abd23c2 --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy-deploymentconfig/src/main/docker/Dockerfile.jvm @@ -0,0 +1,54 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/rest-client-quickstart-jvm . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/rest-client-quickstart-jvm +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005) like this : EXPOSE 8080 5050 +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 -p 5005:5005 -e JAVA_ENABLE_DEBUG="true" quarkus/rest-client-quickstart-jvm +# +### +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.8 + +ARG JAVA_PACKAGE=java-11-openjdk-headless +ARG RUN_JAVA_VERSION=1.3.8 +ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' +# Install java and the run-java script +# Also set up permissions for user `1001` +RUN microdnf install curl ca-certificates ${JAVA_PACKAGE} \ + && microdnf update \ + && microdnf clean all \ + && mkdir /deployments \ + && chown 1001 /deployments \ + && chmod "g+rwX" /deployments \ + && chown 1001:root /deployments \ + && curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \ + && chown 1001 /deployments/run-java.sh \ + && chmod 540 /deployments/run-java.sh \ + && echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security + +# Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size. +ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +# We make four distinct layers so if there are application changes the library layers can be re-used +COPY --chown=1001 target/quarkus-app/lib/ /deployments/lib/ +COPY --chown=1001 target/quarkus-app/*.jar /deployments/ +COPY --chown=1001 target/quarkus-app/app/ /deployments/app/ +COPY --chown=1001 target/quarkus-app/quarkus/ /deployments/quarkus/ + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT [ "/deployments/run-java.sh" ] diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy-deploymentconfig/src/main/java/org/acme/Hello.java b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy-deploymentconfig/src/main/java/org/acme/Hello.java new file mode 100644 index 0000000000000..95b11f63bda44 --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy-deploymentconfig/src/main/java/org/acme/Hello.java @@ -0,0 +1,16 @@ +package org.acme; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("/hello") +public class Hello { + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return "hello"; + } +} diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy-deploymentconfig/src/main/resources/application.properties b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy-deploymentconfig/src/main/resources/application.properties new file mode 100644 index 0000000000000..f46ffa5ad2a6e --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy-deploymentconfig/src/main/resources/application.properties @@ -0,0 +1,11 @@ +# Configuration file +# key = value + +quarkus.kubernetes.deployment-target=openshift +quarkus.kubernetes-client.trust-certs=true +quarkus.container-image.builder=docker +quarkus.container-image.group=test +quarkus.openshift.deployment-kind=deployment-config +# To try it locally (outside of Openshift) just provide registry details +#quarkus.container-image.registry=docker.io +#quarkus.container-image.group=<> \ No newline at end of file diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy-deploymentconfig/verify.groovy b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy-deploymentconfig/verify.groovy new file mode 100644 index 0000000000000..b9488fa75e4de --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy-deploymentconfig/verify.groovy @@ -0,0 +1,17 @@ +import io.dekorate.utils.Serialization +import io.fabric8.kubernetes.api.model.KubernetesList +import io.fabric8.kubernetes.api.model.apps.Deployment; +import io.fabric8.openshift.api.model.* + +//Check that file exits +String base = basedir +File openshiftYml = new File(base, "target/kubernetes/openshift.yml") +assert openshiftYml.exists() +openshiftYml.withInputStream { stream -> + //Check that its parse-able + KubernetesList list = Serialization.unmarshalAsList(stream) + assert list != null + + ImageStream imageStream = list.items.find{r -> r.kind == "ImageStream"} + assert imageStream != null +} diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/verify.groovy b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/verify.groovy index b9488fa75e4de..1d5b895266384 100644 --- a/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/verify.groovy +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/verify.groovy @@ -13,5 +13,5 @@ openshiftYml.withInputStream { stream -> assert list != null ImageStream imageStream = list.items.find{r -> r.kind == "ImageStream"} - assert imageStream != null + assert imageStream == null } diff --git a/integration-tests/kubernetes/quarkus-standard-way-kafka/src/test/java/io/quarkus/it/kubernetes/kafka/BasicOpenshiftDeploymentConfigTest.java b/integration-tests/kubernetes/quarkus-standard-way-kafka/src/test/java/io/quarkus/it/kubernetes/kafka/BasicOpenshiftDeploymentConfigTest.java new file mode 100644 index 0000000000000..90a3b4f1560fc --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way-kafka/src/test/java/io/quarkus/it/kubernetes/kafka/BasicOpenshiftDeploymentConfigTest.java @@ -0,0 +1,65 @@ +package io.quarkus.it.kubernetes.kafka; + +import static org.assertj.core.api.Assertions.*; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; + +import org.assertj.core.api.AbstractObjectAssert; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.PodTemplateSpec; +import io.quarkus.test.ProdBuildResults; +import io.quarkus.test.ProdModeTestResults; +import io.quarkus.test.QuarkusProdModeTest; + +public class BasicOpenshiftDeploymentConfigTest { + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar.addClasses(DummyProcessor.class)) + .setApplicationName("basic-openshift") + .setApplicationVersion("0.1-SNAPSHOT") + .withConfigurationResource("basic-openshift.properties") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config"); + + @ProdBuildResults + private ProdModeTestResults prodModeTestResults; + + @SuppressWarnings("unchecked") + @Test + public void assertGeneratedResources() throws IOException { + Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); + assertThat(kubernetesDir) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json")) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml")) + .satisfies(p -> assertThat(p.toFile().listFiles()).hasSize(2)); + List openshiftList = DeserializationUtil + .deserializeAsList(kubernetesDir.resolve("openshift.yml")); + + assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(h.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo("basic-openshift"); + assertThat(m.getLabels().get("app.openshift.io/runtime")).isEqualTo("quarkus"); + assertThat(m.getNamespace()).isNull(); + }); + AbstractObjectAssert specAssert = assertThat(h).extracting("spec"); + specAssert.extracting("replicas").isEqualTo(1); + specAssert.extracting("selector").isInstanceOfSatisfying(Map.class, selectorsMap -> { + assertThat(selectorsMap).containsOnly(entry("app.kubernetes.io/name", "basic-openshift"), + entry("app.kubernetes.io/version", "0.1-SNAPSHOT")); + }); + specAssert.extracting("template").isInstanceOfSatisfying(PodTemplateSpec.class, templateMap -> { + assertThat(templateMap.getSpec()).satisfies(podSpec -> { + assertThat(podSpec.getContainers()).singleElement().satisfies(container -> { + assertThat(container.getPorts()).isNullOrEmpty(); + }); + }); + }); + }); + } +} diff --git a/integration-tests/kubernetes/quarkus-standard-way-kafka/src/test/java/io/quarkus/it/kubernetes/kafka/BasicOpenshiftTest.java b/integration-tests/kubernetes/quarkus-standard-way-kafka/src/test/java/io/quarkus/it/kubernetes/kafka/BasicOpenshiftTest.java index 02fcbec067927..0accdcbf73b6e 100644 --- a/integration-tests/kubernetes/quarkus-standard-way-kafka/src/test/java/io/quarkus/it/kubernetes/kafka/BasicOpenshiftTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way-kafka/src/test/java/io/quarkus/it/kubernetes/kafka/BasicOpenshiftTest.java @@ -41,7 +41,7 @@ public void assertGeneratedResources() throws IOException { List openshiftList = DeserializationUtil .deserializeAsList(kubernetesDir.resolve("openshift.yml")); - assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(openshiftList).filteredOn(h -> "Deployment".equals(h.getKind())).singleElement().satisfies(h -> { assertThat(h.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo("basic-openshift"); assertThat(m.getLabels().get("app.openshift.io/runtime")).isEqualTo("quarkus"); @@ -49,7 +49,7 @@ public void assertGeneratedResources() throws IOException { }); AbstractObjectAssert specAssert = assertThat(h).extracting("spec"); specAssert.extracting("replicas").isEqualTo(1); - specAssert.extracting("selector").isInstanceOfSatisfying(Map.class, selectorsMap -> { + specAssert.extracting("selector.matchLabels").isInstanceOfSatisfying(Map.class, selectorsMap -> { assertThat(selectorsMap).containsOnly(entry("app.kubernetes.io/name", "basic-openshift"), entry("app.kubernetes.io/version", "0.1-SNAPSHOT")); }); diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/BasicOpenshiftDeploymentConfigTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/BasicOpenshiftDeploymentConfigTest.java new file mode 100644 index 0000000000000..527a41cc84eca --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/BasicOpenshiftDeploymentConfigTest.java @@ -0,0 +1,75 @@ +package io.quarkus.it.kubernetes; + +import static org.assertj.core.api.Assertions.*; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.Service; +import io.fabric8.openshift.api.model.DeploymentConfig; +import io.quarkus.test.ProdBuildResults; +import io.quarkus.test.ProdModeTestResults; +import io.quarkus.test.QuarkusProdModeTest; + +public class BasicOpenshiftDeploymentConfigTest { + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) + .setApplicationName("basic-openshift") + .setApplicationVersion("0.1-SNAPSHOT") + .withConfigurationResource("openshift.properties") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config"); + + @ProdBuildResults + private ProdModeTestResults prodModeTestResults; + + @Test + public void assertGeneratedResources() throws IOException { + Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); + assertThat(kubernetesDir) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json")) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml")) + .satisfies(p -> assertThat(p.toFile().listFiles()).hasSize(2)); + List openshiftList = DeserializationUtil + .deserializeAsList(kubernetesDir.resolve("openshift.yml")); + + assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + DeploymentConfig deployment = (DeploymentConfig) h; + + // metadata assertions + assertThat(deployment.getMetadata().getName()).isEqualTo("basic-openshift"); + assertThat(deployment.getMetadata().getLabels().get("app.openshift.io/runtime")).isEqualTo("quarkus"); + assertThat(deployment.getMetadata().getLabels().get("app.kubernetes.io/managed-by")).isEqualTo("quarkus"); + assertThat(deployment.getMetadata().getNamespace()).isNull(); + + // spec assertions + assertThat(deployment.getSpec().getReplicas()).isEqualTo(1); + assertThat(deployment.getSpec().getSelector()).containsOnly(entry("app.kubernetes.io/name", "basic-openshift"), + entry("app.kubernetes.io/version", "0.1-SNAPSHOT")); + + // containers assertions + assertThat(deployment.getSpec().getTemplate().getSpec().getContainers()).satisfiesExactly(container -> { + assertThat(container.getImagePullPolicy()).isEqualTo("Always"); // expect the default value + }); + }); + + assertThat(openshiftList).filteredOn(h -> "Service".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(h).isInstanceOfSatisfying(Service.class, s -> { + assertThat(s.getMetadata()).satisfies(m -> { + assertThat(m.getNamespace()).isNull(); + }); + + assertThat(s.getSpec()).satisfies(spec -> { + assertThat(spec.getSelector()).containsOnly(entry("app.kubernetes.io/name", "basic-openshift"), + entry("app.kubernetes.io/version", "0.1-SNAPSHOT")); + }); + }); + }); + } +} diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/BasicOpenshiftTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/BasicOpenshiftTest.java index 9b50ac085e001..0a099422dbb86 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/BasicOpenshiftTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/BasicOpenshiftTest.java @@ -12,7 +12,7 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.Service; -import io.fabric8.openshift.api.model.DeploymentConfig; +import io.fabric8.kubernetes.api.model.apps.Deployment; import io.quarkus.test.ProdBuildResults; import io.quarkus.test.ProdModeTestResults; import io.quarkus.test.QuarkusProdModeTest; @@ -39,8 +39,8 @@ public void assertGeneratedResources() throws IOException { List openshiftList = DeserializationUtil .deserializeAsList(kubernetesDir.resolve("openshift.yml")); - assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { - DeploymentConfig deployment = (DeploymentConfig) h; + assertThat(openshiftList).filteredOn(h -> "Deployment".equals(h.getKind())).singleElement().satisfies(h -> { + Deployment deployment = (Deployment) h; // metadata assertions assertThat(deployment.getMetadata().getName()).isEqualTo("basic-openshift"); @@ -50,7 +50,8 @@ public void assertGeneratedResources() throws IOException { // spec assertions assertThat(deployment.getSpec().getReplicas()).isEqualTo(1); - assertThat(deployment.getSpec().getSelector()).containsOnly(entry("app.kubernetes.io/name", "basic-openshift"), + assertThat(deployment.getSpec().getSelector().getMatchLabels()).containsOnly( + entry("app.kubernetes.io/name", "basic-openshift"), entry("app.kubernetes.io/version", "0.1-SNAPSHOT")); // containers assertions diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithSpecifiedContainerNameTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithSpecifiedContainerNameTest.java index 1008f62907f6d..9da21c41bbf4c 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithSpecifiedContainerNameTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithSpecifiedContainerNameTest.java @@ -29,6 +29,7 @@ public class KubernetesWithSpecifiedContainerNameTest { .setApplicationName("kubernetes-with-specified-container-name") .setApplicationVersion("0.1-SNAPSHOT") .withConfigurationResource("kubernetes-with-specified-container-name.properties") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config") .setForcedDependencies(List.of( Dependency.of("io.quarkus", "quarkus-kubernetes", Version.getVersion()), Dependency.of("io.quarkus", "quarkus-container-image-s2i", Version.getVersion()))); diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftV4DeploymentConfigTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftV4DeploymentConfigTest.java new file mode 100644 index 0000000000000..ab75d935d80d2 --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftV4DeploymentConfigTest.java @@ -0,0 +1,74 @@ +package io.quarkus.it.kubernetes; + +import static org.assertj.core.api.Assertions.*; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; + +import org.assertj.core.api.AbstractObjectAssert; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.Service; +import io.quarkus.test.ProdBuildResults; +import io.quarkus.test.ProdModeTestResults; +import io.quarkus.test.QuarkusProdModeTest; + +public class OpenshiftV4DeploymentConfigTest { + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) + .setApplicationName("openshift-v4-deploymentconfig") + .setApplicationVersion("0.1-SNAPSHOT") + .withConfigurationResource("openshift-v4.properties") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config"); + + @ProdBuildResults + private ProdModeTestResults prodModeTestResults; + + @Test + public void assertGeneratedResources() throws IOException { + Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); + assertThat(kubernetesDir) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json")) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml")) + .satisfies(p -> assertThat(p.toFile().listFiles()).hasSize(2)); + List openshiftList = DeserializationUtil + .deserializeAsList(kubernetesDir.resolve("openshift.yml")); + + assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(h.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo("openshift-v4-deploymentconfig"); + assertThat(m.getLabels().get("app.openshift.io/runtime")).isEqualTo("test"); + assertThat(m.getLabels().get("app.kubernetes.io/name")).isEqualTo("openshift-v4-deploymentconfig"); + assertThat(m.getLabels().get("app")).isNull(); + assertThat(m.getNamespace()).isNull(); + }); + AbstractObjectAssert specAssert = assertThat(h).extracting("spec"); + specAssert.extracting("selector").isInstanceOfSatisfying(Map.class, selectorsMap -> { + assertThat(selectorsMap).containsOnly(entry("app.kubernetes.io/name", "openshift-v4-deploymentconfig"), + entry("app.kubernetes.io/version", "0.1-SNAPSHOT")); + }); + }); + + assertThat(openshiftList).filteredOn(h -> "Service".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(h).isInstanceOfSatisfying(Service.class, s -> { + assertThat(s.getMetadata()).satisfies(m -> { + assertThat(m.getNamespace()).isNull(); + assertThat(m.getLabels().get("app.kubernetes.io/name")).isEqualTo("openshift-v4-deploymentconfig"); + assertThat(m.getLabels().get("app")).isNull(); + }); + + assertThat(s.getSpec()).satisfies(spec -> { + assertThat(spec.getSelector()).containsOnly( + entry("app.kubernetes.io/name", "openshift-v4-deploymentconfig"), + entry("app.kubernetes.io/version", "0.1-SNAPSHOT")); + }); + }); + }); + } +} diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftV4Test.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftV4Test.java index 28e4c4f5c48ae..d7370c8afa58c 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftV4Test.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftV4Test.java @@ -40,7 +40,7 @@ public void assertGeneratedResources() throws IOException { List openshiftList = DeserializationUtil .deserializeAsList(kubernetesDir.resolve("openshift.yml")); - assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(openshiftList).filteredOn(h -> "Deployment".equals(h.getKind())).singleElement().satisfies(h -> { assertThat(h.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo("openshift-v4"); assertThat(m.getLabels().get("app.openshift.io/runtime")).isEqualTo("test"); @@ -49,7 +49,7 @@ public void assertGeneratedResources() throws IOException { assertThat(m.getNamespace()).isNull(); }); AbstractObjectAssert specAssert = assertThat(h).extracting("spec"); - specAssert.extracting("selector").isInstanceOfSatisfying(Map.class, selectorsMap -> { + specAssert.extracting("selector.matchLabels").isInstanceOfSatisfying(Map.class, selectorsMap -> { assertThat(selectorsMap).containsOnly(entry("app.kubernetes.io/name", "openshift-v4"), entry("app.kubernetes.io/version", "0.1-SNAPSHOT")); }); diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithAppConfigMapTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithAppConfigMapTest.java index 70206ded24570..26148ba9c2900 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithAppConfigMapTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithAppConfigMapTest.java @@ -44,7 +44,7 @@ public void assertGeneratedResources() throws IOException { List openshiftList = DeserializationUtil.deserializeAsList( kubernetesDir.resolve("openshift.yml")); - assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(openshiftList).filteredOn(h -> "Deployment".equals(h.getKind())).singleElement().satisfies(h -> { assertThat(h.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo("openshift-with-app-config-map"); assertThat(m.getLabels().get("app.openshift.io/runtime")).isEqualTo("quarkus"); diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithAppSecretTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithAppSecretTest.java index 8fdf8df986221..3f75fd9172a92 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithAppSecretTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithAppSecretTest.java @@ -29,6 +29,7 @@ public class OpenshiftWithAppSecretTest { .setApplicationName("openshift-with-app-secret") .setApplicationVersion("0.1-SNAPSHOT") .withConfigurationResource("openshift-with-app-secret.properties") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config") .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-openshift", Version.getVersion()))); @ProdBuildResults diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithApplicationPropertiesTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithApplicationPropertiesTest.java index 8591c5a1c83b2..b13e8f0cfc3c3 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithApplicationPropertiesTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithApplicationPropertiesTest.java @@ -28,7 +28,8 @@ public class OpenshiftWithApplicationPropertiesTest { .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) .setApplicationName("openshift") .setApplicationVersion("0.1-SNAPSHOT") - .withConfigurationResource("openshift-with-application.properties"); + .withConfigurationResource("openshift-with-application.properties") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config"); @ProdBuildResults private ProdModeTestResults prodModeTestResults; diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithArgumentsTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithArgumentsTest.java index 2f3e776b4b026..d1f67992ef8c0 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithArgumentsTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithArgumentsTest.java @@ -10,7 +10,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.openshift.api.model.DeploymentConfig; +import io.fabric8.kubernetes.api.model.apps.Deployment; import io.quarkus.test.ProdBuildResults; import io.quarkus.test.ProdModeTestResults; import io.quarkus.test.QuarkusProdModeTest; @@ -33,7 +33,7 @@ public void assertGeneratedResources() throws IOException { List openshiftList = DeserializationUtil .deserializeAsList(kubernetesDir.resolve("openshift.yml")); - assertThat(openshiftList.get(0)).isInstanceOfSatisfying(DeploymentConfig.class, dc -> { + assertThat(openshiftList.get(0)).isInstanceOfSatisfying(Deployment.class, dc -> { assertThat(dc.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo("openshift-with-arguments"); }); diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithBaseImageFromInternalRegistryDeploymentConfigTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithBaseImageFromInternalRegistryDeploymentConfigTest.java new file mode 100644 index 0000000000000..ff0dc62515fd9 --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithBaseImageFromInternalRegistryDeploymentConfigTest.java @@ -0,0 +1,89 @@ +package io.quarkus.it.kubernetes; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.Container; +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.openshift.api.model.BuildConfig; +import io.fabric8.openshift.api.model.DeploymentConfig; +import io.fabric8.openshift.api.model.DeploymentTriggerImageChangeParams; +import io.fabric8.openshift.api.model.ImageStream; +import io.quarkus.builder.Version; +import io.quarkus.maven.dependency.Dependency; +import io.quarkus.test.ProdBuildResults; +import io.quarkus.test.ProdModeTestResults; +import io.quarkus.test.QuarkusProdModeTest; + +public class OpenshiftWithBaseImageFromInternalRegistryDeploymentConfigTest { + + private static final String APP_NAME = "openshift-with-base-image-stream"; + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) + .setApplicationName(APP_NAME) + .setApplicationVersion("0.1-SNAPSHOT") + .overrideConfigKey("quarkus.openshift.base-jvm-image", + "image-registry.openshift-image-registry.svc:5000/myns/myimage:1.0") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config") + .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-openshift", Version.getVersion()))); + + @ProdBuildResults + private ProdModeTestResults prodModeTestResults; + + @Test + public void assertGeneratedResources() throws IOException { + Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); + + assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json")) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml")); + List openshiftList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("openshift.yml")); + + assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(h.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo(APP_NAME); + }); + assertThat(h).isInstanceOfSatisfying(DeploymentConfig.class, d -> { + Container container = d.getSpec().getTemplate().getSpec().getContainers().get(0); + assertThat(container.getImage()).endsWith(APP_NAME + ":0.1-SNAPSHOT"); + + DeploymentTriggerImageChangeParams imageTriggerParams = d.getSpec().getTriggers().get(0).getImageChangeParams(); + assertThat(imageTriggerParams.getFrom().getKind()).isEqualTo("ImageStreamTag"); + assertThat(imageTriggerParams.getFrom().getName()).isEqualTo(APP_NAME + ":0.1-SNAPSHOT"); + }); + }); + + assertThat(openshiftList).filteredOn(h -> "BuildConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(h.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo(APP_NAME); + }); + assertThat(h).isInstanceOfSatisfying(BuildConfig.class, b -> { + assertThat(b.getSpec().getStrategy().getSourceStrategy().getFrom()).satisfies(f -> { + assertThat(f.getKind()).isEqualTo("ImageStreamTag"); + assertThat(f.getNamespace()).isEqualTo("myns"); + assertThat(f.getName()).isEqualTo("myimage:1.0"); + }); + }); + }); + + //Verify that we only got one Image + assertThat(openshiftList).filteredOn(h -> "ImageStream".equals(h.getKind())).singleElement() + .satisfies(h -> { + assertThat(h.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo(APP_NAME); + }); + + assertThat(h).isInstanceOfSatisfying(ImageStream.class, i -> { + assertThat(i.getSpec().getDockerImageRepository()).isNull(); + }); + }); + + } +} diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithBaseImageFromInternalRegistryTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithBaseImageFromInternalRegistryTest.java index 003e1404cbdf7..a2d9fe8b632c2 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithBaseImageFromInternalRegistryTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithBaseImageFromInternalRegistryTest.java @@ -11,9 +11,8 @@ import io.fabric8.kubernetes.api.model.Container; import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.openshift.api.model.BuildConfig; -import io.fabric8.openshift.api.model.DeploymentConfig; -import io.fabric8.openshift.api.model.DeploymentTriggerImageChangeParams; import io.fabric8.openshift.api.model.ImageStream; import io.quarkus.builder.Version; import io.quarkus.maven.dependency.Dependency; @@ -45,17 +44,13 @@ public void assertGeneratedResources() throws IOException { .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml")); List openshiftList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("openshift.yml")); - assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(openshiftList).filteredOn(h -> "Deployment".equals(h.getKind())).singleElement().satisfies(h -> { assertThat(h.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo(APP_NAME); }); - assertThat(h).isInstanceOfSatisfying(DeploymentConfig.class, d -> { + assertThat(h).isInstanceOfSatisfying(Deployment.class, d -> { Container container = d.getSpec().getTemplate().getSpec().getContainers().get(0); assertThat(container.getImage()).endsWith(APP_NAME + ":0.1-SNAPSHOT"); - - DeploymentTriggerImageChangeParams imageTriggerParams = d.getSpec().getTriggers().get(0).getImageChangeParams(); - assertThat(imageTriggerParams.getFrom().getKind()).isEqualTo("ImageStreamTag"); - assertThat(imageTriggerParams.getFrom().getName()).isEqualTo(APP_NAME + ":0.1-SNAPSHOT"); }); }); @@ -83,6 +78,5 @@ public void assertGeneratedResources() throws IOException { assertThat(i.getSpec().getDockerImageRepository()).isNull(); }); }); - } } diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithCommandTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithCommandTest.java index b7d95163844d1..ad54f1815c701 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithCommandTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithCommandTest.java @@ -10,7 +10,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.openshift.api.model.DeploymentConfig; +import io.fabric8.kubernetes.api.model.apps.Deployment; import io.quarkus.test.ProdBuildResults; import io.quarkus.test.ProdModeTestResults; import io.quarkus.test.QuarkusProdModeTest; @@ -33,7 +33,7 @@ public void assertGeneratedResources() throws IOException { List openshiftList = DeserializationUtil .deserializeAsList(kubernetesDir.resolve("openshift.yml")); - assertThat(openshiftList.get(0)).isInstanceOfSatisfying(DeploymentConfig.class, dc -> { + assertThat(openshiftList.get(0)).isInstanceOfSatisfying(Deployment.class, dc -> { assertThat(dc.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo("openshift-with-command"); }); diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDockerAndImageTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDockerAndImageTest.java index 422b108a16baa..d06976b2073dc 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDockerAndImageTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDockerAndImageTest.java @@ -30,6 +30,7 @@ public class OpenshiftWithDockerAndImageTest { .setApplicationName(APP_NAME) .setApplicationVersion("0.1-SNAPSHOT") .withConfigurationResource(APP_NAME + ".properties") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config") .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-openshift", Version.getVersion()))); @ProdBuildResults diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDockerBuildStrategyTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDockerBuildStrategyTest.java index 0b2f70afd817a..b3731f392c5d8 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDockerBuildStrategyTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDockerBuildStrategyTest.java @@ -25,6 +25,7 @@ public class OpenshiftWithDockerBuildStrategyTest { .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) .setApplicationName("openshift-s2i").setApplicationVersion("0.1-SNAPSHOT") .withConfigurationResource("openshift-with-docker-build-strategy.properties") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config") .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-openshift", Version.getVersion()))); @ProdBuildResults diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithHealthDeploymentConfigTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithHealthDeploymentConfigTest.java new file mode 100644 index 0000000000000..0e3a765480823 --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithHealthDeploymentConfigTest.java @@ -0,0 +1,94 @@ +package io.quarkus.it.kubernetes; + +import static io.restassured.RestAssured.given; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.*; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.PodSpec; +import io.quarkus.builder.Version; +import io.quarkus.maven.dependency.Dependency; +import io.quarkus.test.LogFile; +import io.quarkus.test.ProdBuildResults; +import io.quarkus.test.ProdModeTestResults; +import io.quarkus.test.QuarkusProdModeTest; + +public class OpenshiftWithHealthDeploymentConfigTest { + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) + .setApplicationName("openshift-health") + .setApplicationVersion("0.1-SNAPSHOT") + .setRun(true) + .setLogFileName("k8s.log") + .withConfigurationResource("openshift-with-health.properties") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config") + .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-smallrye-health", Version.getVersion()))); + + @ProdBuildResults + private ProdModeTestResults prodModeTestResults; + + @LogFile + private Path logfile; + + @Test + public void assertApplicationRuns() { + assertThat(logfile).isRegularFile().hasFileName("k8s.log"); + TestUtil.assertLogFileContents(logfile, "kubernetes", "health"); + + given() + .when().get("/greeting") + .then() + .statusCode(200) + .body(is("hello")); + } + + @Test + public void assertGeneratedResources() throws IOException { + Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); + assertThat(kubernetesDir) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json")) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml")); + List openshiftList = DeserializationUtil + .deserializeAsList(kubernetesDir.resolve("openshift.yml")); + + assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(h.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo("openshift-health"); + }); + assertThat(h).extracting("spec").extracting("template").extracting("spec").isInstanceOfSatisfying(PodSpec.class, + podSpec -> { + assertThat(podSpec.getContainers()).singleElement().satisfies(container -> { + assertThat(container.getReadinessProbe()).isNotNull().satisfies(p -> { + assertThat(p.getPeriodSeconds()).isEqualTo(15); + assertThat(p.getHttpGet()).satisfies(h1 -> { + assertThat(h1.getPath()).isEqualTo("/q/health/ready"); + }); + }); + assertThat(container.getLivenessProbe()).isNotNull().satisfies(p -> { + assertThat(p.getPeriodSeconds()).isEqualTo(10); + assertThat(p.getHttpGet()).isNull(); + assertThat(p.getExec()).satisfies(e -> { + assertThat(e.getCommand()).containsOnly("kill"); + }); + }); + assertThat(container.getStartupProbe()).isNotNull().satisfies(p -> { + assertThat(p.getInitialDelaySeconds()).isEqualTo(5); + assertNotNull(p.getHttpGet()); + assertEquals(p.getHttpGet().getPath(), "/q/health/started"); + }); + }); + }); + }); + } + +} diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithHealthTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithHealthTest.java index 081128984d4c5..93265c8f13c71 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithHealthTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithHealthTest.java @@ -61,7 +61,7 @@ public void assertGeneratedResources() throws IOException { List openshiftList = DeserializationUtil .deserializeAsList(kubernetesDir.resolve("openshift.yml")); - assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(openshiftList).filteredOn(h -> "Deployment".equals(h.getKind())).singleElement().satisfies(h -> { assertThat(h.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo("openshift-health"); }); diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithHealthUsingManagementInterfaceDeploymentConfigTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithHealthUsingManagementInterfaceDeploymentConfigTest.java new file mode 100644 index 0000000000000..96077c2a423bf --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithHealthUsingManagementInterfaceDeploymentConfigTest.java @@ -0,0 +1,90 @@ +package io.quarkus.it.kubernetes; + +import static io.restassured.RestAssured.given; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.is; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.IntOrString; +import io.fabric8.kubernetes.api.model.PodSpec; +import io.quarkus.builder.Version; +import io.quarkus.maven.dependency.Dependency; +import io.quarkus.test.LogFile; +import io.quarkus.test.ProdBuildResults; +import io.quarkus.test.ProdModeTestResults; +import io.quarkus.test.QuarkusProdModeTest; + +public class OpenshiftWithHealthUsingManagementInterfaceDeploymentConfigTest { + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) + .setApplicationName("openshift-health") + .setApplicationVersion("0.1-SNAPSHOT") + .setRun(true) + .setLogFileName("k8s.log") + .withConfigurationResource("openshift-with-health-and-management.properties") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config") + .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-smallrye-health", Version.getVersion()))); + + @ProdBuildResults + private ProdModeTestResults prodModeTestResults; + + @LogFile + private Path logfile; + + @Test + public void assertApplicationRuns() { + assertThat(logfile).isRegularFile().hasFileName("k8s.log"); + TestUtil.assertLogFileContents(logfile, "kubernetes", "health"); + + given() + .when().get("/greeting") + .then() + .statusCode(200) + .body(is("hello")); + } + + @Test + public void assertGeneratedResources() throws IOException { + Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); + assertThat(kubernetesDir) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json")) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml")); + List openshiftList = DeserializationUtil + .deserializeAsList(kubernetesDir.resolve("openshift.yml")); + + assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(h.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo("openshift-health"); + }); + assertThat(h).extracting("spec").extracting("template").extracting("spec").isInstanceOfSatisfying(PodSpec.class, + podSpec -> { + assertThat(podSpec.getContainers()).singleElement().satisfies(container -> { + assertThat(container.getReadinessProbe()).isNotNull().satisfies(p -> { + assertThat(p.getPeriodSeconds()).isEqualTo(15); + assertThat(p.getHttpGet()).satisfies(h1 -> { + assertThat(h1.getPath()).isEqualTo("/q/health/ready"); + assertThat(h1.getPort()).isEqualTo(new IntOrString(9000)); + }); + }); + assertThat(container.getLivenessProbe()).isNotNull().satisfies(p -> { + assertThat(p.getPeriodSeconds()).isEqualTo(10); + assertThat(p.getHttpGet()).isNull(); + assertThat(p.getExec()).satisfies(e -> { + assertThat(e.getCommand()).containsOnly("kill"); + }); + }); + }); + }); + }); + } + +} diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithHealthUsingManagementInterfaceTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithHealthUsingManagementInterfaceTest.java index f46b3487ef657..9dd34f298984a 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithHealthUsingManagementInterfaceTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithHealthUsingManagementInterfaceTest.java @@ -60,7 +60,7 @@ public void assertGeneratedResources() throws IOException { List openshiftList = DeserializationUtil .deserializeAsList(kubernetesDir.resolve("openshift.yml")); - assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(openshiftList).filteredOn(h -> "Deployment".equals(h.getKind())).singleElement().satisfies(h -> { assertThat(h.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo("openshift-health"); }); diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithImageTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithImageTest.java index a9801c3687225..23258b64db57c 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithImageTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithImageTest.java @@ -30,6 +30,7 @@ public class OpenshiftWithImageTest { .setApplicationName(APP_NAME) .setApplicationVersion("0.1-SNAPSHOT") .overrideConfigKey("quarkus.container-image.image", "user/app:2.0") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config") .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-openshift", Version.getVersion()))); @ProdBuildResults diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithJvmAdditionalArgumentsDeploymentConfigTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithJvmAdditionalArgumentsDeploymentConfigTest.java new file mode 100644 index 0000000000000..89d7243aa67b6 --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithJvmAdditionalArgumentsDeploymentConfigTest.java @@ -0,0 +1,58 @@ +package io.quarkus.it.kubernetes; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.openshift.api.model.DeploymentConfig; +import io.quarkus.builder.Version; +import io.quarkus.maven.dependency.Dependency; +import io.quarkus.test.ProdBuildResults; +import io.quarkus.test.ProdModeTestResults; +import io.quarkus.test.QuarkusProdModeTest; + +public class OpenshiftWithJvmAdditionalArgumentsDeploymentConfigTest { + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) + .setApplicationName("openshift-with-jvm-additional-arguments") + .setApplicationVersion("0.1-SNAPSHOT") + .withConfigurationResource("openshift-with-jvm-additional-arguments.properties") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config") + .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-openshift", Version.getVersion())));; + + @ProdBuildResults + private ProdModeTestResults prodModeTestResults; + + @Test + public void assertGeneratedResources() throws IOException { + Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); + List openshiftList = DeserializationUtil + .deserializeAsList(kubernetesDir.resolve("openshift.yml")); + + assertThat(openshiftList.get(1)).isInstanceOfSatisfying(DeploymentConfig.class, dc -> { + assertThat(dc.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo("openshift-with-jvm-additional-arguments"); + }); + assertThat(dc.getSpec()).satisfies(deploymentSpec -> { + assertThat(deploymentSpec.getTemplate()).satisfies(t -> { + assertThat(t.getSpec()).satisfies(podSpec -> { + assertThat(podSpec.getContainers()).singleElement().satisfies(container -> { + assertThat(container.getCommand()).containsExactly("java", + "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", + "-jar", + "/deployments/quarkus-run.jar"); + }); + }); + }); + }); + }); + } +} diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithJvmAdditionalArgumentsTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithJvmAdditionalArgumentsTest.java index a221bebf23709..4c1d87d1e61d9 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithJvmAdditionalArgumentsTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithJvmAdditionalArgumentsTest.java @@ -10,7 +10,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.openshift.api.model.DeploymentConfig; +import io.fabric8.kubernetes.api.model.apps.Deployment; import io.quarkus.builder.Version; import io.quarkus.maven.dependency.Dependency; import io.quarkus.test.ProdBuildResults; @@ -36,11 +36,11 @@ public void assertGeneratedResources() throws IOException { List openshiftList = DeserializationUtil .deserializeAsList(kubernetesDir.resolve("openshift.yml")); - assertThat(openshiftList.get(1)).isInstanceOfSatisfying(DeploymentConfig.class, dc -> { - assertThat(dc.getMetadata()).satisfies(m -> { + assertThat(openshiftList.get(1)).isInstanceOfSatisfying(Deployment.class, d -> { + assertThat(d.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo("openshift-with-jvm-additional-arguments"); }); - assertThat(dc.getSpec()).satisfies(deploymentSpec -> { + assertThat(d.getSpec()).satisfies(deploymentSpec -> { assertThat(deploymentSpec.getTemplate()).satisfies(t -> { assertThat(t.getSpec()).satisfies(podSpec -> { assertThat(podSpec.getContainers()).singleElement().satisfies(container -> { diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithJvmArgumentsDeploymentConfigTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithJvmArgumentsDeploymentConfigTest.java new file mode 100644 index 0000000000000..bb7c3f12814fe --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithJvmArgumentsDeploymentConfigTest.java @@ -0,0 +1,58 @@ +package io.quarkus.it.kubernetes; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.openshift.api.model.DeploymentConfig; +import io.quarkus.builder.Version; +import io.quarkus.maven.dependency.Dependency; +import io.quarkus.test.ProdBuildResults; +import io.quarkus.test.ProdModeTestResults; +import io.quarkus.test.QuarkusProdModeTest; + +public class OpenshiftWithJvmArgumentsDeploymentConfigTest { + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) + .setApplicationName("openshift-with-jvm-arguments") + .setApplicationVersion("0.1-SNAPSHOT") + .withConfigurationResource("openshift-with-jvm-arguments.properties") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config") + .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-openshift", Version.getVersion())));; + + @ProdBuildResults + private ProdModeTestResults prodModeTestResults; + + @Test + public void assertGeneratedResources() throws IOException { + Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); + List openshiftList = DeserializationUtil + .deserializeAsList(kubernetesDir.resolve("openshift.yml")); + + assertThat(openshiftList.get(1)).isInstanceOfSatisfying(DeploymentConfig.class, dc -> { + assertThat(dc.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo("openshift-with-jvm-arguments"); + }); + assertThat(dc.getSpec()).satisfies(deploymentSpec -> { + assertThat(deploymentSpec.getTemplate()).satisfies(t -> { + assertThat(t.getSpec()).satisfies(podSpec -> { + assertThat(podSpec.getContainers()).singleElement().satisfies(container -> { + assertThat(container.getCommand()).containsExactly("java", + "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", + "-jar", + "/deployments/quarkus-run.jar"); + }); + }); + }); + }); + }); + } +} diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithJvmArgumentsTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithJvmArgumentsTest.java index aebc37505afe5..8e8afcc209542 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithJvmArgumentsTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithJvmArgumentsTest.java @@ -10,7 +10,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.openshift.api.model.DeploymentConfig; +import io.fabric8.kubernetes.api.model.apps.Deployment; import io.quarkus.builder.Version; import io.quarkus.maven.dependency.Dependency; import io.quarkus.test.ProdBuildResults; @@ -36,11 +36,11 @@ public void assertGeneratedResources() throws IOException { List openshiftList = DeserializationUtil .deserializeAsList(kubernetesDir.resolve("openshift.yml")); - assertThat(openshiftList.get(1)).isInstanceOfSatisfying(DeploymentConfig.class, dc -> { - assertThat(dc.getMetadata()).satisfies(m -> { + assertThat(openshiftList.get(1)).isInstanceOfSatisfying(Deployment.class, d -> { + assertThat(d.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo("openshift-with-jvm-arguments"); }); - assertThat(dc.getSpec()).satisfies(deploymentSpec -> { + assertThat(d.getSpec()).satisfies(deploymentSpec -> { assertThat(deploymentSpec.getTemplate()).satisfies(t -> { assertThat(t.getSpec()).satisfies(podSpec -> { assertThat(podSpec.getContainers()).singleElement().satisfies(container -> { diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithKubernetesConfigDeploymentConfigTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithKubernetesConfigDeploymentConfigTest.java new file mode 100644 index 0000000000000..f1dab8ef8a908 --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithKubernetesConfigDeploymentConfigTest.java @@ -0,0 +1,67 @@ +package io.quarkus.it.kubernetes; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; + +import org.assertj.core.api.AbstractObjectAssert; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.EnvVar; +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.PodSpec; +import io.quarkus.builder.Version; +import io.quarkus.maven.dependency.Dependency; +import io.quarkus.test.ProdBuildResults; +import io.quarkus.test.ProdModeTestResults; +import io.quarkus.test.QuarkusProdModeTest; + +public class OpenshiftWithKubernetesConfigDeploymentConfigTest { + + private static final String NAME = "openshift-with-kubernetes-config"; + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) + .setApplicationName(NAME) + .setApplicationVersion("0.1-SNAPSHOT") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config") + .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-openshift", Version.getVersion()), + Dependency.of("io.quarkus", "quarkus-kubernetes-config", Version.getVersion()))); + + @ProdBuildResults + private ProdModeTestResults prodModeTestResults; + + @Test + public void assertGeneratedResources() throws IOException { + Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); + + assertThat(kubernetesDir) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json")) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml")); + List openshiftList = DeserializationUtil.deserializeAsList( + kubernetesDir.resolve("openshift.yml")); + + assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(h.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo(NAME); + assertThat(m.getLabels().get("app.openshift.io/runtime")).isEqualTo("quarkus"); + }); + + AbstractObjectAssert specAssert = assertThat(h).extracting("spec"); + specAssert.extracting("template").extracting("spec").isInstanceOfSatisfying(PodSpec.class, + podSpec -> { + assertThat(podSpec.getContainers()).singleElement().satisfies(container -> { + List envVars = container.getEnv(); + assertThat(envVars).anySatisfy(envVar -> { + assertThat(envVar.getName()).isEqualTo("JAVA_APP_JAR"); + assertThat(envVar.getValue()).isEqualTo("/deployments/quarkus-run.jar"); + }); + }); + }); + }); + } +} diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithKubernetesConfigTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithKubernetesConfigTest.java index 62b997b1feb1a..7cf22c87d32db 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithKubernetesConfigTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithKubernetesConfigTest.java @@ -44,7 +44,7 @@ public void assertGeneratedResources() throws IOException { List openshiftList = DeserializationUtil.deserializeAsList( kubernetesDir.resolve("openshift.yml")); - assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(openshiftList).filteredOn(h -> "Deployment".equals(h.getKind())).singleElement().satisfies(h -> { assertThat(h.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo(NAME); assertThat(m.getLabels().get("app.openshift.io/runtime")).isEqualTo("quarkus"); diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithLegacySidecarAndS2iTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithLegacySidecarAndS2iTest.java index 899d3ae83e0a5..30d8681f4a8fd 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithLegacySidecarAndS2iTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithLegacySidecarAndS2iTest.java @@ -26,6 +26,7 @@ public class OpenshiftWithLegacySidecarAndS2iTest { .setApplicationName("openshift-sidecar-test") .setApplicationVersion("0.1-SNAPSHOT") .withConfigurationResource("openshift-with-legacy-sidecar-and-s2i.properties") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config") .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-openshift", Version.getVersion()))); @ProdBuildResults diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithLocalDockerAndDeploymentResourceTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithLocalDockerAndDeploymentResourceTest.java index 189e9f5b3008a..4566a7c13257e 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithLocalDockerAndDeploymentResourceTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithLocalDockerAndDeploymentResourceTest.java @@ -31,7 +31,6 @@ public class OpenshiftWithLocalDockerAndDeploymentResourceTest { .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClasses(GreetingResource.class)) .setApplicationName("openshift-with-local-docker-and-deployment-resource") .setApplicationVersion("0.1-SNAPSHOT") - .overrideConfigKey("quarkus.openshift.deployment-kind", "Deployment") .overrideConfigKey("quarkus.container-image.builder", "docker") .overrideConfigKey("quarkus.container-image.group", "testme") .setLogFileName("k8s.log") diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithLocalDockerTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithLocalDockerTest.java index 82bf0f4fb0960..c37e13842490e 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithLocalDockerTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithLocalDockerTest.java @@ -36,6 +36,7 @@ public class OpenshiftWithLocalDockerTest { .setApplicationVersion("0.1-SNAPSHOT") .overrideConfigKey("quarkus.container-image.builder", "docker") .overrideConfigKey("quarkus.container-image.group", "testme") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config") .setLogFileName("k8s.log") .setForcedDependencies(List.of( Dependency.of("io.quarkus", "quarkus-openshift", Version.getVersion()), diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithRemoteDebugDeploymentConfigTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithRemoteDebugDeploymentConfigTest.java new file mode 100644 index 0000000000000..fb40366b86c75 --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithRemoteDebugDeploymentConfigTest.java @@ -0,0 +1,73 @@ +package io.quarkus.it.kubernetes; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.EnvVar; +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.Service; +import io.fabric8.openshift.api.model.DeploymentConfig; +import io.quarkus.builder.Version; +import io.quarkus.maven.dependency.Dependency; +import io.quarkus.test.ProdBuildResults; +import io.quarkus.test.ProdModeTestResults; +import io.quarkus.test.QuarkusProdModeTest; + +public class OpenshiftWithRemoteDebugDeploymentConfigTest { + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) + .setApplicationName("openshift-with-debug") + .setApplicationVersion("0.1-SNAPSHOT") + .withConfigurationResource("openshift-with-debug.properties") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config") + .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-openshift", Version.getVersion()))); + + @ProdBuildResults + private ProdModeTestResults prodModeTestResults; + + @Test + public void assertGeneratedResources() throws IOException { + Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); + + assertThat(kubernetesDir) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json")) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml")); + List openshiftList = DeserializationUtil.deserializeAsList( + kubernetesDir.resolve("openshift.yml")); + + assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + DeploymentConfig deployment = (DeploymentConfig) h; + assertThat(deployment.getSpec().getTemplate().getSpec().getContainers()).singleElement().satisfies(container -> { + List envVars = container.getEnv(); + assertThat(envVars).anySatisfy(envVar -> { + assertThat(envVar.getName()).isEqualTo("JAVA_TOOL_OPTIONS"); + assertThat(envVar.getValue()) + .isEqualTo("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"); + }); + }); + }); + + assertThat(openshiftList).filteredOn(h -> "Service".equals(h.getKind())).singleElement().satisfies(h -> { + Service service = (Service) h; + assertThat(service.getSpec().getPorts()).anySatisfy(p -> { + assertThat(p.getName()).isEqualTo("http"); + assertThat(p.getPort()).isEqualTo(80); + assertThat(p.getTargetPort().getIntVal()).isEqualTo(8080); + }); + + assertThat(service.getSpec().getPorts()).anySatisfy(p -> { + assertThat(p.getName()).isEqualTo("debug"); + assertThat(p.getPort()).isEqualTo(5005); + assertThat(p.getTargetPort().getIntVal()).isEqualTo(5005); + }); + }); + } +} diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithRemoteDebugTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithRemoteDebugTest.java index a365db437a79d..f2307920d6b1b 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithRemoteDebugTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithRemoteDebugTest.java @@ -12,7 +12,7 @@ import io.fabric8.kubernetes.api.model.EnvVar; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.Service; -import io.fabric8.openshift.api.model.DeploymentConfig; +import io.fabric8.kubernetes.api.model.apps.Deployment; import io.quarkus.builder.Version; import io.quarkus.maven.dependency.Dependency; import io.quarkus.test.ProdBuildResults; @@ -42,8 +42,8 @@ public void assertGeneratedResources() throws IOException { List openshiftList = DeserializationUtil.deserializeAsList( kubernetesDir.resolve("openshift.yml")); - assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { - DeploymentConfig deployment = (DeploymentConfig) h; + assertThat(openshiftList).filteredOn(h -> "Deployment".equals(h.getKind())).singleElement().satisfies(h -> { + Deployment deployment = (Deployment) h; assertThat(deployment.getSpec().getTemplate().getSpec().getContainers()).singleElement().satisfies(container -> { List envVars = container.getEnv(); assertThat(envVars).anySatisfy(envVar -> { diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithS2iTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithS2iTest.java index 136f04936feb5..fe9fadee8c406 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithS2iTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithS2iTest.java @@ -30,6 +30,7 @@ public class OpenshiftWithS2iTest { .setApplicationName("openshift-s2i") .setApplicationVersion("0.1-SNAPSHOT") .withConfigurationResource("openshift-with-s2i.properties") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config") .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-openshift", Version.getVersion()))); @ProdBuildResults diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithServiceBindingTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithServiceBindingTest.java index e5a65ebae4cea..b5a1ac35e579a 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithServiceBindingTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithServiceBindingTest.java @@ -29,6 +29,7 @@ public class OpenshiftWithServiceBindingTest { .setApplicationName(APP_NAME) .setApplicationVersion("0.1-SNAPSHOT") .withConfigurationResource(APP_NAME + ".properties") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config") .setLogFileName("k8s.log") .setForcedDependencies(List.of( Dependency.of("io.quarkus", "quarkus-openshift", Version.getVersion()), diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithSidecarAndS2iDeploymentConfigTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithSidecarAndS2iDeploymentConfigTest.java new file mode 100644 index 0000000000000..ef43e0efd5e35 --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithSidecarAndS2iDeploymentConfigTest.java @@ -0,0 +1,86 @@ +package io.quarkus.it.kubernetes; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; + +import org.assertj.core.api.AbstractObjectAssert; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.PodSpec; +import io.quarkus.builder.Version; +import io.quarkus.maven.dependency.Dependency; +import io.quarkus.test.ProdBuildResults; +import io.quarkus.test.ProdModeTestResults; +import io.quarkus.test.QuarkusProdModeTest; + +public class OpenshiftWithSidecarAndS2iDeploymentConfigTest { + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) + .setApplicationName("openshift-sidecar-test") + .setApplicationVersion("0.1-SNAPSHOT") + .withConfigurationResource("openshift-with-sidecar-and-s2i.properties") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config") + .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-openshift", Version.getVersion()))); + + @ProdBuildResults + private ProdModeTestResults prodModeTestResults; + + @Test + public void assertGeneratedResources() throws IOException { + final Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); + + assertThat(kubernetesDir) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json")) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml")); + List openshiftList = DeserializationUtil.deserializeAsList( + kubernetesDir.resolve("openshift.yml")); + + assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(h.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo("openshift-sidecar-test"); + assertThat(m.getLabels().get("app.openshift.io/runtime")).isEqualTo("quarkus"); + }); + + AbstractObjectAssert specAssert = assertThat(h).extracting("spec"); + specAssert.extracting("template").extracting("spec").isInstanceOfSatisfying(PodSpec.class, + podSpec -> { + assertThat(podSpec.getContainers()).hasSize(2); + assertSidecar(podSpec); + assertApplicationContainer(podSpec); + }); + }); + } + + private void assertApplicationContainer(PodSpec podSpec) { + assertThat(podSpec.getContainers()).filteredOn(ps -> "openshift-sidecar-test".equals(ps.getName())) + .singleElement().satisfies(c -> { + assertThat(c.getEnv()).extracting("name").contains("JAVA_APP_JAR"); + }); + } + + private void assertSidecar(PodSpec podSpec) { + assertThat(podSpec.getContainers()).filteredOn(ps -> "sc".equals(ps.getName())) + .singleElement().satisfies(c -> { + assertThat(c.getImage()).isEqualTo("quay.io/sidecar/image:2.1"); + assertThat(c.getImagePullPolicy()).isEqualTo("IfNotPresent"); + assertThat(c.getCommand()).containsOnly("ls"); + assertThat(c.getArgs()).containsOnly("-l"); + assertThat(c.getWorkingDir()).isEqualTo("/work"); + assertThat(c.getVolumeMounts()).singleElement().satisfies(volumeMount -> { + assertThat(volumeMount.getName()).isEqualTo("app-config"); + assertThat(volumeMount.getMountPath()).isEqualTo("/deployments/config"); + }); + assertThat(c.getPorts()).singleElement().satisfies(p -> { + assertThat(p.getContainerPort()).isEqualTo(3000); + }); + assertThat(c.getEnv()).extracting("name").doesNotContain("JAVA_APP_JAR"); + }); + } +} diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithSidecarAndS2iTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithSidecarAndS2iTest.java index 2e06e443c00e5..0dcfd196cd23f 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithSidecarAndS2iTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithSidecarAndS2iTest.java @@ -41,7 +41,7 @@ public void assertGeneratedResources() throws IOException { List openshiftList = DeserializationUtil.deserializeAsList( kubernetesDir.resolve("openshift.yml")); - assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(openshiftList).filteredOn(h -> "Deployment".equals(h.getKind())).singleElement().satisfies(h -> { assertThat(h.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo("openshift-sidecar-test"); assertThat(m.getLabels().get("app.openshift.io/runtime")).isEqualTo("quarkus"); diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithUberJarDeploymentConfigTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithUberJarDeploymentConfigTest.java new file mode 100644 index 0000000000000..cc1b2ff5b7520 --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithUberJarDeploymentConfigTest.java @@ -0,0 +1,81 @@ +package io.quarkus.it.kubernetes; + +import static io.restassured.RestAssured.given; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.is; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; + +import org.assertj.core.api.Condition; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.EnvVar; +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.PodSpec; +import io.quarkus.builder.Version; +import io.quarkus.maven.dependency.Dependency; +import io.quarkus.test.LogFile; +import io.quarkus.test.ProdBuildResults; +import io.quarkus.test.ProdModeTestResults; +import io.quarkus.test.QuarkusProdModeTest; + +public class OpenshiftWithUberJarDeploymentConfigTest { + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) + .setApplicationName("openshift-uberjar") + .setApplicationVersion("0.1-SNAPSHOT") + .setRun(true) + .setLogFileName("k8s.log") + .withConfigurationResource("openshift-with-uberjar.properties") + .overrideConfigKey("quarkus.openshift.deployment-kind", "deployment-config") + .setForcedDependencies( + List.of( + Dependency.of("io.quarkus", "quarkus-openshift", Version.getVersion()))); + + @ProdBuildResults + private ProdModeTestResults prodModeTestResults; + + @LogFile + private Path logfile; + + @Test + public void assertApplicationRuns() { + assertThat(logfile).isRegularFile().hasFileName("k8s.log"); + TestUtil.assertLogFileContents(logfile, "kubernetes", "uberjar"); + + given().when().get("/greeting").then().statusCode(200).body(is("hello")); + } + + @Test + public void assertGeneratedResources() throws IOException { + Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); + assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json")) + .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml")); + List openshiftList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("openshift.yml")); + + assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(h.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo("openshift-uberjar"); + }); + assertThat(h).extracting("spec").extracting("template").extracting("spec").isInstanceOfSatisfying(PodSpec.class, + podSpec -> { + assertThat(podSpec.getContainers()).singleElement().satisfies(container -> { + assertThat(container.getEnv()) + .filteredOn(new Condition(e -> e.getName().equals("APP_JAVA_LIB"), + "Environment variable JAVA_APP_LIB")) + .hasSize(0); + + assertThat(container.getArgs()) + .filteredOn(new Condition(e -> e.equals("-cp"), "Classpath arguments")) + .hasSize(0); + }); + }); + }); + } + +} diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithUberJarTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithUberJarTest.java index b0343b969908d..32d7f1d27da5a 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithUberJarTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithUberJarTest.java @@ -27,9 +27,14 @@ public class OpenshiftWithUberJarTest { @RegisterExtension static final QuarkusProdModeTest config = new QuarkusProdModeTest() .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) - .setApplicationName("openshift-uberjar").setApplicationVersion("0.1-SNAPSHOT").setRun(true) - .setLogFileName("k8s.log").withConfigurationResource("openshift-with-uberjar.properties") - .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-openshift", Version.getVersion()))); + .setApplicationName("openshift-uberjar") + .setApplicationVersion("0.1-SNAPSHOT") + .setRun(true) + .setLogFileName("k8s.log") + .withConfigurationResource("openshift-with-uberjar.properties") + .setForcedDependencies( + List.of( + Dependency.of("io.quarkus", "quarkus-openshift", Version.getVersion()))); @ProdBuildResults private ProdModeTestResults prodModeTestResults; @@ -52,7 +57,7 @@ public void assertGeneratedResources() throws IOException { .isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml")); List openshiftList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("openshift.yml")); - assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(openshiftList).filteredOn(h -> "Deployment".equals(h.getKind())).singleElement().satisfies(h -> { assertThat(h.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo("openshift-uberjar"); });