diff --git a/docs/src/main/asciidoc/deploying-to-kubernetes.adoc b/docs/src/main/asciidoc/deploying-to-kubernetes.adoc index 45a3050cb11070..f9f324ee719143 100644 --- a/docs/src/main/asciidoc/deploying-to-kubernetes.adoc +++ b/docs/src/main/asciidoc/deploying-to-kubernetes.adoc @@ -595,7 +595,6 @@ The table below describe all the available configuration options. | quarkus.kubernetes.arguments | String[] | | | quarkus.kubernetes.replicas | int | | 1 | quarkus.kubernetes.service-account | String | | -| quarkus.kubernetes.host | String | | | quarkus.kubernetes.ports | Map | | | quarkus.kubernetes.service-type | ServiceType | | ClusterIP | quarkus.kubernetes.pvc-volumes | Map | | @@ -611,7 +610,9 @@ The table below describe all the available configuration options. | quarkus.kubernetes.liveness-probe | Probe | | ( see Probe ) | quarkus.kubernetes.readiness-probe | Probe | | ( see Probe ) | quarkus.kubernetes.sidecars | Map | | -| quarkus.kubernetes.expose | boolean | | false +| quarkus.kubernetes.ingress.expose | boolean | | false +| quarkus.kubernetes.ingress.host | String | | +| quarkus.kubernetes.ingress.annotations | Map | | | quarkus.kubernetes.headless | boolean | | false | quarkus.kubernetes.hostaliases | Map | | | quarkus.kubernetes.resources.requests.cpu | String | | @@ -833,7 +834,6 @@ The OpenShift resources can be customized in a similar approach with Kubernetes. | quarkus.openshift.arguments | String[] | | | quarkus.openshift.replicas | int | | 1 | quarkus.openshift.service-account | String | | -| quarkus.openshift.host | String | | | quarkus.openshift.ports | Map | | | quarkus.openshift.service-type | ServiceType | | ClusterIP | quarkus.openshift.pvc-volumes | Map | | @@ -849,7 +849,9 @@ The OpenShift resources can be customized in a similar approach with Kubernetes. | quarkus.openshift.liveness-probe | Probe | | ( see Probe ) | quarkus.openshift.readiness-probe | Probe | | ( see Probe ) | quarkus.openshift.sidecars | Map | | -| quarkus.openshift.expose | boolean | | false +| quarkus.openshift.route.expose | boolean | | false +| quarkus.openshift.route.host | String | | +| quarkus.openshift.route.annotations | Map | | | quarkus.openshift.headless | boolean | | false |==== diff --git a/docs/src/main/asciidoc/deploying-to-openshift.adoc b/docs/src/main/asciidoc/deploying-to-openshift.adoc index bd4f8f0c492206..6437087ea7ddd8 100644 --- a/docs/src/main/asciidoc/deploying-to-openshift.adoc +++ b/docs/src/main/asciidoc/deploying-to-openshift.adoc @@ -163,17 +163,20 @@ To expose a `Route` for the Quarkus application: [source,properties] ---- -quarkus.openshift.expose=true +quarkus.openshift.route.expose=true ---- -Tip: You don't necessarily need to add this property in the `application.properties`. You can pass it as a command line argument: +[TIP] +==== +You don't necessarily need to add this property in the `application.properties`. You can pass it as a command line argument: [source,bash,subs=attributes+] ---- -./mvnw clean package -Dquarkus.openshift.expose=true +./mvnw clean package -Dquarkus.openshift.route.expose=true ---- The same applies to all properties listed below. +==== ==== Labels diff --git a/extensions/kubernetes/minikube/deployment/src/main/java/io/quarkus/minikube/deployment/MinikubeProcessor.java b/extensions/kubernetes/minikube/deployment/src/main/java/io/quarkus/minikube/deployment/MinikubeProcessor.java index 58361c6d3dabbb..bc4d9a2967dc19 100644 --- a/extensions/kubernetes/minikube/deployment/src/main/java/io/quarkus/minikube/deployment/MinikubeProcessor.java +++ b/extensions/kubernetes/minikube/deployment/src/main/java/io/quarkus/minikube/deployment/MinikubeProcessor.java @@ -74,7 +74,7 @@ public void createAnnotations(KubernetesConfig config, BuildProducer labels, - BuildProducer imageLabels) { + BuildProducer imageLabels) { config.getLabels().forEach((k, v) -> { labels.produce(new KubernetesLabelBuildItem(k, v, MINIKUBE)); imageLabels.produce(new ContainerImageLabelBuildItem(k, v)); diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/ApplyExpositionConfigurator.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/ApplyExpositionConfigurator.java new file mode 100644 index 00000000000000..a5d033c96602bc --- /dev/null +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/ApplyExpositionConfigurator.java @@ -0,0 +1,23 @@ +package io.quarkus.kubernetes.deployment; + +import io.dekorate.kubernetes.config.BaseConfigFluent; +import io.dekorate.kubernetes.config.Configurator; + +public class ApplyExpositionConfigurator extends Configurator { + + private final ExpositionConfig expositionConfig; + + public ApplyExpositionConfigurator(ExpositionConfig expositionConfig) { + this.expositionConfig = expositionConfig; + } + + @Override + public void visit(BaseConfigFluent config) { + if (expositionConfig.expose) { + config.withExpose(true); + if (expositionConfig.host.isPresent()) { + config.withHost(expositionConfig.host.get()); + } + } + } +} diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/ExpositionConfig.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/ExpositionConfig.java new file mode 100644 index 00000000000000..2ca689ad503988 --- /dev/null +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/ExpositionConfig.java @@ -0,0 +1,31 @@ +package io.quarkus.kubernetes.deployment; + +import java.util.Map; +import java.util.Optional; + +import io.quarkus.runtime.annotations.ConfigGroup; +import io.quarkus.runtime.annotations.ConfigItem; + +@ConfigGroup +public class ExpositionConfig { + + /** + * If true, the service will be exposed + */ + @ConfigItem + boolean expose; + + /** + * The host under which the application is going to be exposed + */ + @ConfigItem + Optional host; + + /** + * Custom annotations to add to exposition (route or ingress) resources + */ + @ConfigItem + Map annotations; + + +} 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 ae8fa44f2b5e77..4ce7ce54ad5be9 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 @@ -91,6 +91,7 @@ public class KnativeConfig implements PlatformConfiguration { /** * The host under which the application is going to be exposed + * */ @ConfigItem Optional host; diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesCommonHelper.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesCommonHelper.java index def272daf4b6f9..766ff326facc3a 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesCommonHelper.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesCommonHelper.java @@ -1,15 +1,12 @@ package io.quarkus.kubernetes.deployment; -import static io.quarkus.kubernetes.deployment.Constants.QUARKUS_ANNOTATIONS_BUILD_TIMESTAMP; -import static io.quarkus.kubernetes.deployment.Constants.QUARKUS_ANNOTATIONS_COMMIT_ID; -import static io.quarkus.kubernetes.deployment.Constants.QUARKUS_ANNOTATIONS_VCS_URL; - import java.nio.file.Path; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -17,6 +14,7 @@ import java.util.Optional; import java.util.Set; +import io.dekorate.deps.openshift.api.model.Route; import io.dekorate.kubernetes.config.Annotation; import io.dekorate.kubernetes.config.PortBuilder; import io.dekorate.kubernetes.configurator.AddPort; @@ -45,6 +43,7 @@ import io.dekorate.kubernetes.decorator.ApplyServiceAccountNamedDecorator; import io.dekorate.kubernetes.decorator.ApplyWorkingDirDecorator; import io.dekorate.kubernetes.decorator.RemoveAnnotationDecorator; +import io.dekorate.openshift.decorator.AddRouteDecorator; import io.dekorate.project.BuildInfo; import io.dekorate.project.FileProjectFactory; import io.dekorate.project.Project; @@ -66,6 +65,8 @@ import io.quarkus.kubernetes.spi.KubernetesRoleBindingBuildItem; import io.quarkus.kubernetes.spi.KubernetesRoleBuildItem; +import static io.quarkus.kubernetes.deployment.Constants.*; + public class KubernetesCommonHelper { private static final String OUTPUT_ARTIFACT_FORMAT = "%s%s.jar"; @@ -145,6 +146,7 @@ public static List createDecorators(Optional projec result.addAll(createContainerDecorators(project, target, name, config)); result.addAll(createMountAndVolumeDecorators(project, target, name, config)); + //Handle Command and arguments command.ifPresent(c -> { result.add(new DecoratorBuildItem(new ApplyCommandDecorator(name, new String[] { c.getCommand() }))); @@ -325,6 +327,17 @@ private static List createAnnotationDecorators(Optional expostionAnnotations = config.getExposition().get().annotations; + String kind = "Ingress"; + if (config.getTargetPlatformName().equals(OPENSHIFT)) { + kind = "Route"; + } + for (Map.Entry annotation : expostionAnnotations.entrySet()) { + result.add(new DecoratorBuildItem(target, new AddAnnotationDecorator(name, annotation.getKey(), annotation.getValue(), kind))); + } + } + //Add metrics annotations return result; } @@ -383,4 +396,5 @@ private static Map verifyPorts(List ku return result; } + } 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 7177febda1483f..806fb2b27f8715 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 @@ -92,6 +92,8 @@ public class KubernetesConfig implements PlatformConfiguration { /** * The host under which the application is going to be exposed + * + * @deprecated Use the {@code quarkus.kubernetes.ingress.host} instead */ @ConfigItem Optional host; @@ -227,10 +229,17 @@ public class KubernetesConfig implements PlatformConfiguration { /** * If true, a Kubernetes Ingress will be created + * + * @deprecated Use the {@code quarkus.kubernetes.ingress.expose} instead */ @ConfigItem boolean expose; + /** + * Ingress configuration + */ + ExpositionConfig ingress; + /** * If true, the 'app.kubernetes.io/version' label will be part of the selectors of Service and Deployment */ @@ -409,4 +418,9 @@ public ResourcesConfig getResources() { public boolean isExpose() { return expose; } + + @Override + public Optional getExposition() { + return Optional.of(ingress); + } } diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesConfigUtil.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesConfigUtil.java index 78cbd30dec5aa1..e2a4349b4713eb 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesConfigUtil.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesConfigUtil.java @@ -20,6 +20,7 @@ import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.config.ConfigProvider; +import org.jboss.logging.Logger; import io.dekorate.utils.Strings; @@ -34,6 +35,8 @@ public class KubernetesConfigUtil { private static final String EXPOSE_PROPERTY_NAME = "expose"; private static final String[] EXPOSABLE_GENERATORS = { OPENSHIFT, KUBERNETES }; + private static final Logger log = Logger.getLogger(KubernetesConfigUtil.class); + public static List getUserSpecifiedDeploymentTargets() { Config config = ConfigProvider.getConfig(); String configValue = config.getOptionalValue(DEPLOYMENT_TARGET, String.class) @@ -83,7 +86,6 @@ public static Map toMap(PlatformConfiguration... platformConfigu } } - // hard-coded support for exposed handleExpose(config, unPrefixed, platformConfigurations); result.putAll(unPrefixed); @@ -92,6 +94,7 @@ public static Map toMap(PlatformConfiguration... platformConfigu return result; } + @Deprecated private static void handleExpose(Config config, Map unPrefixed, PlatformConfiguration... platformConfigurations) { for (String generator : EXPOSABLE_GENERATORS) { @@ -101,11 +104,25 @@ private static void handleExpose(Config config, Map unPrefixed, .getOptionalValue(QUARKUS_PREFIX + generator + "." + EXPOSE_PROPERTY_NAME, Boolean.class) .orElse(false); if (unprefixedExpose || prefixedExpose) { + if (generator == KUBERNETES) { + log.warn("Usage of quarkus.kubernetes.expose is deprecated in favor of quarkus.kubernetes.ingress.expose"); + } else { + log.warn("Usage of quarkus.openshift.expose is deprecated in favor of quarkus.openshift.route.expose"); + } unPrefixed.put(DEKORATE_PREFIX + generator + "." + EXPOSE_PROPERTY_NAME, true); for (PlatformConfiguration platformConfiguration : platformConfigurations) { if (platformConfiguration.getConfigName().equals(generator)) { platformConfiguration.getHost() - .ifPresent(h -> unPrefixed.put(DEKORATE_PREFIX + generator + ".host", h)); + .ifPresent(h -> { + unPrefixed.put(DEKORATE_PREFIX + generator + ".host", h); + if (generator == KUBERNETES) { + log.warn( + "Usage of quarkus.kubernetes.host is deprecated in favor of quarkus.kubernetes.ingress.host"); + } else { + log.warn( + "Usage of quarkus.openshift.host is deprecated in favor of quarkus.openshift.route.host"); + } + }); break; } } diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesDeployer.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesDeployer.java index 8b67b578e6384e..0043f1833e01fc 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesDeployer.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesDeployer.java @@ -164,8 +164,8 @@ private Optional getOptionalDeploymentTarge } private DeploymentResultBuildItem deploy(DeploymentTargetEntry deploymentTarget, - KubernetesClient client, Path outputDir, - OpenshiftConfig openshiftConfig, ApplicationInfoBuildItem applicationInfo) { + KubernetesClient client, Path outputDir, + OpenshiftConfig openshiftConfig, ApplicationInfoBuildItem applicationInfo) { String namespace = Optional.ofNullable(client.getNamespace()).orElse("default"); log.info("Deploying to " + deploymentTarget.getName().toLowerCase() + " server: " + client.getMasterUrl() + " in namespace: " + namespace + "."); 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 9413f7e6451f80..80271ffa204953 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 @@ -108,6 +108,8 @@ public void build(ApplicationInfoBuildItem applicationInfo, throw new RuntimeException("Unable to setup environment for generating Kubernetes resources", e); } + log.warn("exposition openshift=" + openshiftConfig.route.host); + Map config = KubernetesConfigUtil.toMap(kubernetesConfig, openshiftConfig, knativeConfig); Set deploymentTargets = kubernetesDeploymentTargets.getEntriesSortedByPriority().stream() .map(DeploymentTargetEntry::getName) 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 baf3e63bc25fd0..c5aabfe5e8c67c 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 @@ -106,6 +106,8 @@ public static enum OpenshiftFlavor { /** * The host under which the application is going to be exposed + * + * @deprecated Use the {@code quarkus.openshift.route.host} instead */ @ConfigItem Optional host; @@ -241,10 +243,17 @@ public static enum OpenshiftFlavor { /** * If true, an Openshift Route will be created + * + * @deprecated Use the {@code quarkus.openshift.route.exposition} instead */ @ConfigItem boolean expose; + /** + * Openshift route configuration + */ + ExpositionConfig route; + /** * If true, the 'app.kubernetes.io/version' label will be part of the selectors of Service and DeploymentConfig */ @@ -428,4 +437,9 @@ public Map getEnvVars() { public EnvVarsConfig getEnv() { return env; } + + @Override + public Optional getExposition() { + return Optional.of(route); + } } diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/OpenshiftProcessor.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/OpenshiftProcessor.java index 1f467a1c0a6699..61ae74ed98e460 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/OpenshiftProcessor.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/OpenshiftProcessor.java @@ -16,6 +16,7 @@ import java.util.Optional; import java.util.stream.Stream; +import io.dekorate.deps.openshift.api.model.RouteBuilder; import io.dekorate.kubernetes.annotation.ServiceType; import io.dekorate.kubernetes.config.EnvBuilder; import io.dekorate.kubernetes.decorator.AddEnvVarDecorator; @@ -73,7 +74,7 @@ public void createAnnotations(OpenshiftConfig config, BuildProducer labels, - BuildProducer imageLabels) { + BuildProducer imageLabels) { config.getLabels().forEach((k, v) -> { labels.produce(new KubernetesLabelBuildItem(k, v, OPENSHIFT)); imageLabels.produce(new ContainerImageLabelBuildItem(k, v)); @@ -82,12 +83,13 @@ public void createLabels(OpenshiftConfig config, BuildProducer createConfigurators(ApplicationInfoBuildItem applicationInfo, - OpenshiftConfig config, Capabilities capabilities, Optional image, - List ports) { + OpenshiftConfig config, Capabilities capabilities, Optional image, + List ports) { List result = new ArrayList<>(); result.addAll(KubernetesCommonHelper.createPlatformConfigurators(config)); result.addAll(KubernetesCommonHelper.createGlobalConfigurators(ports)); + result.add(new ConfiguratorBuildItem(new ApplyExpositionConfigurator(config.route))); if (!capabilities.isCapabilityPresent(Capabilities.CONTAINER_IMAGE_S2I) && !capabilities.isCapabilityPresent(Capabilities.CONTAINER_IMAGE_OPENSHIFT)) { @@ -197,5 +199,4 @@ public List createDecorators(ApplicationInfoBuildItem applic return result; } - } 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 2fbb21054b1ae5..096dc083278e51 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 @@ -70,6 +70,10 @@ public interface PlatformConfiguration extends EnvVarHolder { ResourcesConfig getResources(); + default Optional getExposition() { + return Optional.empty(); + } + default boolean isExpose() { return false; } diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/VanillaKubernetesProcessor.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/VanillaKubernetesProcessor.java index 0a6086664bb703..8859b7e3005ab6 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/VanillaKubernetesProcessor.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/VanillaKubernetesProcessor.java @@ -70,7 +70,7 @@ public void createAnnotations(KubernetesConfig config, BuildProducer labels, - BuildProducer imageLabels) { + BuildProducer imageLabels) { config.labels.forEach((k, v) -> { labels.produce(new KubernetesLabelBuildItem(k, v, KUBERNETES)); imageLabels.produce(new ContainerImageLabelBuildItem(k, v)); @@ -82,19 +82,20 @@ public List createConfigurators(KubernetesConfig config, List result = new ArrayList<>(); result.addAll(KubernetesCommonHelper.createPlatformConfigurators(config)); result.addAll(KubernetesCommonHelper.createGlobalConfigurators(ports)); + result.add(new ConfiguratorBuildItem(new ApplyExpositionConfigurator((config.ingress)))); return result; } @BuildStep public List createDecorators(ApplicationInfoBuildItem applicationInfo, - OutputTargetBuildItem outputTarget, KubernetesConfig config, PackageConfig packageConfig, - Optional metricsConfiguration, List annotations, - List labels, List envs, - Optional image, Optional command, - List ports, Optional livenessPath, - Optional readinessPath, List roles, - List roleBindings) { + OutputTargetBuildItem outputTarget, KubernetesConfig config, PackageConfig packageConfig, + Optional metricsConfiguration, List annotations, + List labels, List envs, + Optional image, Optional command, + List ports, Optional livenessPath, + Optional readinessPath, List roles, + List roleBindings) { final List result = new ArrayList<>(); final String name = ResourceNameUtil.getResourceName(config, applicationInfo); @@ -102,7 +103,6 @@ public List createDecorators(ApplicationInfoBuildItem applic Optional project = KubernetesCommonHelper.createProject(applicationInfo, outputTarget, packageConfig); result.addAll(KubernetesCommonHelper.createDecorators(project, KUBERNETES, name, config, metricsConfiguration, annotations, labels, command, ports, livenessPath, readinessPath, roles, roleBindings)); - if (config.getReplicas() != 1) { result.add(new DecoratorBuildItem(KUBERNETES, new ApplyReplicasDecorator(name, config.getReplicas()))); } diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithRoutePropertiesTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithRoutePropertiesTest.java new file mode 100644 index 00000000000000..13353dafc689cf --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithRoutePropertiesTest.java @@ -0,0 +1,71 @@ +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.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.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.Service; +import io.fabric8.openshift.api.model.Route; +import io.quarkus.test.ProdBuildResults; +import io.quarkus.test.ProdModeTestResults; +import io.quarkus.test.QuarkusProdModeTest; + +public class OpenshiftWithRoutePropertiesTest { + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClasses(GreetingResource.class)) + .setApplicationName("openshift") + .setApplicationVersion("0.1-SNAPSHOT") + .withConfigurationResource("openshift-with-route.properties"); + + @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 -> "Service".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(h).isInstanceOfSatisfying(Service.class, s -> { + assertThat(s.getMetadata()).satisfies(m -> { + assertThat(m.getNamespace()).isEqualTo("applications"); + }); + + assertThat(s.getSpec()).satisfies(spec -> { + assertThat(spec.getSelector()).contains(entry("app.kubernetes.io/name", "test-it")); + assertThat(spec.getPorts()).hasSize(1).singleElement().satisfies(p -> { + assertThat(p.getPort()).isEqualTo(9090); + }); + }); + }); + }); + + assertThat(openshiftList).filteredOn(i -> "Route".equals(i.getKind())).singleElement().satisfies(i -> { + assertThat(i).isInstanceOfSatisfying(Route.class, in -> { + //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.getAnnotations()).contains(entry("kubernetes.io/tls-acme", "true")); + assertThat(m.getNamespace()).isEqualTo("applications"); + }); + assertThat(in.getSpec().getHost()).isEqualTo("foo.bar.io"); + }); + }); + } +} 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 2396cda7aaf149..698af3b9baa91c 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 @@ -8,8 +8,8 @@ quarkus.kubernetes.env-vars.my-name.field=metadata.name quarkus.kubernetes.add-version-to-label-selectors=false quarkus.container-image.group=grp quarkus.container-image.registry=quay.io -quarkus.kubernetes.expose=true -quarkus.kubernetes.host=example.com +quarkus.kubernetes.ingress.expose=true +quarkus.kubernetes.ingress.host=example.com quarkus.kubernetes.service-type=NodePort quarkus.kubernetes.image-pull-policy=IfNotPresent quarkus.kubernetes.replicas=3 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 d96b352e850545..50739117762760 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 @@ -6,7 +6,7 @@ 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.openshift.route.expose=true quarkus.s2i.registry=quay.io quarkus.openshift.replicas=3 quarkus.openshift.add-version-to-label-selectors=false diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/openshift-with-route.properties b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/openshift-with-route.properties new file mode 100644 index 00000000000000..a42e2e6b443efb --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/openshift-with-route.properties @@ -0,0 +1,13 @@ +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.group=grp + +quarkus.openshift.route.expose=true +quarkus.openshift.route.host=foo.bar.io +quarkus.openshift.route.annotations."kubernetes.io/tls-acme"=true + +quarkus.s2i.registry=quay.io \ No newline at end of file