Skip to content

Commit

Permalink
Do not include in the list of property names Kubernetes config fallbacks
Browse files Browse the repository at this point in the history
(cherry picked from commit 31e7755)
  • Loading branch information
radcortez authored and gsmet committed Sep 13, 2023
1 parent 032a9ec commit e55991b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package io.quarkus.openshift.deployment.config;

import static java.util.stream.Collectors.toSet;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.LogRecord;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand All @@ -21,13 +28,25 @@ public class OpenshiftConfigFallbackTest {
.overrideConfigKey("quarkus.kubernetes.replicas", "10")
.overrideConfigKey("quarkus.openshift.version", "999-SNAPSHOT")
.overrideConfigKey("quarkus.openshift.labels.app", "openshift")
.overrideConfigKey("quarkus.openshift.route.expose", "true")
.setLogRecordPredicate(record -> record.getLevel().intValue() >= Level.WARNING.intValue())
.setRun(true);

@ProdBuildResults
private ProdModeTestResults prodModeTestResults;

@Test
void configFallback() throws Exception {
List<LogRecord> logRecords = prodModeTestResults.getRetainedBuildLogRecords();
Set<Object> unrecognized = logRecords.stream()
.filter(logRecord -> logRecord.getMessage().startsWith("Unrecognized configuration key"))
.map(logRecord -> Optional.ofNullable(logRecord.getParameters())
.map(parameters -> parameters[0])
.orElse(new Object[0]))
.collect(toSet());

assertTrue(unrecognized.isEmpty());

Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
YamlConfigSource kubernetes = new YamlConfigSource(kubernetesDir.resolve("kubernetes.yml").toUri().toURL());
YamlConfigSource openshift = new YamlConfigSource(kubernetesDir.resolve("openshift.yml").toUri().toURL());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
package io.quarkus.kubernetes.runtime.config;

import java.util.Iterator;
import java.util.function.Function;

import io.smallrye.config.ConfigSourceInterceptorContext;
import io.smallrye.config.FallbackConfigSourceInterceptor;

public class KubernetesConfigFallback extends FallbackConfigSourceInterceptor {
private static final String QUARKUS_KUBERNETES_CONFIG_PREFIX = "quarkus.kubernetes.";
private static final String QUARKUS_OPENSHIFT_CONFIG_PREFIX = "quarkus.openshift.";
private static final int OPENSHIFT_CONFIG_NAME_BEGIN = QUARKUS_OPENSHIFT_CONFIG_PREFIX.length();
private static final String QUARKUS_KNATIVE_CONFIG_PREFIX = "quarkus.knative.";
private static final int KNATIVE_CONFIG_NAME_BEGIN = QUARKUS_KNATIVE_CONFIG_PREFIX.length();

public KubernetesConfigFallback() {
super(new Function<String, String>() {
@Override
public String apply(final String name) {
if (name.startsWith(QUARKUS_OPENSHIFT_CONFIG_PREFIX)) {
return QUARKUS_KUBERNETES_CONFIG_PREFIX + name.substring(OPENSHIFT_CONFIG_NAME_BEGIN);
} else if (name.startsWith(QUARKUS_KNATIVE_CONFIG_PREFIX)) {
return QUARKUS_KUBERNETES_CONFIG_PREFIX + name.substring(KNATIVE_CONFIG_NAME_BEGIN);
}
return name;
super(new FallbackToKubernetesConfig());
}

@Override
public Iterator<String> iterateNames(final ConfigSourceInterceptorContext context) {
return context.iterateNames();
}

private static class FallbackToKubernetesConfig implements Function<String, String> {
@Override
public String apply(final String name) {
if (name.startsWith("quarkus.openshift.")) {
return "quarkus.kubernetes." + name.substring(18);
} else if (name.startsWith("quarkus.knative.")) {
return "quarkus.kubernetes." + name.substring(16);
}
});
return name;
}
}
}

0 comments on commit e55991b

Please sign in to comment.