diff --git a/examples/example-client/src/test/groovy/micronaut/client/KubernetesHealthIndicatorSpec.groovy b/examples/example-client/src/test/groovy/micronaut/client/KubernetesHealthIndicatorSpec.groovy index c080b5269..74043a897 100644 --- a/examples/example-client/src/test/groovy/micronaut/client/KubernetesHealthIndicatorSpec.groovy +++ b/examples/example-client/src/test/groovy/micronaut/client/KubernetesHealthIndicatorSpec.groovy @@ -1,5 +1,6 @@ package micronaut.client +import io.micronaut.context.ApplicationContext import io.micronaut.context.annotation.Property import io.micronaut.context.env.Environment import io.micronaut.http.annotation.Get @@ -45,6 +46,17 @@ class KubernetesHealthIndicatorSpec extends KubernetesSpecification { details.kubernetes.details.containerStatuses.first().ready == true } + void "bean of type KubernetesHealthIndicator does not exist if you set endpoints.health.kubernetes.enabled=false"() { + when: + ApplicationContext applicationContext = ApplicationContext.run(['endpoints.health.kubernetes.enabled': 'false']) + + then: + !applicationContext.containsBean(KubernetesHealthIndicator) + + cleanup: + applicationContext.close() + } + @Client("http://localhost:9999") @MicronautRequires(property = "spec.name", value = "KubernetesHealthIndicatorSpec") static interface ServiceClient { @@ -55,4 +67,4 @@ class KubernetesHealthIndicatorSpec extends KubernetesSpecification { } -} \ No newline at end of file +} diff --git a/kubernetes-discovery-client/src/main/java/io/micronaut/kubernetes/health/KubernetesHealthIndicator.java b/kubernetes-discovery-client/src/main/java/io/micronaut/kubernetes/health/KubernetesHealthIndicator.java index bef989cc6..2b3a36d61 100644 --- a/kubernetes-discovery-client/src/main/java/io/micronaut/kubernetes/health/KubernetesHealthIndicator.java +++ b/kubernetes-discovery-client/src/main/java/io/micronaut/kubernetes/health/KubernetesHealthIndicator.java @@ -22,6 +22,7 @@ import io.kubernetes.client.openapi.models.V1PodStatus; import io.micronaut.context.annotation.Requires; import io.micronaut.context.env.Environment; +import io.micronaut.core.util.StringUtils; import io.micronaut.health.HealthStatus; import io.micronaut.kubernetes.KubernetesConfiguration; import io.micronaut.kubernetes.client.reactor.CoreV1ApiReactorClient; @@ -50,6 +51,7 @@ @Requires(beans = HealthEndpoint.class) @Requires(env = Environment.KUBERNETES) @Requires(property = HOSTNAME_ENV_VARIABLE_IN_PROPERTY_FORMAT) +@Requires(property = HealthEndpoint.PREFIX + ".kubernetes.enabled", notEquals = StringUtils.FALSE) public class KubernetesHealthIndicator extends AbstractHealthIndicator> { public static final String NAME = "kubernetes"; diff --git a/src/main/docs/guide/health-checks.adoc b/src/main/docs/guide/health-checks.adoc index 5e9869365..871bfd328 100644 --- a/src/main/docs/guide/health-checks.adoc +++ b/src/main/docs/guide/health-checks.adoc @@ -84,3 +84,13 @@ Also note that in order to see the full details of the health checks you may nee https://docs.micronaut.io/latest/guide/index.html#healthEndpoint[the documentation of the Health Endpoint] for more information about how to configure it. ==== + +By default the KubernetesHealthIndicator is enabled. To disable it use the following configuration: + +[source,yaml] +---- +endpoints: + health: + kubernetes: + enabled: false +----