From 0ac4ea3462386c56eae620f04c7a2ebf3c3a615e Mon Sep 17 00:00:00 2001 From: mrizzi Date: Sun, 17 Jan 2021 15:22:09 +0100 Subject: [PATCH] Remove ApplyLabelSelectorDecorator from MinikubeHandler --- .../deployment/MinikubeHandler.java | 2 - .../invoker.properties | 2 + .../minikube-with-existing-manifest/pom.xml | 135 ++++++++++++++++++ .../src/main/docker/Dockerfile.jvm | 22 +++ .../src/main/java/org/acme/Hello.java | 16 +++ .../src/main/kubernetes/minikube.json | 119 +++++++++++++++ .../src/main/resources/application.properties | 2 + .../verify.groovy | 48 +++++++ 8 files changed, 344 insertions(+), 2 deletions(-) create mode 100644 integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/invoker.properties create mode 100644 integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/pom.xml create mode 100644 integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/src/main/docker/Dockerfile.jvm create mode 100644 integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/src/main/java/org/acme/Hello.java create mode 100644 integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/src/main/kubernetes/minikube.json create mode 100644 integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/src/main/resources/application.properties create mode 100644 integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/verify.groovy diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/MinikubeHandler.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/MinikubeHandler.java index d2a1a8955f351..e185107b41458 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/MinikubeHandler.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/MinikubeHandler.java @@ -34,7 +34,6 @@ import io.dekorate.kubernetes.decorator.AddServiceResourceDecorator; import io.dekorate.kubernetes.decorator.ApplyHeadlessDecorator; import io.dekorate.kubernetes.decorator.ApplyImageDecorator; -import io.dekorate.kubernetes.decorator.ApplyLabelSelectorDecorator; import io.dekorate.kubernetes.decorator.ApplyReplicasDecorator; import io.dekorate.project.ApplyProjectInfo; import io.dekorate.project.Project; @@ -125,7 +124,6 @@ protected void addDecorators(String group, KubernetesConfig config) { } resources.decorate(group, new AddIngressDecorator(config, Labels.createLabelsAsMap(config, "Ingress"))); - resources.decorate(group, new ApplyLabelSelectorDecorator(createSelector(config))); } /** diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/invoker.properties b/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/invoker.properties new file mode 100644 index 0000000000000..f0dfb6e6c40a1 --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/invoker.properties @@ -0,0 +1,2 @@ +# invoker.goals=clean package -Dquarkus.container.build=true -Dquarkus.package.type=native +invoker.goals=clean package diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/pom.xml b/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/pom.xml new file mode 100644 index 0000000000000..f7fb53fff2e86 --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/pom.xml @@ -0,0 +1,135 @@ + + + 4.0.0 + org.acme + minikube-with-existing-manifest + 0.1-SNAPSHOT + + UTF-8 + 3.0.0-M5 + 1.8 + UTF-8 + 1.8 + + + + + io.quarkus + quarkus-bom + @project.version@ + pom + import + + + + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-kubernetes + + + io.quarkus + quarkus-minikube + + + 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 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + ${native.surefire.skip} + + + + io.quarkus + quarkus-maven-plugin + @project.version@ + + + + native-image + + + true + + + + + + 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/minikube-with-existing-manifest/src/main/docker/Dockerfile.jvm b/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/src/main/docker/Dockerfile.jvm new file mode 100644 index 0000000000000..fa97e4b117200 --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/src/main/docker/Dockerfile.jvm @@ -0,0 +1,22 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the docker image run: +# +# mvn package +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/getting-started-jvm . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/getting-started-jvm +# +### +FROM fabric8/java-alpine-openjdk8-jre +ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV AB_ENABLED=jmx_exporter +COPY target/lib/* /deployments/lib/ +COPY target/*-runner.jar /deployments/app.jar +ENTRYPOINT [ "/deployments/run-java.sh" ] \ No newline at end of file diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/src/main/java/org/acme/Hello.java b/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/src/main/java/org/acme/Hello.java new file mode 100644 index 0000000000000..ad80766a17747 --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/src/main/java/org/acme/Hello.java @@ -0,0 +1,16 @@ +package org.acme; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/hello") +public class Hello { + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return "hello"; + } +} \ No newline at end of file diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/src/main/kubernetes/minikube.json b/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/src/main/kubernetes/minikube.json new file mode 100644 index 0000000000000..caca28a449307 --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/src/main/kubernetes/minikube.json @@ -0,0 +1,119 @@ +[ + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "labels": { + "app.kubernetes.io/name": "postgres", + "app.kubernetes.io/version" : "10.6" + }, + "name": "postgres" + }, + "spec": { + "ports": [ + { + "name": "tcp", + "port": 5432, + "protocol": "TCP", + "targetPort": 5432 + } + ], + "selector": { + "app.kubernetes.io/name": "postgres", + "app.kubernetes.io/version" : "10.6" + }, + "sessionAffinity": "None", + "type": "ClusterIP" + } + }, + { + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "labels": { + "app.kubernetes.io/name": "postgres", + "app.kubernetes.io/version" : "10.6" + }, + "name": "postgres" + }, + "spec": { + "progressDeadlineSeconds": 600, + "replicas": 1, + "selector" : { + "matchLabels": { + "app.kubernetes.io/name": "postgres", + "app.kubernetes.io/version" : "10.6" + } + }, + "strategy": { + "rollingUpdate": { + "maxSurge": "25%", + "maxUnavailable": "25%" + }, + "type": "RollingUpdate" + }, + "template": { + "metadata": { + "labels": { + "app.kubernetes.io/name": "postgres", + "app.kubernetes.io/version" : "10.6" + } + }, + "spec": { + "containers": [ + { + "env": [ + { + "name": "POSTGRES_USER", + "value": "controls" + }, + { + "name": "POSTGRES_PASSWORD", + "value": "controls" + }, + { + "name": "POSTGRES_DB", + "value": "controls_db" + } + ], + "image": "postgres:10.6", + "imagePullPolicy": "IfNotPresent", + "name": "postgres", + "ports": [ + { + "containerPort": 5432, + "protocol": "TCP" + } + ], + "readinessProbe": { + "timeoutSeconds": 1, + "initialDelaySeconds": 5, + "exec": { + "command": [ "psql", "-U", "$(POSTGRES_USER)", "-d", "$(POSTGRES_DB)", "-c", "SELECT 1" ] + } + }, + "livenessProbe": { + "timeoutSeconds": 10, + "initialDelaySeconds": 120, + "exec": { + "command": [ "psql", "-U", "$(POSTGRES_USER)", "-d", "$(POSTGRES_DB)", "-c", "SELECT 1" ] + } + }, + "resources": {}, + "securityContext": { + "privileged": false + }, + "terminationMessagePath": "/dev/termination-log", + "terminationMessagePolicy": "File" + } + ], + "dnsPolicy": "ClusterFirst", + "restartPolicy": "Always", + "schedulerName": "default-scheduler", + "securityContext": {}, + "terminationGracePeriodSeconds": 30 + } + } + } + } +] diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/src/main/resources/application.properties b/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/src/main/resources/application.properties new file mode 100644 index 0000000000000..75b9417d6dc14 --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/src/main/resources/application.properties @@ -0,0 +1,2 @@ +# Configuration file +# key = value diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/verify.groovy b/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/verify.groovy new file mode 100644 index 0000000000000..e0ffe79f260c8 --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/minikube-with-existing-manifest/verify.groovy @@ -0,0 +1,48 @@ +import io.dekorate.utils.Serialization +import io.dekorate.deps.kubernetes.api.model.KubernetesList +import io.dekorate.deps.kubernetes.api.model.Container +import io.dekorate.deps.kubernetes.api.model.Service +import io.dekorate.deps.kubernetes.api.model.apps.Deployment; + +//Check that file exits +String base = basedir +File kubernetesYml = new File(base, "target/kubernetes/minikube.yml") +assert kubernetesYml.exists() +kubernetesYml.withInputStream { stream -> + //Check that its parse-able + KubernetesList list = Serialization.unmarshalAsList(stream) + assert list != null + + //Check that it contains the existing Service provided + Service service = list.items.find{ r -> r.kind == "Service" && r.metadata.name == "postgres"} + assert service != null + assert service.metadata.labels.get("app.kubernetes.io/name") == "postgres" + assert service.metadata.labels.get("app.kubernetes.io/version") == "10.6" + assert service.spec.selector.get("app.kubernetes.io/name") == "postgres" + assert service.spec.selector.get("app.kubernetes.io/version") == "10.6" + + //Check that it contains the existing Deployment with provided labels and selector + Deployment deploymentProvided = list.items.find{r -> r.kind == "Deployment" && r.metadata.name == "postgres"} + assert deploymentProvided != null + assert deploymentProvided.metadata.labels.get("app.kubernetes.io/name") == "postgres" + assert deploymentProvided.metadata.labels.get("app.kubernetes.io/version") == "10.6" + assert deploymentProvided.spec.replicas == 1 + + assert deploymentProvided.spec.selector.matchLabels.get("app.kubernetes.io/name") == "postgres" + assert deploymentProvided.spec.selector.matchLabels.get("app.kubernetes.io/version") == "10.6" + + Container container = deploymentProvided.spec.template.spec.containers[0] + assert container != null + assert container.name == "postgres" + assert container.ports.find{p -> p.protocol = "TCP"}.containerPort == 5432 + + //Check that it created the application's Deployment with right labels and selector + Deployment deployment = list.items.find{r -> r.kind == "Deployment" && r.metadata.name == "minikube-with-existing-manifest"} + assert deployment != null + assert deployment.metadata.labels.get("app.kubernetes.io/name") == "minikube-with-existing-manifest" + assert deployment.metadata.labels.get("app.kubernetes.io/version") == "0.1-SNAPSHOT" + assert deployment.spec.replicas == 1 + + assert deployment.spec.selector.matchLabels.get("app.kubernetes.io/name") == "minikube-with-existing-manifest" + assert deployment.spec.selector.matchLabels.get("app.kubernetes.io/version") == "0.1-SNAPSHOT" +}