diff --git a/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientSecretsPropertySource.java b/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientSecretsPropertySource.java index 642386f604..bac7a39fe5 100644 --- a/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientSecretsPropertySource.java +++ b/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientSecretsPropertySource.java @@ -29,6 +29,7 @@ */ public class KubernetesClientSecretsPropertySource extends SecretsPropertySource { + @Deprecated(forRemoval = true) public KubernetesClientSecretsPropertySource(SourceData sourceData) { super(sourceData); } diff --git a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/src/main/java/org/springframework/cloud/kubernetes/configserver/KubernetesEnvironmentRepository.java b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/src/main/java/org/springframework/cloud/kubernetes/configserver/KubernetesEnvironmentRepository.java index 3c25e7f91b..aa377751d4 100644 --- a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/src/main/java/org/springframework/cloud/kubernetes/configserver/KubernetesEnvironmentRepository.java +++ b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/src/main/java/org/springframework/cloud/kubernetes/configserver/KubernetesEnvironmentRepository.java @@ -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; @@ -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 kubernetesPropertySourceSuppliers; + private final List kubernetesPropertySourceSuppliers; - private String namespace; + private final String namespace; public KubernetesEnvironmentRepository(CoreV1Api coreApi, List kubernetesPropertySourceSuppliers, String namespace) { @@ -64,8 +63,7 @@ public Environment findOne(String application, String profile, String label, boo if (!StringUtils.hasText(profile)) { profile = "default"; } - List profiles = new java.util.ArrayList<>( - Arrays.stream(StringUtils.commaDelimitedListToStringArray(profile)).toList()); + List profiles = new ArrayList<>(List.of(StringUtils.commaDelimitedListToStringArray(profile))); Collections.reverse(profiles); if (!profiles.contains("default")) { @@ -98,8 +96,7 @@ public Environment findOne(String application, String profile, String label, boo } private MutablePropertySources createPropertySources(String application) { - Map applicationProperties = new HashMap<>(); - applicationProperties.put("spring.application.name", application); + Map applicationProperties = Map.of("spring.application.name", application); MapPropertySource propertySource = new MapPropertySource("kubernetes-config-server", applicationProperties); MutablePropertySources mutablePropertySources = new MutablePropertySources(); mutablePropertySources.addFirst(propertySource); @@ -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 propertySources = supplier.get(coreApi, applicationName, namespace, springEnv); propertySources.forEach(propertySource -> { if (propertySource.getPropertyNames().length > 0) { diff --git a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/src/main/java/org/springframework/cloud/kubernetes/configserver/KubernetesPropertySourceSupplier.java b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/src/main/java/org/springframework/cloud/kubernetes/configserver/KubernetesPropertySourceSupplier.java index a73af430dd..e2973ac2e6 100644 --- a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/src/main/java/org/springframework/cloud/kubernetes/configserver/KubernetesPropertySourceSupplier.java +++ b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/src/main/java/org/springframework/cloud/kubernetes/configserver/KubernetesPropertySourceSupplier.java @@ -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; @@ -33,11 +31,18 @@ public interface KubernetesPropertySourceSupplier { List 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 namespaceSplitter(String namespacesString, String currentNamespace) { - List namespaces = Collections.singletonList(currentNamespace); + List namespaces = List.of(currentNamespace); String[] namespacesArray = StringUtils.commaDelimitedListToStringArray(namespacesString); if (namespacesArray.length > 0) { - namespaces = Arrays.asList(namespacesArray); + namespaces = List.of(namespacesArray); } return namespaces; }