Skip to content

Commit

Permalink
feat: allow disabling KubernetesHealthIndicator using endpoints.healt…
Browse files Browse the repository at this point in the history
…h.kubernetes.enabled: false (#755)
  • Loading branch information
felhag committed Sep 12, 2024
1 parent b031575 commit a90dd49
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
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
import io.micronaut.http.client.annotation.Client
import io.micronaut.kubernetes.health.KubernetesHealthIndicator
import micronaut.client.utils.KubernetesSpecification
import io.micronaut.kubernetes.test.TestUtils
import io.micronaut.test.extensions.spock.annotation.MicronautTest
Expand Down Expand Up @@ -45,6 +47,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 {
Expand All @@ -55,4 +68,4 @@ class KubernetesHealthIndicatorSpec extends KubernetesSpecification {
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Map<String, Object>> {

public static final String NAME = "kubernetes";
Expand Down
10 changes: 10 additions & 0 deletions src/main/docs/guide/health-checks.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
----

0 comments on commit a90dd49

Please sign in to comment.