diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddCronJobResourceDecorator.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddCronJobResourceDecorator.java index 907043428f78c..c3bdf1f41ff85 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddCronJobResourceDecorator.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddCronJobResourceDecorator.java @@ -65,6 +65,8 @@ private void initCronJobResourceWithDefaults(CronJobBuilder builder) { // - match labels if (jobTemplateSpec.buildSelector().getMatchLabels() == null) { jobTemplateSpec.editSelector().withMatchLabels(new HashMap<>()).endSelector(); + } else { + jobTemplateSpec.withSelector(null); } // - termination grace period seconds if (jobTemplateSpec.buildTemplate().getSpec().getTerminationGracePeriodSeconds() == null) { diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithCronJobResourceTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithCronJobResourceTest.java index 0b44ec0e142ad..1d7d759dd6230 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithCronJobResourceTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithCronJobResourceTest.java @@ -64,9 +64,7 @@ public void assertGeneratedResources() throws IOException { }); }); }); - assertThat(jobSpec.getSelector()).satisfies(ls -> { - assertThat(ls.getMatchLabels()).containsEntry("app.kubernetes.io/name", APP_NAME); - }); + assertThat(jobSpec.getSelector()).isEqualTo(null); }); }); }); diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithCronJobResourceWithoutSelectorTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithCronJobResourceWithoutSelectorTest.java new file mode 100644 index 0000000000000..0ee1858b77508 --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithCronJobResourceWithoutSelectorTest.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.kubernetes.api.model.batch.v1.CronJob; +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 KubernetesWithCronJobResourceWithoutSelectorTest { + + static final String APP_NAME = "kubernetes-with-cronjob-resource-without-selector"; + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) + .setApplicationName(APP_NAME) + .setApplicationVersion("0.1-SNAPSHOT") + .withConfigurationResource(APP_NAME + ".properties") + .setLogFileName("k8s.log") + .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-kubernetes", 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("kubernetes.json")) + .isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.yml")); + List kubernetesList = DeserializationUtil + .deserializeAsList(kubernetesDir.resolve("kubernetes.yml")); + + assertThat(kubernetesList).filteredOn(i -> i instanceof CronJob).singleElement().satisfies(i -> { + assertThat(i).isInstanceOfSatisfying(CronJob.class, s -> { + assertThat(s.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo(APP_NAME); + }); + + assertThat(s.getSpec().getJobTemplate().getSpec()).satisfies(jobSpec -> { + assertThat(jobSpec.getSelector()).isEqualTo(null); + }); + }); + }); + } +} diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithExistingCronJobResourceTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithExistingCronJobResourceTest.java index d55bff64b5dea..8af6a603c408e 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithExistingCronJobResourceTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithExistingCronJobResourceTest.java @@ -72,9 +72,7 @@ public void assertGeneratedResources() throws IOException { }); }); }); - assertThat(jobSpec.getSelector()).satisfies(ls -> { - assertThat(ls.getMatchLabels()).containsEntry("app.kubernetes.io/name", APP_NAME); - }); + assertThat(jobSpec.getSelector()).isEqualTo(null); }); }); }); diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithCronJobResourceTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithCronJobResourceTest.java index 5a4a6d8317415..3ff7977c2b490 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithCronJobResourceTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithCronJobResourceTest.java @@ -64,9 +64,7 @@ public void assertGeneratedResources() throws IOException { }); }); }); - assertThat(jobSpec.getSelector()).satisfies(ls -> { - assertThat(ls.getMatchLabels()).containsEntry("app.kubernetes.io/name", APP_NAME); - }); + assertThat(jobSpec.getSelector()).isEqualTo(null); }); }); }); diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-cronjob-resource-without-selector.properties b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-cronjob-resource-without-selector.properties new file mode 100644 index 0000000000000..66841f1056e99 --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-cronjob-resource-without-selector.properties @@ -0,0 +1,7 @@ +quarkus.kubernetes.deployment-kind=CronJob +quarkus.kubernetes.arguments=A,B +quarkus.kubernetes.cron-job.schedule=0 0 0 0 * +quarkus.kubernetes.cron-job.parallelism=10 +quarkus.kubernetes.cron-job.restart-policy=Never +quarkus.kubernetes.add-version-to-label-selectors=false +quarkus.kubernetes.add-name-to-label-selectors=false \ No newline at end of file