Close the connection of ad hoc kubernetes client (#550)

This commit is contained in:
Yuusaku Taniguchi
2020-04-20 23:59:16 +09:00
committed by GitHub
parent 67783aefb5
commit 5a28981faf

View File

@@ -49,9 +49,7 @@ public class KubernetesProfileEnvironmentPostProcessor
return;
}
final StandardPodUtils podUtils = new StandardPodUtils(
new DefaultKubernetesClient());
if (podUtils.isInsideKubernetes()) {
if (isInsideKubernetes()) {
if (hasKubernetesProfile(environment)) {
if (LOG.isDebugEnabled()) {
LOG.debug("'kubernetes' already in list of active profiles");
@@ -72,6 +70,13 @@ public class KubernetesProfileEnvironmentPostProcessor
}
}
private boolean isInsideKubernetes() {
try (DefaultKubernetesClient client = new DefaultKubernetesClient()) {
final StandardPodUtils podUtils = new StandardPodUtils(client);
return podUtils.isInsideKubernetes();
}
}
private boolean hasKubernetesProfile(Environment environment) {
for (String activeProfile : environment.getActiveProfiles()) {
if (KUBERNETES_PROFILE.equalsIgnoreCase(activeProfile)) {