diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddNamespaceDecorator.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddNamespaceDecorator.java new file mode 100644 index 0000000000000..2ad6dbc99f468 --- /dev/null +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddNamespaceDecorator.java @@ -0,0 +1,45 @@ +package io.quarkus.kubernetes.deployment; + +import java.util.Objects; + +import io.dekorate.deps.kubernetes.api.model.ObjectMeta; +import io.dekorate.deps.kubernetes.api.model.ObjectMetaBuilder; +import io.dekorate.kubernetes.decorator.AddSidecarDecorator; +import io.dekorate.kubernetes.decorator.ContainerDecorator; +import io.dekorate.kubernetes.decorator.Decorator; +import io.dekorate.kubernetes.decorator.NamedResourceDecorator; +import io.dekorate.kubernetes.decorator.ResourceProvidingDecorator; + +public class AddNamespaceDecorator extends NamedResourceDecorator { + + private final String namespace; + + public AddNamespaceDecorator(String namespace) { + this.namespace = Objects.requireNonNull(namespace); + } + + @Override + public void andThenVisit(ObjectMetaBuilder builder, ObjectMeta resourceMeta) { + builder.withNamespace(namespace); + } + + @Override + public Class[] after() { + return new Class[] { ResourceProvidingDecorator.class, ContainerDecorator.class, AddSidecarDecorator.class }; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + AddNamespaceDecorator that = (AddNamespaceDecorator) o; + return namespace.equals(that.namespace); + } + + @Override + public int hashCode() { + return Objects.hash(namespace); + } +} diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeConfig.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeConfig.java index 05b4e3bbb96c1..d5561a8b98ce6 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeConfig.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeConfig.java @@ -31,6 +31,18 @@ public class KnativeConfig implements PlatformConfiguration { @ConfigItem(defaultValue = "${quarkus.container-image.tag}") Optional version; + /** + * The namespace the generated resources should belong to. + * If not value is set, then the 'namespace' field will not be + * added to the 'metadata' section of the generated manifests. + * This in turn means that when the manifests are applied to a cluster, + * the namespace will be resolved from the current Kubernetes context + * (see https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#context + * for more details). + */ + @ConfigItem + Optional namespace; + /** * Custom labels to add to all resources */ @@ -191,6 +203,10 @@ public Optional getVersion() { return version; } + public Optional getNamespace() { + return namespace; + } + public Map getLabels() { return labels; } diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesConfig.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesConfig.java index d0e177bdfa8c8..1d866719c9f72 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesConfig.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesConfig.java @@ -32,6 +32,18 @@ public class KubernetesConfig implements PlatformConfiguration { @ConfigItem(defaultValue = "${quarkus.container-image.tag}") Optional version; + /** + * The namespace the generated resources should belong to. + * If not value is set, then the 'namespace' field will not be + * added to the 'metadata' section of the generated manifests. + * This in turn means that when the manifests are applied to a cluster, + * the namespace will be resolved from the current Kubernetes context + * (see https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#context + * for more details). + */ + @ConfigItem + Optional namespace; + /** * Custom labels to add to all resources */ @@ -219,6 +231,10 @@ public Optional getVersion() { return version; } + public Optional getNamespace() { + return namespace; + } + public Map getLabels() { return labels; } diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesProcessor.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesProcessor.java index be381da2bbc3e..81dfebea0e5aa 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesProcessor.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesProcessor.java @@ -415,27 +415,11 @@ private void applyConfig(Session session, Project project, String target, String session.resources().decorate(OPENSHIFT, new AddLabelDecorator(new Label(OPENSHIFT_APP_RUNTIME, QUARKUS))); } - ScmInfo scm = project.getScmInfo(); - String vcsUrl = scm != null ? scm.getUrl() : null; - String commitId = scm != null ? scm.getCommit() : null; - - //Dekorate uses its own annotations. Let's replace them with the quarkus ones. - session.resources().decorate(target, new RemoveAnnotationDecorator(Annotations.VCS_URL)); - session.resources().decorate(target, new RemoveAnnotationDecorator(Annotations.COMMIT_ID)); - //Add quarkus vcs annotations - if (commitId != null) { - session.resources().decorate(target, - new AddAnnotationDecorator(new Annotation(QUARKUS_ANNOTATIONS_COMMIT_ID, commitId))); - } - if (vcsUrl != null) { - session.resources().decorate(target, - new AddAnnotationDecorator(new Annotation(QUARKUS_ANNOTATIONS_VCS_URL, vcsUrl))); + if (config.getNamespace().isPresent()) { + session.resources().decorate(target, new AddNamespaceDecorator(config.getNamespace().get())); } - if (config.isAddBuildTimestamp()) { - session.resources().decorate(target, new AddAnnotationDecorator(new Annotation(QUARKUS_ANNOTATIONS_BUILD_TIMESTAMP, - now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd - HH:mm:ss Z"))))); - } + applyAnnotations(session, project, target, config, now); config.getWorkingDir().ifPresent(w -> { session.resources().decorate(target, new ApplyWorkingDirDecorator(name, w)); @@ -505,6 +489,31 @@ private void applyConfig(Session session, Project project, String target, String session.resources().decorate(target, new RemoveOptionalFromConfigMapKeySelectorDecorator()); } + private void applyAnnotations(Session session, Project project, String target, PlatformConfiguration config, + ZonedDateTime now) { + ScmInfo scm = project.getScmInfo(); + String vcsUrl = scm != null ? scm.getUrl() : null; + String commitId = scm != null ? scm.getCommit() : null; + + //Dekorate uses its own annotations. Let's replace them with the quarkus ones. + session.resources().decorate(target, new RemoveAnnotationDecorator(Annotations.VCS_URL)); + session.resources().decorate(target, new RemoveAnnotationDecorator(Annotations.COMMIT_ID)); + //Add quarkus vcs annotations + if (commitId != null) { + session.resources().decorate(target, + new AddAnnotationDecorator(new Annotation(QUARKUS_ANNOTATIONS_COMMIT_ID, commitId))); + } + if (vcsUrl != null) { + session.resources().decorate(target, + new AddAnnotationDecorator(new Annotation(QUARKUS_ANNOTATIONS_VCS_URL, vcsUrl))); + } + + if (config.isAddBuildTimestamp()) { + session.resources().decorate(target, new AddAnnotationDecorator(new Annotation(QUARKUS_ANNOTATIONS_BUILD_TIMESTAMP, + now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd - HH:mm:ss Z"))))); + } + } + private void applyKnativeConfig(Session session, Project project, String name, KnativeConfig config) { if (config.clusterLocal) { session.resources().decorate(KNATIVE, new AddLabelDecorator(name, 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 68ebdba4cd355..4b0832cfb690b 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 @@ -33,6 +33,18 @@ public class OpenshiftConfig implements PlatformConfiguration { @ConfigItem(defaultValue = "${quarkus.container-image.tag}") Optional version; + /** + * The namespace the generated resources should belong to. + * If not value is set, then the 'namespace' field will not be + * added to the 'metadata' section of the generated manifests. + * This in turn means that when the manifests are applied to a cluster, + * the namespace will be resolved from the current Kubernetes context + * (see https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#context + * for more details). + */ + @ConfigItem + Optional namespace; + /** * Custom labels to add to all resources */ @@ -211,6 +223,10 @@ public Optional getVersion() { return version; } + public Optional getNamespace() { + return namespace; + } + public Map getLabels() { return labels; } diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/PlatformConfiguration.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/PlatformConfiguration.java index 146f1a24e9a3e..208e8ccde182b 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/PlatformConfiguration.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/PlatformConfiguration.java @@ -16,6 +16,8 @@ public interface PlatformConfiguration extends EnvVarHolder { Optional getVersion(); + Optional getNamespace(); + Map getLabels(); Map getAnnotations(); diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/BasicKubernetesTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/BasicKubernetesTest.java index 37357f88a7a67..7654193636c8c 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/BasicKubernetesTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/BasicKubernetesTest.java @@ -65,6 +65,7 @@ public void assertGeneratedResources() throws IOException { assertThat(kubernetesList.get(0)).isInstanceOfSatisfying(Deployment.class, d -> { assertThat(d.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo("basic"); + assertThat(m.getNamespace()).isNull(); }); assertThat(d.getSpec()).satisfies(deploymentSpec -> { @@ -82,6 +83,9 @@ public void assertGeneratedResources() throws IOException { }); assertThat(kubernetesList.get(1)).isInstanceOfSatisfying(Service.class, s -> { + assertThat(s.getMetadata()).satisfies(m -> { + assertThat(m.getNamespace()).isNull(); + }); assertThat(s.getSpec()).satisfies(spec -> { assertThat(spec.getPorts()).hasSize(1).hasOnlyOneElementSatisfying(p -> { assertThat(p.getPort()).isEqualTo(8080); @@ -89,6 +93,10 @@ public void assertGeneratedResources() throws IOException { }); }); - assertThat(kubernetesList.get(2)).isInstanceOf(ServiceAccount.class); + assertThat(kubernetesList.get(2)).isInstanceOfSatisfying(ServiceAccount.class, sa -> { + assertThat(sa.getMetadata()).satisfies(m -> { + assertThat(m.getNamespace()).isNull(); + }); + }); } } 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 f661f17892ff0..a0e7b410e3581 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 @@ -14,6 +14,7 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.PodSpec; +import io.fabric8.kubernetes.api.model.Service; import io.quarkus.test.ProdBuildResults; import io.quarkus.test.ProdModeTestResults; import io.quarkus.test.QuarkusProdModeTest; @@ -44,6 +45,7 @@ public void assertGeneratedResources() throws IOException { 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(); }); assertThat(h).extracting("spec").extracting("replicas").isEqualTo(1); assertThat(h).extracting("spec").extracting("template").extracting("spec").isInstanceOfSatisfying(PodSpec.class, @@ -55,5 +57,13 @@ public void assertGeneratedResources() throws IOException { }); }); }); + + assertThat(openshiftList).filteredOn(h -> "Service".equals(h.getKind())).hasOnlyOneElementSatisfying(h -> { + assertThat(h).isInstanceOfSatisfying(Service.class, s -> { + assertThat(s.getMetadata()).satisfies(m -> { + assertThat(m.getNamespace()).isNull(); + }); + }); + }); } } diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeTest.java index 9364ba9e205de..913bfd860822b 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeTest.java @@ -43,6 +43,10 @@ public void assertGeneratedResources() throws IOException { assertThat(kubernetesList).filteredOn(i -> "Service".equals(i.getKind())).hasOnlyOneElementSatisfying(i -> { assertThat(i).isInstanceOfSatisfying(Service.class, s -> { assertThat(s.getSpec()).satisfies(spec -> { + assertThat(s.getMetadata()).satisfies(m -> { + assertThat(m.getNamespace()).isNull(); + }); + assertThat(spec.getTemplate()).satisfies(template -> { assertThat(template.getSpec()).satisfies(templateSpec -> { assertThat(templateSpec.getContainers()).hasSize(1).hasOnlyOneElementSatisfying(c -> { diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeWithApplicationPropertiesTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeWithApplicationPropertiesTest.java new file mode 100644 index 0000000000000..03865bf83fdff --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeWithApplicationPropertiesTest.java @@ -0,0 +1,67 @@ +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; +import java.util.List; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.knative.serving.v1.Service; +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.quarkus.test.ProdBuildResults; +import io.quarkus.test.ProdModeTestResults; +import io.quarkus.test.QuarkusProdModeTest; + +public class KnativeWithApplicationPropertiesTest { + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClasses(GreetingResource.class)) + .setApplicationName("knative-with-application-properties") + .setApplicationVersion("0.1-SNAPSHOT") + .withConfigurationResource("knative-with-application.properties"); + + @ProdBuildResults + private ProdModeTestResults prodModeTestResults; + + @Test + public void assertGeneratedResources() throws IOException { + Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); + assertThat(kubernetesDir) + .isDirectoryContaining(p -> p.getFileName().endsWith("knative.json")) + .isDirectoryContaining(p -> p.getFileName().endsWith("knative.yml")) + .satisfies(p -> assertThat(p.toFile().listFiles()).hasSize(2)); + + List kubernetesList = DeserializationUtil + .deserializeAsList(kubernetesDir.resolve("knative.yml")); + + assertThat(kubernetesList).filteredOn(i -> "Service".equals(i.getKind())).hasOnlyOneElementSatisfying(i -> { + assertThat(i).isInstanceOfSatisfying(Service.class, s -> { + assertThat(s.getSpec()).satisfies(spec -> { + assertThat(s.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo("test-it"); + assertThat(m.getLabels()).contains(entry("foo", "bar")); + assertThat(m.getAnnotations()).contains(entry("bar", "baz")); + assertThat(m.getNamespace()).isEqualTo("applications"); + }); + + assertThat(spec.getTemplate()).satisfies(template -> { + assertThat(template.getSpec()).satisfies(templateSpec -> { + assertThat(templateSpec.getContainers()).hasSize(1).hasOnlyOneElementSatisfying(c -> { + assertThat(c.getPorts()).hasSize(1).hasOnlyOneElementSatisfying(p -> { + assertThat(p.getName()).isEqualTo("http1"); + }); + }); + }); + }); + }); + }); + }); + } +} diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithApplicationPropertiesTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithApplicationPropertiesTest.java index 4bcd2a8e9954f..f1ea28c90d091 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithApplicationPropertiesTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithApplicationPropertiesTest.java @@ -52,6 +52,7 @@ public void assertGeneratedResources() throws IOException { assertThat(d.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo("test-it"); assertThat(m.getLabels()).contains(entry("foo", "bar")); + assertThat(m.getNamespace()).isEqualTo("applications"); }); assertThat(d.getSpec()).satisfies(deploymentSpec -> { @@ -82,6 +83,10 @@ public void assertGeneratedResources() throws IOException { assertThat(kubernetesList).filteredOn(i -> "Service".equals(i.getKind())).hasOnlyOneElementSatisfying(i -> { assertThat(i).isInstanceOfSatisfying(Service.class, s -> { + assertThat(s.getMetadata()).satisfies(m -> { + assertThat(m.getNamespace()).isEqualTo("applications"); + }); + assertThat(s.getSpec()).satisfies(spec -> { assertEquals("NodePort", spec.getType()); assertThat(spec.getPorts()).hasSize(1).hasOnlyOneElementSatisfying(p -> { @@ -96,11 +101,12 @@ public void assertGeneratedResources() throws IOException { assertThat(kubernetesList).filteredOn(i -> "Ingress".equals(i.getKind())).hasOnlyOneElementSatisfying(i -> { assertThat(i).isInstanceOfSatisfying(Ingress.class, in -> { - //Check that lables and annotations are also applied to Ingresses (#10260) + //Check that labels and annotations are also applied to Ingresses (#10260) assertThat(i.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo("test-it"); assertThat(m.getLabels()).contains(entry("foo", "bar")); assertThat(m.getAnnotations()).contains(entry("bar", "baz")); + assertThat(m.getNamespace()).isEqualTo("applications"); }); assertThat(in.getSpec().getRules()).hasOnlyOneElementSatisfying(r -> { diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/MinikubeWithApplicationPropertiesTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/MinikubeWithApplicationPropertiesTest.java index be7eb8fe46878..4f6c6bc1b4868 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/MinikubeWithApplicationPropertiesTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/MinikubeWithApplicationPropertiesTest.java @@ -47,6 +47,7 @@ public void assertGeneratedResources() throws IOException { assertThat(m.getName()).isEqualTo("minikube-with-application-properties"); assertThat(m.getLabels()).contains(entry("foo", "bar")); assertThat(m.getAnnotations()).contains(entry("bar", "baz")); + assertThat(m.getNamespace()).isEqualTo("applications"); }); assertThat(d.getSpec()).satisfies(deploymentSpec -> { @@ -64,6 +65,10 @@ public void assertGeneratedResources() throws IOException { assertThat(kubernetesList).filteredOn(i -> "Service".equals(i.getKind())).hasOnlyOneElementSatisfying(i -> { assertThat(i).isInstanceOfSatisfying(Service.class, s -> { + assertThat(s.getMetadata()).satisfies(m -> { + assertThat(m.getNamespace()).isEqualTo("applications"); + }); + assertThat(s.getSpec()).satisfies(spec -> { assertEquals("NodePort", spec.getType()); assertThat(spec.getPorts()).hasSize(1).hasOnlyOneElementSatisfying(p -> { diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/MinikubeWithDefaultsTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/MinikubeWithDefaultsTest.java index 2284b4a7440ab..f3d6630abdd8e 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/MinikubeWithDefaultsTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/MinikubeWithDefaultsTest.java @@ -44,6 +44,10 @@ public void assertGeneratedResources() throws IOException { assertThat(kubernetesList).filteredOn(i -> "Deployment".equals(i.getKind())).hasOnlyOneElementSatisfying(i -> { assertThat(i).isInstanceOfSatisfying(Deployment.class, d -> { + assertThat(d.getMetadata()).satisfies(m -> { + assertThat(m.getNamespace()).isNull(); + }); + assertThat(d.getSpec()).satisfies(deploymentSpec -> { assertThat(deploymentSpec.getReplicas()).isEqualTo(1); assertThat(deploymentSpec.getTemplate()).satisfies(t -> { @@ -59,6 +63,10 @@ public void assertGeneratedResources() throws IOException { assertThat(kubernetesList).filteredOn(i -> "Service".equals(i.getKind())).hasOnlyOneElementSatisfying(i -> { assertThat(i).isInstanceOfSatisfying(Service.class, s -> { + assertThat(s.getMetadata()).satisfies(m -> { + assertThat(m.getNamespace()).isNull(); + }); + assertThat(s.getSpec()).satisfies(spec -> { assertEquals("NodePort", spec.getType()); assertThat(spec.getPorts()).hasSize(1).hasOnlyOneElementSatisfying(p -> { 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 1c8318dd2c2f5..ee4aa9b8d7d4b 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 @@ -46,6 +46,7 @@ public void assertGeneratedResources() throws IOException { assertThat(h.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo("test-it"); assertThat(m.getLabels()).contains(entry("foo", "bar")); + assertThat(m.getNamespace()).isEqualTo("applications"); }); assertThat(h).extracting("spec").extracting("replicas").isEqualTo(3); assertThat(h).extracting("spec").extracting("template").extracting("spec").isInstanceOfSatisfying(PodSpec.class, @@ -59,6 +60,10 @@ public void assertGeneratedResources() throws IOException { assertThat(openshiftList).filteredOn(h -> "Service".equals(h.getKind())).hasOnlyOneElementSatisfying(h -> { assertThat(h).isInstanceOfSatisfying(Service.class, s -> { + assertThat(s.getMetadata()).satisfies(m -> { + assertThat(m.getNamespace()).isEqualTo("applications"); + }); + assertThat(s.getSpec()).satisfies(spec -> { assertThat(spec.getPorts()).hasSize(1).hasOnlyOneElementSatisfying(p -> { assertThat(p.getPort()).isEqualTo(9090); @@ -69,11 +74,12 @@ public void assertGeneratedResources() throws IOException { assertThat(openshiftList).filteredOn(i -> "Route".equals(i.getKind())).hasOnlyOneElementSatisfying(i -> { assertThat(i).isInstanceOfSatisfying(Route.class, in -> { - //Check that lables and annotations are also applied to Routes (#10260) + //Check that labels and annotations are also applied to Routes (#10260) assertThat(i.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo("test-it"); assertThat(m.getLabels()).contains(entry("foo", "bar")); assertThat(m.getAnnotations()).contains(entry("bar", "baz")); + assertThat(m.getNamespace()).isEqualTo("applications"); }); }); }); diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/knative-with-application.properties b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/knative-with-application.properties new file mode 100644 index 0000000000000..784fa617f9bff --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/knative-with-application.properties @@ -0,0 +1,6 @@ +# Configuration file +quarkus.kubernetes.deployment-target=knative +quarkus.knative.name=test-it +quarkus.knative.namespace=applications +quarkus.knative.labels.foo=bar +quarkus.knative.annotations.bar=baz diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-application.properties b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-application.properties index 567a3a6d8113b..460d96bedb543 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-application.properties +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-application.properties @@ -1,5 +1,6 @@ quarkus.http.port=9090 quarkus.kubernetes.name=test-it +quarkus.kubernetes.namespace=applications quarkus.kubernetes.labels.foo=bar quarkus.kubernetes.annotations.bar=baz quarkus.kubernetes.env-vars.my-env-var.value=SOMEVALUE diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/minikube-with-application.properties b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/minikube-with-application.properties index 3a5e14e2660a1..b997cb52c8727 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/minikube-with-application.properties +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/minikube-with-application.properties @@ -1,4 +1,5 @@ quarkus.kubernetes.deployment-target=minikube +quarkus.kubernetes.namespace=applications quarkus.http.port=9090 quarkus.kubernetes.node-port=31999 quarkus.kubernetes.labels.foo=bar diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/openshift-with-application.properties b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/openshift-with-application.properties index 321fc5d18337d..c747176fdaed2 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/openshift-with-application.properties +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/openshift-with-application.properties @@ -1,10 +1,11 @@ quarkus.http.port=9090 quarkus.kubernetes.deployment-target=openshift quarkus.openshift.name=test-it +quarkus.openshift.namespace=applications quarkus.openshift.labels.foo=bar quarkus.openshift.annotations.bar=baz quarkus.openshift.env-vars.my-env-var.value=SOMEVALUE quarkus.openshift.group=grp quarkus.openshift.expose=true quarkus.s2i.registry=quay.io -quarkus.openshift.replicas=3 \ No newline at end of file +quarkus.openshift.replicas=3