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 085ac6b982be35..a420a890ac0798 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 ec65140a97419e..cf174966c66057 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());