From 0637e96529667182bf2554f1c4b495a93b4b47dd Mon Sep 17 00:00:00 2001 From: erabii Date: Tue, 13 Jul 2021 10:44:43 -0400 Subject: [PATCH 1/5] fix (#816) * fix --- .../commons/config/ConfigMapConfigProperties.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapConfigProperties.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapConfigProperties.java index 4cb0377e..fed95bfa 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapConfigProperties.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapConfigProperties.java @@ -71,11 +71,10 @@ public class ConfigMapConfigProperties extends AbstractConfigProperties { */ public List determineSources() { if (this.sources.isEmpty()) { - return Collections.singletonList(new NormalizedSource(ConfigMapConfigProperties.this.name, - ConfigMapConfigProperties.this.namespace)); + return Collections.singletonList(new NormalizedSource(name, namespace)); } - return this.sources.stream().map(s -> s.normalize(this.name, this.namespace)).collect(Collectors.toList()); + return sources.stream().map(s -> s.normalize(name, namespace)).collect(Collectors.toList()); } @Override @@ -99,6 +98,7 @@ public class ConfigMapConfigProperties extends AbstractConfigProperties { private String namespace; public Source() { + } public Source(String name, String namespace) { @@ -129,7 +129,6 @@ public class ConfigMapConfigProperties extends AbstractConfigProperties { public NormalizedSource normalize(String defaultName, String defaultNamespace) { String normalizedName = StringUtils.hasLength(this.name) ? this.name : defaultName; String normalizedNamespace = StringUtils.hasLength(this.namespace) ? this.namespace : defaultNamespace; - return new NormalizedSource(normalizedName, normalizedNamespace); } From b380f463a533f476aa40b6d18f5522cae1fccba0 Mon Sep 17 00:00:00 2001 From: erabii Date: Tue, 13 Jul 2021 13:56:02 -0400 Subject: [PATCH 2/5] fix 825 (#829) --- .../fabric8/Fabric8ActuatorConfiguration.java | 50 ++++++++++ .../fabric8/Fabric8AutoConfiguration.java | 24 ----- .../main/resources/META-INF/spring.factories | 4 +- .../fabric8/config/Fabric8ActuatorTests.java | 93 +++++++++++++++++++ 4 files changed, 145 insertions(+), 26 deletions(-) create mode 100644 spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8ActuatorConfiguration.java create mode 100644 spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ActuatorTests.java diff --git a/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8ActuatorConfiguration.java b/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8ActuatorConfiguration.java new file mode 100644 index 00000000..befd6725 --- /dev/null +++ b/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8ActuatorConfiguration.java @@ -0,0 +1,50 @@ +/* + * Copyright 2013-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.kubernetes.fabric8; + +import io.fabric8.kubernetes.api.model.Pod; + +import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; +import org.springframework.boot.actuate.autoconfigure.info.ConditionalOnEnabledInfoContributor; +import org.springframework.boot.actuate.health.HealthIndicator; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled; +import org.springframework.cloud.kubernetes.commons.PodUtils; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author wind57 + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnClass(HealthIndicator.class) +@ConditionalOnKubernetesEnabled +public class Fabric8ActuatorConfiguration { + + @Bean + @ConditionalOnEnabledHealthIndicator("kubernetes") + public Fabric8HealthIndicator kubernetesHealthIndicator(PodUtils podUtils) { + return new Fabric8HealthIndicator(podUtils); + } + + @Bean + @ConditionalOnEnabledInfoContributor("kubernetes") + public Fabric8InfoContributor kubernetesInfoContributor(PodUtils podUtils) { + return new Fabric8InfoContributor(podUtils); + } + +} diff --git a/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8AutoConfiguration.java b/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8AutoConfiguration.java index 06d255bd..722b5e8b 100644 --- a/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8AutoConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8AutoConfiguration.java @@ -18,7 +18,6 @@ package org.springframework.cloud.kubernetes.fabric8; import java.time.Duration; -import io.fabric8.kubernetes.api.model.Pod; import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.ConfigBuilder; import io.fabric8.kubernetes.client.DefaultKubernetesClient; @@ -26,16 +25,11 @@ import io.fabric8.kubernetes.client.KubernetesClient; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; -import org.springframework.boot.actuate.autoconfigure.info.ConditionalOnEnabledInfoContributor; -import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled; import org.springframework.cloud.kubernetes.commons.KubernetesClientProperties; import org.springframework.cloud.kubernetes.commons.KubernetesCommonsAutoConfiguration; -import org.springframework.cloud.kubernetes.commons.PodUtils; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -123,22 +117,4 @@ public class Fabric8AutoConfiguration { return new Fabric8PodUtils(client); } - @Configuration(proxyBeanMethods = false) - @ConditionalOnClass(HealthIndicator.class) - protected static class KubernetesActuatorConfiguration { - - @Bean - @ConditionalOnEnabledHealthIndicator("kubernetes") - public Fabric8HealthIndicator kubernetesHealthIndicator(PodUtils podUtils) { - return new Fabric8HealthIndicator(podUtils); - } - - @Bean - @ConditionalOnEnabledInfoContributor("kubernetes") - public Fabric8InfoContributor kubernetesInfoContributor(PodUtils podUtils) { - return new Fabric8InfoContributor(podUtils); - } - - } - } diff --git a/spring-cloud-kubernetes-fabric8-autoconfig/src/main/resources/META-INF/spring.factories b/spring-cloud-kubernetes-fabric8-autoconfig/src/main/resources/META-INF/spring.factories index dd3eef52..ea4ff164 100644 --- a/spring-cloud-kubernetes-fabric8-autoconfig/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-kubernetes-fabric8-autoconfig/src/main/resources/META-INF/spring.factories @@ -1,6 +1,6 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration\ - +org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration,\ +org.springframework.cloud.kubernetes.fabric8.Fabric8ActuatorConfiguration org.springframework.boot.env.EnvironmentPostProcessor=\ org.springframework.cloud.kubernetes.fabric8.profile.Fabric8ProfileEnvironmentPostProcessor diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ActuatorTests.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ActuatorTests.java new file mode 100644 index 00000000..d564d4c4 --- /dev/null +++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ActuatorTests.java @@ -0,0 +1,93 @@ +/* + * Copyright 2013-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.kubernetes.fabric8.config; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.actuate.health.ReactiveHealthContributorRegistry; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.kubernetes.fabric8.config.example.App; +import org.springframework.http.MediaType; +import org.springframework.test.web.reactive.server.WebTestClient; + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.not; + +/** + * @author wind57 + */ +public class Fabric8ActuatorTests { + + @Nested + @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = { + "management.health.kubernetes.enabled=false", "management.endpoint.health.show-details=always", + "management.endpoint.health.show-components=always", "management.endpoints.web.exposure.include=health" }) + public class DisabledHealthTest { + + @Autowired + private ReactiveHealthContributorRegistry registry; + + @Autowired + private WebTestClient webClient; + + @Value("${local.server.port}") + private int port; + + @Test + public void healthEndpointShouldContainKubernetes() { + this.webClient.get().uri("http://localhost:{port}/actuator/health", this.port) + .accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody(String.class) + .value(not(containsString("kubernetes"))); + + Assertions.assertNull(registry.getContributor("kubernetes"), + "reactive kubernetes contributor must NOT be present when 'management.health.kubernetes.enabled=false'"); + } + + } + + @Nested + @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = { + "management.health.kubernetes.enabled=true", "management.endpoint.health.show-details=always", + "management.endpoint.health.show-components=always", "management.endpoints.web.exposure.include=health" }) + public class EnabledHealthTest { + + @Autowired + private WebTestClient webClient; + + @Autowired + private ReactiveHealthContributorRegistry registry; + + @Value("${local.server.port}") + private int port; + + @Test + public void healthEndpointShouldContainKubernetes() { + this.webClient.get().uri("http://localhost:{port}/actuator/health", this.port) + .accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody(String.class) + .value(containsString("kubernetes")); + + Assertions.assertNotNull(registry.getContributor("kubernetes"), + "reactive kubernetes contributor must be present when 'management.health.kubernetes.enabled=true'"); + } + + } + +} From 231fc9f70c50aa95514f37623f05261eb0fc8c94 Mon Sep 17 00:00:00 2001 From: erabii Date: Tue, 13 Jul 2021 13:57:31 -0400 Subject: [PATCH 3/5] backport 825 (#830) * backport 825 * backport 825 : fix tests * backport 825 : fix checkstyle --- .../pom.xml | 5 + ...KubernetesClientActuatorConfiguration.java | 50 ++++++++++ .../KubernetesClientAutoConfiguration.java | 24 ----- .../main/resources/META-INF/spring.factories | 3 +- .../client/KubernetesClientActuatorTests.java | 91 +++++++++++++++++++ ...ubernetesClientBootstrapConfiguration.java | 36 +++----- 6 files changed, 163 insertions(+), 46 deletions(-) create mode 100644 spring-cloud-kubernetes-client-autoconfig/src/main/java/org/springframework/cloud/kubernetes/client/KubernetesClientActuatorConfiguration.java create mode 100644 spring-cloud-kubernetes-client-autoconfig/src/test/java/org/springframework/cloud/kubernetes/client/KubernetesClientActuatorTests.java diff --git a/spring-cloud-kubernetes-client-autoconfig/pom.xml b/spring-cloud-kubernetes-client-autoconfig/pom.xml index 410a9a6f..8044c42c 100644 --- a/spring-cloud-kubernetes-client-autoconfig/pom.xml +++ b/spring-cloud-kubernetes-client-autoconfig/pom.xml @@ -48,6 +48,11 @@ spring-boot-starter-web test + + org.springframework.boot + spring-boot-starter-webflux + test + org.mockito mockito-inline diff --git a/spring-cloud-kubernetes-client-autoconfig/src/main/java/org/springframework/cloud/kubernetes/client/KubernetesClientActuatorConfiguration.java b/spring-cloud-kubernetes-client-autoconfig/src/main/java/org/springframework/cloud/kubernetes/client/KubernetesClientActuatorConfiguration.java new file mode 100644 index 00000000..755c50bd --- /dev/null +++ b/spring-cloud-kubernetes-client-autoconfig/src/main/java/org/springframework/cloud/kubernetes/client/KubernetesClientActuatorConfiguration.java @@ -0,0 +1,50 @@ +/* + * Copyright 2013-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.kubernetes.client; + +import io.kubernetes.client.openapi.models.V1Pod; + +import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; +import org.springframework.boot.actuate.autoconfigure.info.ConditionalOnEnabledInfoContributor; +import org.springframework.boot.actuate.health.HealthIndicator; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled; +import org.springframework.cloud.kubernetes.commons.PodUtils; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author wind57 + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnClass(HealthIndicator.class) +@ConditionalOnKubernetesEnabled +public class KubernetesClientActuatorConfiguration { + + @Bean + @ConditionalOnEnabledHealthIndicator("kubernetes") + public KubernetesClientHealthIndicator kubernetesHealthIndicator(PodUtils podUtils) { + return new KubernetesClientHealthIndicator(podUtils); + } + + @Bean + @ConditionalOnEnabledInfoContributor("kubernetes") + public KubernetesClientInfoContributor kubernetesInfoContributor(PodUtils podUtils) { + return new KubernetesClientInfoContributor(podUtils); + } + +} diff --git a/spring-cloud-kubernetes-client-autoconfig/src/main/java/org/springframework/cloud/kubernetes/client/KubernetesClientAutoConfiguration.java b/spring-cloud-kubernetes-client-autoconfig/src/main/java/org/springframework/cloud/kubernetes/client/KubernetesClientAutoConfiguration.java index 8a665c9c..2e8f3975 100644 --- a/spring-cloud-kubernetes-client-autoconfig/src/main/java/org/springframework/cloud/kubernetes/client/KubernetesClientAutoConfiguration.java +++ b/spring-cloud-kubernetes-client-autoconfig/src/main/java/org/springframework/cloud/kubernetes/client/KubernetesClientAutoConfiguration.java @@ -18,18 +18,12 @@ package org.springframework.cloud.kubernetes.client; import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; -import org.springframework.boot.actuate.autoconfigure.info.ConditionalOnEnabledInfoContributor; -import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled; import org.springframework.cloud.kubernetes.commons.KubernetesCommonsAutoConfiguration; import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; -import org.springframework.cloud.kubernetes.commons.PodUtils; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; @@ -71,22 +65,4 @@ public class KubernetesClientAutoConfiguration { return new KubernetesClientPodUtils(client, kubernetesNamespaceProvider.getNamespace()); } - @Configuration(proxyBeanMethods = false) - @ConditionalOnClass(HealthIndicator.class) - protected static class KubernetesActuatorConfiguration { - - @Bean - @ConditionalOnEnabledHealthIndicator("kubernetes") - public KubernetesClientHealthIndicator kubernetesHealthIndicator(PodUtils podUtils) { - return new KubernetesClientHealthIndicator(podUtils); - } - - @Bean - @ConditionalOnEnabledInfoContributor("kubernetes") - public KubernetesClientInfoContributor kubernetesInfoContributor(PodUtils podUtils) { - return new KubernetesClientInfoContributor(podUtils); - } - - } - } diff --git a/spring-cloud-kubernetes-client-autoconfig/src/main/resources/META-INF/spring.factories b/spring-cloud-kubernetes-client-autoconfig/src/main/resources/META-INF/spring.factories index 92100504..43c87e4c 100644 --- a/spring-cloud-kubernetes-client-autoconfig/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-kubernetes-client-autoconfig/src/main/resources/META-INF/spring.factories @@ -1,5 +1,6 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.springframework.cloud.kubernetes.client.KubernetesClientAutoConfiguration +org.springframework.cloud.kubernetes.client.KubernetesClientAutoConfiguration,\ +org.springframework.cloud.kubernetes.client.KubernetesClientActuatorConfiguration org.springframework.boot.env.EnvironmentPostProcessor=\ diff --git a/spring-cloud-kubernetes-client-autoconfig/src/test/java/org/springframework/cloud/kubernetes/client/KubernetesClientActuatorTests.java b/spring-cloud-kubernetes-client-autoconfig/src/test/java/org/springframework/cloud/kubernetes/client/KubernetesClientActuatorTests.java new file mode 100644 index 00000000..9233f30e --- /dev/null +++ b/spring-cloud-kubernetes-client-autoconfig/src/test/java/org/springframework/cloud/kubernetes/client/KubernetesClientActuatorTests.java @@ -0,0 +1,91 @@ +/* + * Copyright 2013-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.kubernetes.client; + +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.actuate.health.ReactiveHealthContributorRegistry; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.kubernetes.client.example.App; +import org.springframework.http.MediaType; +import org.springframework.test.web.reactive.server.WebTestClient; + +/** + * @author wind57 + */ +public class KubernetesClientActuatorTests { + + @Nested + @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = { + "management.health.kubernetes.enabled=false", "management.endpoint.health.show-details=always", + "management.endpoint.health.show-components=always", "management.endpoints.web.exposure.include=health" }) + public class DisabledHealthTest { + + @Autowired + private ReactiveHealthContributorRegistry registry; + + @Autowired + private WebTestClient webClient; + + @Value("${local.server.port}") + private int port; + + @Test + public void healthEndpointShouldContainKubernetes() { + this.webClient.get().uri("http://localhost:{port}/actuator/health", this.port) + .accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody(String.class) + .value(Matchers.not(Matchers.containsString("kubernetes"))); + + Assertions.assertNull(registry.getContributor("kubernetes"), + "reactive kubernetes contributor must NOT be present when 'management.health.kubernetes.enabled=false'"); + } + + } + + @Nested + @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = { + "management.health.kubernetes.enabled=true", "management.endpoint.health.show-details=always", + "management.endpoint.health.show-components=always", "management.endpoints.web.exposure.include=health" }) + public class EnabledHealthTest { + + @Autowired + private WebTestClient webClient; + + @Autowired + private ReactiveHealthContributorRegistry registry; + + @Value("${local.server.port}") + private int port; + + @Test + public void healthEndpointShouldContainKubernetes() { + this.webClient.get().uri("http://localhost:{port}/actuator/health", this.port) + .accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody(String.class) + .value(Matchers.containsString("kubernetes")); + + Assertions.assertNotNull(registry.getContributor("kubernetes"), + "reactive kubernetes contributor must be present when 'management.health.kubernetes.enabled=true'"); + } + + } + +} diff --git a/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientBootstrapConfiguration.java b/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientBootstrapConfiguration.java index df47dfb1..bdf86bf4 100644 --- a/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientBootstrapConfiguration.java +++ b/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientBootstrapConfiguration.java @@ -19,9 +19,10 @@ package org.springframework.cloud.kubernetes.client.config; import io.kubernetes.client.openapi.apis.CoreV1Api; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.kubernetes.client.KubernetesClientAutoConfiguration; +import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesConfigEnabled; import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled; +import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesSecretsEnabled; import org.springframework.cloud.kubernetes.commons.KubernetesCommonsAutoConfiguration; import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.config.ConfigMapConfigProperties; @@ -37,29 +38,22 @@ import org.springframework.context.annotation.Import; @Configuration(proxyBeanMethods = false) @ConditionalOnKubernetesEnabled @AutoConfigureAfter(KubernetesBootstrapConfiguration.class) +@Import({ KubernetesCommonsAutoConfiguration.class, KubernetesClientAutoConfiguration.class }) public class KubernetesClientBootstrapConfiguration { - @Configuration(proxyBeanMethods = false) - @Import({ KubernetesCommonsAutoConfiguration.class, KubernetesClientAutoConfiguration.class }) - protected static class KubernetesPropertySourceConfiguration { - - @Bean - @ConditionalOnProperty(name = "spring.cloud.kubernetes.config.enabled", matchIfMissing = true) - public KubernetesClientConfigMapPropertySourceLocator configMapPropertySourceLocator( - ConfigMapConfigProperties properties, CoreV1Api coreV1Api, - KubernetesNamespaceProvider kubernetesNamespaceProvider) { - return new KubernetesClientConfigMapPropertySourceLocator(coreV1Api, properties, - kubernetesNamespaceProvider); - } - - @Bean - @ConditionalOnProperty(name = "spring.cloud.kubernetes.secrets.enabled", matchIfMissing = true) - public KubernetesClientSecretsPropertySourceLocator secretsPropertySourceLocator( - SecretsConfigProperties properties, CoreV1Api coreV1Api, - KubernetesNamespaceProvider kubernetesNamespaceProvider) { - return new KubernetesClientSecretsPropertySourceLocator(coreV1Api, kubernetesNamespaceProvider, properties); - } + @Bean + @ConditionalOnKubernetesConfigEnabled + public KubernetesClientConfigMapPropertySourceLocator configMapPropertySourceLocator( + ConfigMapConfigProperties properties, CoreV1Api coreV1Api, + KubernetesNamespaceProvider kubernetesNamespaceProvider) { + return new KubernetesClientConfigMapPropertySourceLocator(coreV1Api, properties, kubernetesNamespaceProvider); + } + @Bean + @ConditionalOnKubernetesSecretsEnabled + public KubernetesClientSecretsPropertySourceLocator secretsPropertySourceLocator(SecretsConfigProperties properties, + CoreV1Api coreV1Api, KubernetesNamespaceProvider kubernetesNamespaceProvider) { + return new KubernetesClientSecretsPropertySourceLocator(coreV1Api, kubernetesNamespaceProvider, properties); } } From 05a214ade70efaa465c936394acc6b7c4a0207d3 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Tue, 13 Jul 2021 13:58:21 -0400 Subject: [PATCH 4/5] Revert "Add note to disable health indicator in bootstrap yaml | properites (#827)" This reverts commit 6dcad3a7b81b1520dd5df0e02eb8a0f2f2109b4d. --- docs/src/main/asciidoc/pod-health-indicator.adoc | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/src/main/asciidoc/pod-health-indicator.adoc b/docs/src/main/asciidoc/pod-health-indicator.adoc index d3139f50..05f1fd21 100644 --- a/docs/src/main/asciidoc/pod-health-indicator.adoc +++ b/docs/src/main/asciidoc/pod-health-indicator.adoc @@ -7,6 +7,3 @@ The Kubernetes health indicator (which is part of the core module) exposes the f * Pod name, IP address, namespace, service account, node name, and its IP address * A flag that indicates whether the Spring Boot application is internal or external to Kubernetes - -You can disable this `HealthContributor` by setting `management.health.kubernetes.enabled` -to `false` in `bootstrap.[properties | yaml]`. From d11da589278bcb53d11c16399c063fd101e01494 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Tue, 13 Jul 2021 14:00:27 -0400 Subject: [PATCH 5/5] Clarify how to disable health and info contributors --- docs/src/main/asciidoc/info-contributor.adoc | 2 +- docs/src/main/asciidoc/pod-health-indicator.adoc | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/src/main/asciidoc/info-contributor.adoc b/docs/src/main/asciidoc/info-contributor.adoc index 073dfdca..7f2057e1 100644 --- a/docs/src/main/asciidoc/info-contributor.adoc +++ b/docs/src/main/asciidoc/info-contributor.adoc @@ -4,4 +4,4 @@ Spring Cloud Kubernetes includes an `InfoContributor` which adds Pod information Spring Boot's `/info` Acturator endpoint. You can disable this `InfoContributor` by setting `management.info.kubernetes.enabled` -to `false` in `bootstrap.[properties | yaml]`. +to `false` in `application.[properties | yaml]`. diff --git a/docs/src/main/asciidoc/pod-health-indicator.adoc b/docs/src/main/asciidoc/pod-health-indicator.adoc index 05f1fd21..3c59f2e3 100644 --- a/docs/src/main/asciidoc/pod-health-indicator.adoc +++ b/docs/src/main/asciidoc/pod-health-indicator.adoc @@ -7,3 +7,6 @@ The Kubernetes health indicator (which is part of the core module) exposes the f * Pod name, IP address, namespace, service account, node name, and its IP address * A flag that indicates whether the Spring Boot application is internal or external to Kubernetes + +You can disable this `HealthContributor` by setting `management.health.kubernetes.enabled` +to `false` in `application.[properties | yaml]`.