Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not include in the list of property names Kubernetes config fallbacks #35792

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}
Loading