Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow disabling KubernetesHealthIndicator using endpoints.healt… #756

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
----
Loading