diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/kubernetes/ProbesHealthContributorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/kubernetes/ProbesHealthContributorAutoConfiguration.java index 7259724781..bd01f0592e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/kubernetes/ProbesHealthContributorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/kubernetes/ProbesHealthContributorAutoConfiguration.java @@ -17,6 +17,7 @@ package org.springframework.boot.actuate.autoconfigure.kubernetes; import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; +import org.springframework.boot.actuate.autoconfigure.kubernetes.ProbesHealthContributorAutoConfiguration.KubernetesOrPropertyCondition; import org.springframework.boot.actuate.availability.LivenessProbeHealthIndicator; import org.springframework.boot.actuate.availability.ReadinessProbeHealthIndicator; import org.springframework.boot.actuate.health.HealthEndpointGroupsRegistryCustomizer; @@ -24,11 +25,14 @@ import org.springframework.boot.actuate.kubernetes.ProbesHealthEndpointGroupsReg import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.availability.ApplicationAvailabilityProvider; import org.springframework.boot.cloud.CloudPlatform; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; /** @@ -39,7 +43,7 @@ import org.springframework.context.annotation.Configuration; * @since 2.3.0 */ @Configuration(proxyBeanMethods = false) -@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) +@Conditional(KubernetesOrPropertyCondition.class) @AutoConfigureAfter(ApplicationAvailabilityAutoConfiguration.class) public class ProbesHealthContributorAutoConfiguration { @@ -64,4 +68,22 @@ public class ProbesHealthContributorAutoConfiguration { return new ProbesHealthEndpointGroupsRegistrar(); } + static class KubernetesOrPropertyCondition extends AnyNestedCondition { + + KubernetesOrPropertyCondition() { + super(ConfigurationPhase.PARSE_CONFIGURATION); + } + + @ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) + static class Kubernetes { + + } + + @ConditionalOnProperty(prefix = "management.health.probes", name = "enabled") + static class ProbesIndicatorsEnabled { + + } + + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 1be8a99d86..4ba0d95641 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -146,6 +146,12 @@ "description": "Whether to enable ping health check.", "defaultValue": true }, + { + "name": "management.health.probes.enabled", + "type": "java.lang.Boolean", + "description": "Whether to enable liveness and readiness probes.", + "defaultValue": false + }, { "name": "management.health.rabbit.enabled", "type": "java.lang.Boolean", diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/kubernetes/ProbesHealthContributorAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/kubernetes/ProbesHealthContributorAutoConfigurationTests.java index 57e0c937d5..fa919c537e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/kubernetes/ProbesHealthContributorAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/kubernetes/ProbesHealthContributorAutoConfigurationTests.java @@ -47,8 +47,8 @@ class ProbesHealthContributorAutoConfigurationTests { } @Test - void probesConfiguredIfKubernetes() { - this.contextRunner.withPropertyValues("spring.main.cloud-platform=kubernetes") + void probesConfiguredIfProperty() { + this.contextRunner.withPropertyValues("management.health.probes.enabled=true") .run((context) -> assertThat(context).hasSingleBean(ApplicationAvailabilityProvider.class) .hasSingleBean(LivenessProbeHealthIndicator.class) .hasSingleBean(ReadinessProbeHealthIndicator.class) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/deployment.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/deployment.adoc index 328cde83c7..5aaf91e152 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/deployment.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/deployment.adoc @@ -184,7 +184,7 @@ TIP: The https://github.com/pivotal-cf/java-cfenv/[Java CFEnv] project is a bett [[cloud-deployment-kubernetes]] === Kubernetes Spring Boot auto-detects Kubernetes deployment environments by checking the environment for `"*_SERVICE_HOST"` and `"*_SERVICE_PORT"` variables. -You can override this detection with the configprop:spring.main.cloud-platform[] configuration property. +You can override this detection with the configprop:management.health.probes.enabled[] configuration property. Spring Boot helps you to <> and export it with <>.