Close the connection of ad hoc kubernetes client
@@ -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)) {
