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 d3139f50..3c59f2e3 100644
--- a/docs/src/main/asciidoc/pod-health-indicator.adoc
+++ b/docs/src/main/asciidoc/pod-health-indicator.adoc
@@ -9,4 +9,4 @@ The Kubernetes health indicator (which is part of the core module) exposes the f
* 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]`.
+to `false` in `application.[properties | yaml]`.
diff --git a/spring-cloud-kubernetes-client-autoconfig/pom.xml b/spring-cloud-kubernetes-client-autoconfig/pom.xml
index bea028e4..1dc34748 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);
}
}
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'");
+ }
+
+ }
+
+}