some improvements (#621)

* some improvments

* correct keys
This commit is contained in:
erabii
2020-09-29 17:02:15 -04:00
committed by GitHub
parent 0059aeb946
commit 2c863aee0f
2 changed files with 31 additions and 38 deletions

View File

@@ -39,35 +39,31 @@ public final class ConfigUtils {
throw new IllegalStateException("Can't instantiate a utility class");
}
public static <C extends AbstractConfigProperties> 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 <C extends AbstractConfigProperties> 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;
}
}

View File

@@ -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<String, String>() {
{
put("bean.common-message", "c1");
put("bean.message1", "m1");
}
});
Map<String, String> one = new HashMap<>();
one.put("bean.common-message", "c1");
one.put("bean.message1", "m1");
createConfigmap(server, "defname", "s2", new HashMap<String, String>() {
{
put("bean.common-message", "c2");
put("bean.message2", "m2");
}
});
createConfigmap(server, "s1", "defnamespace", one);
createConfigmap(server, "othername", "othernamespace", new HashMap<String, String>() {
{
put("bean.common-message", "c3");
put("bean.message3", "m3");
}
});
Map<String, String> two = new HashMap<>();
two.put("bean.common-message", "c2");
two.put("bean.message2", "m2");
createConfigmap(server, "defname", "s2", two);
Map<String, String> 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,