From e673ea5989f422866bcd37cfac05fac6453f13d0 Mon Sep 17 00:00:00 2001 From: Jose Date: Mon, 5 Dec 2022 14:28:51 +0100 Subject: [PATCH] Add spec.metadata.labels in Deployment resource for OpenShift Fix https://github.com/quarkusio/quarkus/issues/29497 --- .../deployment/AddDeploymentResourceDecorator.java | 2 ++ .../OpenshiftWithDeploymentResourceTest.java | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddDeploymentResourceDecorator.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddDeploymentResourceDecorator.java index c877ad32e26e0..2afcf46e728de 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddDeploymentResourceDecorator.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddDeploymentResourceDecorator.java @@ -24,6 +24,8 @@ public void visit(KubernetesListFluent list) { .withMatchLabels(new HashMap()) .endSelector() .withNewTemplate() + .withNewMetadata() + .endMetadata() .withNewSpec() .addNewContainer() .withName(name) diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDeploymentResourceTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDeploymentResourceTest.java index d4e5ae89ea863..4b86271cfdcbf 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDeploymentResourceTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithDeploymentResourceTest.java @@ -2,6 +2,7 @@ package io.quarkus.it.kubernetes; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; import java.io.IOException; import java.nio.file.Path; @@ -29,10 +30,12 @@ // public class OpenshiftWithDeploymentResourceTest { + private static final String NAME = "openshift-with-deployment-resource"; + @RegisterExtension static final QuarkusProdModeTest config = new QuarkusProdModeTest() .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) - .setApplicationName("openshift-with-deployment-resource") + .setApplicationName(NAME) .setApplicationVersion("0.1-SNAPSHOT") .overrideConfigKey("quarkus.openshift.deployment-kind", "Deployment") .overrideConfigKey("quarkus.openshift.replicas", "3") @@ -55,17 +58,21 @@ public void assertGeneratedResources() throws IOException { assertThat(kubernetesList).filteredOn(h -> "BuildConfig".equals(h.getKind())).hasSize(1); assertThat(kubernetesList).filteredOn(h -> "ImageStream".equals(h.getKind())).hasSize(2); assertThat(kubernetesList).filteredOn(h -> "ImageStream".equals(h.getKind()) - && h.getMetadata().getName().equals("openshift-with-deployment-resource")).hasSize(1); + && h.getMetadata().getName().equals(NAME)).hasSize(1); assertThat(kubernetesList).filteredOn(i -> i instanceof Deployment).singleElement().satisfies(i -> { assertThat(i).isInstanceOfSatisfying(Deployment.class, d -> { assertThat(d.getMetadata()).satisfies(m -> { - assertThat(m.getName()).isEqualTo("openshift-with-deployment-resource"); + assertThat(m.getName()).isEqualTo(NAME); }); assertThat(d.getSpec()).satisfies(deploymentSpec -> { assertThat(deploymentSpec.getReplicas()).isEqualTo(3); assertThat(deploymentSpec.getTemplate()).satisfies(t -> { + assertThat(t.getMetadata()).satisfies(metadata -> assertThat(metadata.getLabels()).containsAnyOf( + entry("app.kubernetes.io/name", NAME), + entry("app.kubernetes.io/version", "0.1-SNAPSHOT"))); + assertThat(t.getSpec()).satisfies(podSpec -> { assertThat(podSpec.getContainers()).singleElement().satisfies(container -> { assertThat(container.getImage())