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 31b67b3be770aa..a919fc062bed30 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 @@ -25,6 +25,7 @@ import java.util.stream.Collectors; import org.eclipse.microprofile.config.ConfigProvider; +import org.jboss.logging.Logger; import io.dekorate.kubernetes.config.Annotation; import io.dekorate.kubernetes.config.ConfigMapVolumeBuilder; @@ -103,6 +104,10 @@ public class KubernetesCommonHelper { + private static final Map PORTS_WITH_CONFIG = Map.of("http", + new PortProperty("quarkus.http.port", 8080), + "https", new PortProperty("quarkus.http.ssl-port", 8443), + "management", new PortProperty("quarkus.management.port", 9000)); private static final String ANY = null; private static final String OUTPUT_ARTIFACT_FORMAT = "%s%s.jar"; private static final String[] PROMETHEUS_ANNOTATION_TARGETS = { "Service", @@ -111,6 +116,7 @@ public class KubernetesCommonHelper { private static final List LIST_WITH_EMPTY = List.of(""); private static final String SCHEME_HTTP = "HTTP"; private static final String SCHEME_HTTPS = "HTTPS"; + private static final Logger LOG = Logger.getLogger(KubernetesDeployer.class); public static Optional createProject(ApplicationInfoBuildItem app, Optional customProjectRoot, OutputTargetBuildItem outputTarget, @@ -186,13 +192,16 @@ public static Map combinePorts(List ports : buildItemPort.getPath()) .build(); - // Special handling for ports with name "https". We look up the container port from the Quarkus configuration. - if ("https".equals(name) && combinedPort.getContainerPort() == null) { - int containerPort = ConfigProvider.getConfig() - .getOptionalValue("quarkus.http.ssl-port", Integer.class) - .orElse(8443); - - combinedPort = new PortBuilder(combinedPort).withContainerPort(containerPort).build(); + // Special handling for ports with mapped configuration. We look up the container port from the Quarkus configuration. + if (combinedPort.getContainerPort() == null) { + for (Map.Entry portWithConfig : PORTS_WITH_CONFIG.entrySet()) { + if (portWithConfig.getKey().equals(name)) { + combinedPort = new PortBuilder(combinedPort) + .withContainerPort(portWithConfig.getValue().getPortFromConfig()) + .build(); + break; + } + } } allPorts.put(name, combinedPort); @@ -200,6 +209,23 @@ public static Map combinePorts(List ports return allPorts; } + /** + * Creates the configurator build items. + */ + public static void printMessageAboutPortsThatCantChange(String target, List ports, + PlatformConfiguration config) { + Collection allPorts = combinePorts(ports, config).values(); + for (Port port : allPorts) { + for (Map.Entry portWithConfig : PORTS_WITH_CONFIG.entrySet()) { + if (port.getName().equals(portWithConfig.getKey())) { + LOG.info(String.format("The target '%s' is mapping the container to the port '%s' which value is '%d'. " + + "You won't be able to change it at runtime using the property '%s'.", + target, port.getName(), port.getContainerPort(), portWithConfig.getValue().propertyName)); + } + } + } + } + /** * Creates the common decorator build items. */ @@ -1085,4 +1111,18 @@ private static List toPolicyRulesList(Map .build()) .collect(Collectors.toList()); } + + private static class PortProperty { + public String propertyName; + public int defaultPort; + + public PortProperty(String propertyName, int defaultPort) { + this.propertyName = propertyName; + this.defaultPort = defaultPort; + } + + public int getPortFromConfig() { + return ConfigProvider.getConfig().getOptionalValue(propertyName, Integer.class).orElse(defaultPort); + } + } } 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 50827d91246d65..02cf66652c0faf 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 @@ -9,6 +9,7 @@ import static io.quarkus.kubernetes.deployment.Constants.READINESS_PROBE; import static io.quarkus.kubernetes.deployment.Constants.ROUTE; import static io.quarkus.kubernetes.deployment.Constants.STARTUP_PROBE; +import static io.quarkus.kubernetes.deployment.KubernetesCommonHelper.printMessageAboutPortsThatCantChange; import static io.quarkus.kubernetes.deployment.KubernetesConfigUtil.MANAGEMENT_PORT_NAME; import static io.quarkus.kubernetes.deployment.KubernetesConfigUtil.managementPortIsEnabled; import static io.quarkus.kubernetes.deployment.OpenshiftConfig.OpenshiftFlavor.v3; @@ -378,6 +379,9 @@ public List createDecorators(ApplicationInfoBuildItem applic || !config.route.targetPort.equals(MANAGEMENT_PORT_NAME))) { result.add(new DecoratorBuildItem(OPENSHIFT, new RemovePortFromServiceDecorator(name, MANAGEMENT_PORT_NAME))); } + + printMessageAboutPortsThatCantChange(OPENSHIFT, ports, config); + return result; } 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 aa52dfb0f5da38..ceb7dc040614b4 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 @@ -8,6 +8,7 @@ import static io.quarkus.kubernetes.deployment.Constants.LIVENESS_PROBE; import static io.quarkus.kubernetes.deployment.Constants.READINESS_PROBE; import static io.quarkus.kubernetes.deployment.Constants.STARTUP_PROBE; +import static io.quarkus.kubernetes.deployment.KubernetesCommonHelper.printMessageAboutPortsThatCantChange; import static io.quarkus.kubernetes.deployment.KubernetesConfigUtil.MANAGEMENT_PORT_NAME; import static io.quarkus.kubernetes.deployment.KubernetesConfigUtil.managementPortIsEnabled; import static io.quarkus.kubernetes.spi.KubernetesDeploymentTargetBuildItem.VANILLA_KUBERNETES_PRIORITY; @@ -290,6 +291,8 @@ public List createDecorators(ApplicationInfoBuildItem applic result.add(new DecoratorBuildItem(KUBERNETES, new RemovePortFromServiceDecorator(name, MANAGEMENT_PORT_NAME))); } + printMessageAboutPortsThatCantChange(KUBERNETES, ports, config); + return result; }