diff --git a/extensions/kubernetes/openshift/deployment/src/test/java/io/quarkus/openshift/deployment/config/OpenshiftConfigFallbackTest.java b/extensions/kubernetes/openshift/deployment/src/test/java/io/quarkus/openshift/deployment/config/OpenshiftConfigFallbackTest.java index dabca1dacb383..0bb57f8311245 100644 --- a/extensions/kubernetes/openshift/deployment/src/test/java/io/quarkus/openshift/deployment/config/OpenshiftConfigFallbackTest.java +++ b/extensions/kubernetes/openshift/deployment/src/test/java/io/quarkus/openshift/deployment/config/OpenshiftConfigFallbackTest.java @@ -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; @@ -21,6 +28,8 @@ 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 @@ -28,6 +37,16 @@ public class OpenshiftConfigFallbackTest { @Test void configFallback() throws Exception { + List logRecords = prodModeTestResults.getRetainedBuildLogRecords(); + Set 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()); diff --git a/extensions/kubernetes/vanilla/runtime/src/main/java/io/quarkus/kubernetes/runtime/config/KubernetesConfigFallback.java b/extensions/kubernetes/vanilla/runtime/src/main/java/io/quarkus/kubernetes/runtime/config/KubernetesConfigFallback.java index c5d4d112e3b3b..9ee238563c076 100644 --- a/extensions/kubernetes/vanilla/runtime/src/main/java/io/quarkus/kubernetes/runtime/config/KubernetesConfigFallback.java +++ b/extensions/kubernetes/vanilla/runtime/src/main/java/io/quarkus/kubernetes/runtime/config/KubernetesConfigFallback.java @@ -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() { - @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 iterateNames(final ConfigSourceInterceptorContext context) { + return context.iterateNames(); + } + + private static class FallbackToKubernetesConfig implements Function { + @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; + } } }