From 67783aefb5d5f9ffb9a635c068a497fc25ae728b Mon Sep 17 00:00:00 2001 From: yuvarajsanjeevi <41108987+yuvarajsanjeevi@users.noreply.github.com> Date: Fri, 10 Apr 2020 17:50:03 +0300 Subject: [PATCH 1/2] Remove extra space (#549) Spring factories failing to load the class because of extra spaces --- .../src/main/resources/META-INF/spring.factories | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-kubernetes-core/src/main/resources/META-INF/spring.factories b/spring-cloud-kubernetes-core/src/main/resources/META-INF/spring.factories index 9d0f344c..47252386 100644 --- a/spring-cloud-kubernetes-core/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-kubernetes-core/src/main/resources/META-INF/spring.factories @@ -3,4 +3,4 @@ org.springframework.cloud.kubernetes.KubernetesAutoConfiguration\ org.springframework.boot.env.EnvironmentPostProcessor=\ -org.springframework.cloud.kubernetes.profile.KubernetesProfileEnvironmentPostProcessor +org.springframework.cloud.kubernetes.profile.KubernetesProfileEnvironmentPostProcessor From 5a28981faf00f4eabcb93f11a947651ec659808c Mon Sep 17 00:00:00 2001 From: Yuusaku Taniguchi Date: Mon, 20 Apr 2020 23:59:16 +0900 Subject: [PATCH 2/2] Close the connection of ad hoc kubernetes client (#550) --- .../KubernetesProfileEnvironmentPostProcessor.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/spring-cloud-kubernetes-core/src/main/java/org/springframework/cloud/kubernetes/profile/KubernetesProfileEnvironmentPostProcessor.java b/spring-cloud-kubernetes-core/src/main/java/org/springframework/cloud/kubernetes/profile/KubernetesProfileEnvironmentPostProcessor.java index a8f8cf47..e2402e14 100644 --- a/spring-cloud-kubernetes-core/src/main/java/org/springframework/cloud/kubernetes/profile/KubernetesProfileEnvironmentPostProcessor.java +++ b/spring-cloud-kubernetes-core/src/main/java/org/springframework/cloud/kubernetes/profile/KubernetesProfileEnvironmentPostProcessor.java @@ -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)) {