Skip to content
Closed
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
Expand Up @@ -22,6 +22,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
Expand Down Expand Up @@ -120,7 +121,7 @@ private void addPropertySourcesFromPaths(Environment environment, CompositePrope
}).toList().forEach(p -> {
try {
String content = new String(Files.readAllBytes(p)).trim();
String filename = p.toAbsolutePath().toString().toLowerCase();
String filename = p.toAbsolutePath().toString().toLowerCase(Locale.ROOT);
if (filename.endsWith(".properties")) {
addPropertySourceIfNeeded(c -> PROPERTIES_TO_MAP.apply(KEY_VALUE_TO_PROPERTIES.apply(c)), content,
filename, composite);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import org.springframework.boot.BootstrapRegistry;
import org.springframework.boot.ConfigurableBootstrapContext;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.Environment;
import org.springframework.core.style.ToStringCreator;
import org.springframework.util.CollectionUtils;
Expand Down Expand Up @@ -329,17 +330,23 @@ private static Map<String, String> decodeData(Map<String, String> data) {
}

public static <T> void registerSingle(ConfigurableBootstrapContext bootstrapContext, Class<T> cls, T instance,
String name) {
String name, ApplicationListener<?> listener) {
bootstrapContext.registerIfAbsent(cls, BootstrapRegistry.InstanceSupplier.of(instance));
bootstrapContext.addCloseListener(event -> {
if (event.getApplicationContext().getBeanFactory().getSingleton(name) == null) {
event.getApplicationContext()
.getBeanFactory()
.registerSingleton(name, event.getBootstrapContext().get(cls));
event.getApplicationContext().addApplicationListener(listener);
}
});
}

public static <T> void registerSingle(ConfigurableBootstrapContext bootstrapContext, Class<T> cls, T instance,
String name) {
registerSingle(bootstrapContext, cls, instance, name, event -> {});
}

/**
* append prefix to the keys and return a new Map with the new values.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiConsumer;
Expand Down Expand Up @@ -177,7 +178,7 @@ private SecretsPropertySource property(Path filePath) {

try {
String content = new String(Files.readAllBytes(filePath)).trim();
String sourceName = fileName.toLowerCase();
String sourceName = fileName.toLowerCase(Locale.ROOT);
SourceData sourceData = new SourceData(sourceName, Collections.singletonMap(fileName, content));
return new SecretsPropertySource(sourceData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.springframework.cloud.kubernetes.commons.config.SecretsConfigProperties;
import org.springframework.cloud.kubernetes.commons.config.SecretsPropertySourceLocator;
import org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.core.env.Environment;

import static org.springframework.cloud.kubernetes.commons.config.ConfigUtils.registerSingle;
Expand Down Expand Up @@ -85,12 +87,14 @@ protected void registerBeans(ConfigDataLocationResolverContext resolverContext,
}

private KubernetesClient registerConfigAndClient(ConfigurableBootstrapContext bootstrapContext,
KubernetesClientProperties kubernetesClientProperties) {
KubernetesClientProperties kubernetesClientProperties) {
Config config = new Fabric8AutoConfiguration().kubernetesClientConfig(kubernetesClientProperties);
registerSingle(bootstrapContext, Config.class, config, "fabric8Config");

KubernetesClient kubernetesClient = new Fabric8AutoConfiguration().kubernetesClient(config);
registerSingle(bootstrapContext, KubernetesClient.class, kubernetesClient, "configKubernetesClient");
registerSingle(bootstrapContext, KubernetesClient.class, kubernetesClient, "configKubernetesClient", (ApplicationListener<ContextClosedEvent>) event -> {
kubernetesClient.close();
});
return kubernetesClient;
}

Expand Down
Loading