From 9225ac71b3d3f0a02161fbc3c7acebee6c803756 Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 8 Feb 2023 10:39:52 +0100 Subject: [PATCH] Ignore unprefixed properties when the matching capability is not present Fix https://github.com/quarkusio/quarkus/issues/30850 --- .../deployment/KubernetesConfigUtil.java | 27 +++++++++++++++---- .../deployment/KubernetesProcessor.java | 2 +- 2 files changed, 23 insertions(+), 6 deletions(-) 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 085ac6b982be3..a420a890ac079 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 @@ -29,6 +29,8 @@ import org.jboss.logging.Logger; import io.dekorate.utils.Strings; +import io.quarkus.deployment.Capabilities; +import io.quarkus.deployment.Capability; public class KubernetesConfigUtil { @@ -36,8 +38,11 @@ public class KubernetesConfigUtil { private static final String QUARKUS_PREFIX = "quarkus."; private static final Pattern QUARKUS_DEPLOY_PATTERN = Pattern.compile("quarkus\\.([^\\.]+)\\.deploy"); - private static final Set ALLOWED_GENERATORS = new HashSet<>( - Arrays.asList(KUBERNETES, OPENSHIFT, KNATIVE, DOCKER, S2I)); + private static final Set ALLOWED_GENERATORS = Set.of(KUBERNETES, KNATIVE); + private static final Map ALLOWED_GENERATORS_BY_CAPABILITY = Map.of( + Capability.OPENSHIFT, OPENSHIFT, + Capability.CONTAINER_IMAGE_DOCKER, DOCKER, + Capability.CONTAINER_IMAGE_S2I, S2I); private static final String EXPOSE_PROPERTY_NAME = "expose"; private static final String[] EXPOSABLE_GENERATORS = { OPENSHIFT, KUBERNETES }; @@ -133,7 +138,7 @@ public static boolean isDeploymentEnabled() { * * @return A map containing the properties. */ - public static Map toMap(PlatformConfiguration... platformConfigurations) { + public static Map toMap(Capabilities capabilities, PlatformConfiguration... platformConfigurations) { Config config = ConfigProvider.getConfig(); Map result = new HashMap<>(); @@ -149,12 +154,13 @@ public static Map toMap(PlatformConfiguration... platformConfigu .ifPresent(v -> quarkusPrefixed.put(DEKORATE_PREFIX + p.getConfigName() + ".version", v)); }); + Set allowedGenerators = allowedGenerators(capabilities); Map unPrefixed = StreamSupport.stream(config.getPropertyNames().spliterator(), false) - .filter(k -> ALLOWED_GENERATORS.contains(generatorName(k))) + .filter(k -> allowedGenerators.contains(generatorName(k))) .filter(k -> config.getOptionalValue(k, String.class).isPresent()) .collect(Collectors.toMap(k -> DEKORATE_PREFIX + k, k -> config.getValue(k, String.class))); - for (String generator : ALLOWED_GENERATORS) { + for (String generator : allowedGenerators) { String oldKey = DEKORATE_PREFIX + generator + ".group"; String newKey = DEKORATE_PREFIX + generator + ".part-of"; if (unPrefixed.containsKey(oldKey)) { @@ -206,6 +212,17 @@ private static void handleExpose(Config config, Map unPrefixed, } } + private static Set allowedGenerators(Capabilities capabilities) { + Set generators = new HashSet<>(ALLOWED_GENERATORS); + for (Map.Entry optionalGenerator : ALLOWED_GENERATORS_BY_CAPABILITY.entrySet()) { + if (capabilities.isPresent(optionalGenerator.getKey())) { + generators.add(optionalGenerator.getValue()); + } + } + + return generators; + } + /** * Returns the name of the generators that can handle the specified key. * 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 ec65140a97419..cf174966c6605 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 @@ -127,7 +127,7 @@ public void build(ApplicationInfoBuildItem applicationInfo, throw new RuntimeException("Unable to setup environment for generating Kubernetes resources", e); } - Map config = KubernetesConfigUtil.toMap(kubernetesConfig, openshiftConfig, knativeConfig); + Map config = KubernetesConfigUtil.toMap(capabilities, kubernetesConfig, openshiftConfig, knativeConfig); Set deploymentTargets = kubernetesDeploymentTargets.getEntriesSortedByPriority().stream() .map(DeploymentTargetEntry::getName) .collect(Collectors.toSet());