diff --git a/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/ConfigUtils.java b/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/ConfigUtils.java index f867b092..0bfe37d3 100644 --- a/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/ConfigUtils.java +++ b/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/ConfigUtils.java @@ -39,35 +39,31 @@ public final class ConfigUtils { throw new IllegalStateException("Can't instantiate a utility class"); } - public static String getApplicationName(Environment env, String configName, + public static String getApplicationName(Environment env, String configName, String configurationTarget) { - String name = configName; - if (StringUtils.isEmpty(name)) { + if (StringUtils.isEmpty(configName)) { // TODO: use relaxed binding - if (LOG.isDebugEnabled()) { - LOG.debug(configurationTarget + " name has not been set, taking it from property/env " - + SPRING_APPLICATION_NAME + " (default=" + FALLBACK_APPLICATION_NAME + ")"); - } - - name = env.getProperty(SPRING_APPLICATION_NAME, FALLBACK_APPLICATION_NAME); + LOG.debug(configurationTarget + + " name has not been set, taking it from property/env " + + SPRING_APPLICATION_NAME + " (default=" + FALLBACK_APPLICATION_NAME + + ")"); + configName = env.getProperty(SPRING_APPLICATION_NAME, + FALLBACK_APPLICATION_NAME); } - return name; + return configName; } - public static String getApplicationNamespace(KubernetesClient client, + public static String getApplicationNamespace(KubernetesClient client, String configNamespace, String configurationTarget) { - String namespace = configNamespace; - if (StringUtils.isEmpty(namespace)) { - if (LOG.isDebugEnabled()) { - LOG.debug(configurationTarget + " namespace has not been set, taking it from client (ns=" - + client.getNamespace() + ")"); - } - - namespace = client.getNamespace(); + if (StringUtils.isEmpty(configNamespace)) { + LOG.debug(configurationTarget + + " namespace has not been set, taking it from client (ns=" + + client.getNamespace() + ")"); + configNamespace = client.getNamespace(); } - return namespace; + return configNamespace; } } diff --git a/spring-cloud-kubernetes-config/src/test/java/org/springframework/cloud/kubernetes/config/MultipleConfigMapsTests.java b/spring-cloud-kubernetes-config/src/test/java/org/springframework/cloud/kubernetes/config/MultipleConfigMapsTests.java index da10be77..9e452242 100644 --- a/spring-cloud-kubernetes-config/src/test/java/org/springframework/cloud/kubernetes/config/MultipleConfigMapsTests.java +++ b/spring-cloud-kubernetes-config/src/test/java/org/springframework/cloud/kubernetes/config/MultipleConfigMapsTests.java @@ -64,26 +64,23 @@ public class MultipleConfigMapsTests { System.setProperty(Config.KUBERNETES_NAMESPACE_SYSTEM_PROPERTY, "test"); System.setProperty(Config.KUBERNETES_HTTP2_DISABLE, "true"); - createConfigmap(server, "s1", "defnamespace", new HashMap() { - { - put("bean.common-message", "c1"); - put("bean.message1", "m1"); - } - }); + Map one = new HashMap<>(); + one.put("bean.common-message", "c1"); + one.put("bean.message1", "m1"); - createConfigmap(server, "defname", "s2", new HashMap() { - { - put("bean.common-message", "c2"); - put("bean.message2", "m2"); - } - }); + createConfigmap(server, "s1", "defnamespace", one); - createConfigmap(server, "othername", "othernamespace", new HashMap() { - { - put("bean.common-message", "c3"); - put("bean.message3", "m3"); - } - }); + Map two = new HashMap<>(); + two.put("bean.common-message", "c2"); + two.put("bean.message2", "m2"); + + createConfigmap(server, "defname", "s2", two); + + Map three = new HashMap<>(); + three.put("bean.common-message", "c3"); + three.put("bean.message3", "m3"); + + createConfigmap(server, "othername", "othernamespace", three); } private static void createConfigmap(KubernetesServer server, String configMapName, String namespace,