Skip to content

Commit

Permalink
simplification in config server (#1614)
Browse files Browse the repository at this point in the history
  • Loading branch information
wind57 authored Mar 28, 2024
1 parent cb3d7ca commit 470ab67
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/
public class KubernetesClientSecretsPropertySource extends SecretsPropertySource {

@Deprecated(forRemoval = true)
public KubernetesClientSecretsPropertySource(SourceData sourceData) {
super(sourceData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

package org.springframework.cloud.kubernetes.configserver;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -41,11 +40,11 @@ public class KubernetesEnvironmentRepository implements EnvironmentRepository {

private static final Log LOG = LogFactory.getLog(KubernetesEnvironmentRepository.class);

private CoreV1Api coreApi;
private final CoreV1Api coreApi;

private List<KubernetesPropertySourceSupplier> kubernetesPropertySourceSuppliers;
private final List<KubernetesPropertySourceSupplier> kubernetesPropertySourceSuppliers;

private String namespace;
private final String namespace;

public KubernetesEnvironmentRepository(CoreV1Api coreApi,
List<KubernetesPropertySourceSupplier> kubernetesPropertySourceSuppliers, String namespace) {
Expand All @@ -64,8 +63,7 @@ public Environment findOne(String application, String profile, String label, boo
if (!StringUtils.hasText(profile)) {
profile = "default";
}
List<String> profiles = new java.util.ArrayList<>(
Arrays.stream(StringUtils.commaDelimitedListToStringArray(profile)).toList());
List<String> profiles = new ArrayList<>(List.of(StringUtils.commaDelimitedListToStringArray(profile)));

Collections.reverse(profiles);
if (!profiles.contains("default")) {
Expand Down Expand Up @@ -98,8 +96,7 @@ public Environment findOne(String application, String profile, String label, boo
}

private MutablePropertySources createPropertySources(String application) {
Map<String, Object> applicationProperties = new HashMap<>();
applicationProperties.put("spring.application.name", application);
Map<String, Object> applicationProperties = Map.of("spring.application.name", application);
MapPropertySource propertySource = new MapPropertySource("kubernetes-config-server", applicationProperties);
MutablePropertySources mutablePropertySources = new MutablePropertySources();
mutablePropertySources.addFirst(propertySource);
Expand All @@ -108,7 +105,7 @@ private MutablePropertySources createPropertySources(String application) {

private void addApplicationConfiguration(Environment environment, StandardEnvironment springEnv,
String applicationName) {
kubernetesPropertySourceSuppliers.stream().forEach(supplier -> {
kubernetesPropertySourceSuppliers.forEach(supplier -> {
List<MapPropertySource> propertySources = supplier.get(coreApi, applicationName, namespace, springEnv);
propertySources.forEach(propertySource -> {
if (propertySource.getPropertyNames().length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package org.springframework.cloud.kubernetes.configserver;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import io.kubernetes.client.openapi.apis.CoreV1Api;
Expand All @@ -33,11 +31,18 @@ public interface KubernetesPropertySourceSupplier {

List<MapPropertySource> get(CoreV1Api coreV1Api, String name, String namespace, Environment environment);

/*
* return either a List containing 'currentNamespace' (if 'namespacesString' is empty
* or null), or a List of comma delimited tokens (namespaces) from 'namespacesString'.
*
* 'currentNamespace' can be treated logically as the "default namespace" to use, if
* the other argument is not provided.
*/
static List<String> namespaceSplitter(String namespacesString, String currentNamespace) {
List<String> namespaces = Collections.singletonList(currentNamespace);
List<String> namespaces = List.of(currentNamespace);
String[] namespacesArray = StringUtils.commaDelimitedListToStringArray(namespacesString);
if (namespacesArray.length > 0) {
namespaces = Arrays.asList(namespacesArray);
namespaces = List.of(namespacesArray);
}
return namespaces;
}
Expand Down

0 comments on commit 470ab67

Please sign in to comment.