Skip to content

Commit

Permalink
Close the connection of ad hoc kubernetes client (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuusaku-t committed Apr 20, 2020
1 parent 67783ae commit 5a28981
Showing 1 changed file with 8 additions and 3 deletions.
Expand Up @@ -49,9 +49,7 @@ public void postProcessEnvironment(ConfigurableEnvironment environment,
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");
Expand All @@ -72,6 +70,13 @@ public void postProcessEnvironment(ConfigurableEnvironment environment,
}
}

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)) {
Expand Down

0 comments on commit 5a28981

Please sign in to comment.