Skip to content

Commit

Permalink
Remove deprecated Kubernetes/OpenShift properties
Browse files Browse the repository at this point in the history
This pull request removes the deprecated properties:
- `quarkus.kubernetes.expose` -> `quarkus.kubernetes.ingress.expose`
- `quarkus.openshift.expose` -> `quarkus.openshift.route.expose`
- `quarkus.kubernetes.host` -> `quarkus.kubernetes.ingress.host`
- `quarkus.openshift.host` -> `quarkus.openshift.route.host`
- `quarkus.kubernetes.group` -> `quarkus.kubernetes.part-of`
- `quarkus.openshift.group` -> `quarkus.openshift.part-of`

Plus, properties with a prefix won't be used anylonger. For example, before these changes we could add `kubernetes.name` and this property will be mapped to `quarkus.kubernetes.name`. After these changes, we're not going to do this anylonger, to avoid issues like quarkusio#30850.
  • Loading branch information
Sgitario committed Feb 8, 2023
1 parent 16e7260 commit cfe907e
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@
import static io.quarkus.deployment.builditem.ApplicationInfoBuildItem.UNSET_VALUE;
import static io.quarkus.kubernetes.deployment.Constants.DEPLOY;
import static io.quarkus.kubernetes.deployment.Constants.DEPLOYMENT_TARGET;
import static io.quarkus.kubernetes.deployment.Constants.DOCKER;
import static io.quarkus.kubernetes.deployment.Constants.KNATIVE;
import static io.quarkus.kubernetes.deployment.Constants.KUBERNETES;
import static io.quarkus.kubernetes.deployment.Constants.OPENSHIFT;
import static io.quarkus.kubernetes.deployment.Constants.S2I;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand All @@ -26,24 +21,12 @@

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;

import io.dekorate.utils.Strings;

public class KubernetesConfigUtil {

private static final String DEKORATE_PREFIX = "dekorate.";
private static final String QUARKUS_PREFIX = "quarkus.";
private static final Pattern QUARKUS_DEPLOY_PATTERN = Pattern.compile("quarkus\\.([^\\.]+)\\.deploy");

private static final Set<String> ALLOWED_GENERATORS = new HashSet<>(
Arrays.asList(KUBERNETES, OPENSHIFT, KNATIVE, DOCKER, S2I));

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);

/**
* Get the explicit configured deployment target, if any.
* The explicit deployment target is determined using: `quarkus.kubernetes.deployment-target=<deployment-target>`
Expand All @@ -63,7 +46,7 @@ public static List<String> getExplictilyDeploymentTargets() {
return Collections.emptyList();
}
return Arrays.stream(deploymentTargets
.split(","))
.split(Pattern.quote(",")))
.map(String::trim)
.map(String::toLowerCase)
.collect(Collectors.toList());
Expand Down Expand Up @@ -134,7 +117,6 @@ public static boolean isDeploymentEnabled() {
* @return A map containing the properties.
*/
public static Map<String, Object> toMap(PlatformConfiguration... platformConfigurations) {
Config config = ConfigProvider.getConfig();
Map<String, Object> result = new HashMap<>();

// Most of quarkus prefixed properties are handled directly by the config items (KubernetesConfig, OpenshiftConfig, KnativeConfig)
Expand All @@ -149,76 +131,11 @@ public static Map<String, Object> toMap(PlatformConfiguration... platformConfigu
.ifPresent(v -> quarkusPrefixed.put(DEKORATE_PREFIX + p.getConfigName() + ".version", v));
});

Map<String, Object> unPrefixed = StreamSupport.stream(config.getPropertyNames().spliterator(), false)
.filter(k -> ALLOWED_GENERATORS.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) {
String oldKey = DEKORATE_PREFIX + generator + ".group";
String newKey = DEKORATE_PREFIX + generator + ".part-of";
if (unPrefixed.containsKey(oldKey)) {
unPrefixed.put(newKey, unPrefixed.get(oldKey));
}
}

handleExpose(config, unPrefixed, platformConfigurations);

result.putAll(unPrefixed);
result.putAll(quarkusPrefixed);
result.putAll(toS2iProperties(quarkusPrefixed));
return result;
}

@Deprecated
private static void handleExpose(Config config, Map<String, Object> unPrefixed,
PlatformConfiguration... platformConfigurations) {
for (String generator : EXPOSABLE_GENERATORS) {
boolean unprefixedExpose = config.getOptionalValue(generator + "." + EXPOSE_PROPERTY_NAME, Boolean.class)
.orElse(false);
boolean prefixedExpose = config
.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);
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;
}
}
}
}
}

/**
* Returns the name of the generators that can handle the specified key.
*
* @param key The key.
* @return The generator name or null if the key format is unexpected.
*/
private static String generatorName(String key) {
if (Strings.isNullOrEmpty(key) || !key.contains(".")) {
return null;
}
return key.substring(0, key.indexOf("."));
}

private static Map<String, Object> toS2iProperties(Map<String, Object> map) {
Map<String, Object> result = new HashMap<>();
map.forEach((k, v) -> {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
quarkus.openshift.expose=true
quarkus.openshift.route.expose=true
quarkus.s2i.base-jvm-image=my.registry.example/openjdk/openjdk-11-rhel7
quarkus.openshift.containers.sc.image=quay.io/sidecar/image:2.1
quarkus.openshift.containers.sc.image-pull-policy=IfNotPresent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
quarkus.openshift.expose=true
quarkus.openshift.route.expose=true
quarkus.s2i.base-jvm-image=my.registry.example/openjdk/openjdk-11-rhel7
quarkus.s2i.jvm-arguments=-Djava.util.logging.manager=org.jboss.logmanager.LogManager
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
quarkus.openshift.expose=true
quarkus.openshift.route.expose=true
quarkus.s2i.base-jvm-image=my.registry.example/openjdk/openjdk-11-rhel7
quarkus.openshift.sidecars.sc.image=quay.io/sidecar/image:2.1
quarkus.openshift.sidecars.sc.image-pull-policy=IfNotPresent
Expand Down

0 comments on commit cfe907e

Please sign in to comment.