diff --git a/CHANGELOG.md b/CHANGELOG.md index 026d5b358c..6e7a5ac359 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ Usage: ./scripts/extract-changelog-for-version.sh 1.3.37 5 ``` ### 1.19-SNAPSHOT +* Fix #3690: jkube-healthcheck-spring-boot enricher: rename property management.health.probes.enabled ### 1.18.1 (2025-02-11) * Fix #3642: Config properties resolved for generated images diff --git a/gradle-plugin/it/src/it/spring-boot-managementhealthprobes/src/main/resources/application.properties b/gradle-plugin/it/src/it/spring-boot-managementhealthprobes/src/main/resources/application.properties index ec2c116dc5..4b386ea5a6 100644 --- a/gradle-plugin/it/src/it/spring-boot-managementhealthprobes/src/main/resources/application.properties +++ b/gradle-plugin/it/src/it/spring-boot-managementhealthprobes/src/main/resources/application.properties @@ -12,4 +12,4 @@ # Red Hat, Inc. - initial API and implementation # -management.health.probes.enabled=true \ No newline at end of file +management.endpoint.health.probes.enabled=true \ No newline at end of file diff --git a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/SpringBootConfiguration.java b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/SpringBootConfiguration.java index c396356c34..5031cacf89 100644 --- a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/SpringBootConfiguration.java +++ b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/SpringBootConfiguration.java @@ -42,7 +42,7 @@ public static SpringBootConfiguration from(JavaProject project) { final Properties properties = SpringBootUtil.getSpringBootApplicationProperties( SpringBootUtil.getSpringBootActiveProfile(project), JKubeProjectUtil.getClassLoader(project)); - final int majorVersion = SpringBootUtil.getSpringBootVersion(project) + final int majorVersion = SpringBootUtil.getSpringBootVersion(project) .map(semVer -> { try { return Integer.parseInt(semVer.substring(0, semVer.indexOf('.'))); @@ -58,7 +58,7 @@ public static SpringBootConfiguration from(JavaProject project) { .managementPort(Optional.ofNullable(properties.getProperty("management.port")).map(Integer::parseInt).orElse(null)) .serverPort(Integer.parseInt(properties.getProperty("server.port", DEFAULT_SERVER_PORT))) .serverKeystore(properties.getProperty("server.ssl.key-store")) - .managementHealthProbesEnabled(Boolean.parseBoolean(properties.getProperty("management.health.probes.enabled"))) + .managementHealthProbesEnabled(Boolean.parseBoolean(properties.getProperty("management.endpoint.health.probes.enabled"))) .managementKeystore(properties.getProperty("management.ssl.key-store")) .servletPath(properties.getProperty("server.servlet-path")) .serverContextPath(properties.getProperty("server.context-path")) @@ -81,6 +81,12 @@ public static SpringBootConfiguration from(JavaProject project) { .servletPath(properties.getProperty("spring.mvc.servlet.path")) .managementContextPath(properties.getProperty("management.server.base-path")); } + // keep backward compatibility with spring-boot < 2.3.x + // prioritize the new property in case both are set + // if (majorVersion < 3 && minorVersion < 4 && properties.getProperty("management.endpoint.health.probes.enabled") == null) { + if (SemanticVersionUtil.isVersionAtLeast(2, 3, Integer.toString(majorVersion)) && properties.getProperty("management.endpoint.health.probes.enabled") == null) { + configBuilder.managementHealthProbesEnabled(Boolean.parseBoolean(properties.getProperty("management.health.probes.enabled"))); + } return configBuilder.build(); } } diff --git a/jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/util/SpringBootConfigurationTest.java b/jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/util/SpringBootConfigurationTest.java index 4271d9e4a8..efd53c49b4 100644 --- a/jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/util/SpringBootConfigurationTest.java +++ b/jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/util/SpringBootConfigurationTest.java @@ -54,6 +54,8 @@ void setUp(@TempDir Path target) throws IOException { properties.put("management.context-path", "management.context-path"); properties.put("management.server.servlet.context-path", "management.server.servlet.context-path"); properties.put("management.endpoints.web.base-path", "management.endpoints.web.base-path"); + properties.put("management.health.probes.enabled", "true"); + properties.put("management.endpoint.health.probes.enabled", "true"); try (OutputStream fos = Files.newOutputStream(target.resolve("application.properties"))) { properties.store(fos, null); } @@ -134,6 +136,12 @@ void getActuatorBasePath() { void getActuatorDefaultBasePath() { assertThat(springBootConfiguration.getActuatorDefaultBasePath()).isEqualTo("/actuator"); } + + @Test + @DisplayName("getManagementHealthProbesEnabled defaults to 'true'") + void getManagementHealthProbesEnabled() { + assertThat(springBootConfiguration.isManagementHealthProbesEnabled()).isTrue(); + } } @Nested @@ -150,6 +158,12 @@ void setUp() { .build()); } + @Test + @DisplayName("getManagementHealthProbesEnabled defaults to 'true'") + void getManagementHealthProbesEnabled() { + assertThat(springBootConfiguration.isManagementHealthProbesEnabled()).isTrue(); + } + @Test @DisplayName("getManagementPort defaults to 'management.server.port'") void getManagementPort() { diff --git a/jkube-kit/doc/src/main/asciidoc/inc/enricher/spring-boot-healthcheck/_jkube_healthcheck_spring_boot.adoc b/jkube-kit/doc/src/main/asciidoc/inc/enricher/spring-boot-healthcheck/_jkube_healthcheck_spring_boot.adoc index 93d979ba20..e999425f80 100644 --- a/jkube-kit/doc/src/main/asciidoc/inc/enricher/spring-boot-healthcheck/_jkube_healthcheck_spring_boot.adoc +++ b/jkube-kit/doc/src/main/asciidoc/inc/enricher/spring-boot-healthcheck/_jkube_healthcheck_spring_boot.adoc @@ -14,14 +14,17 @@ endif::[] If you're using Spring Boot WebFlux, this enricher would automatically read `spring.webflux.base-path` property to infer base path for health check endpoints. -The enricher will try to discover the settings from the `application.properties` / `application.yaml` Spring Boot configuration file. +The enricher will try to discover the settings from the `application.properties` / `application.yaml` Spring Boot configuration file. The configuration properties are: -`/actuator/health` is the default endpoint for the liveness and readiness probes. +* `management.endpoints.web.base-path`: The prefix for the health endpoint. The default is `/actuator` +* `management.endpoint.health.probes.enabled`: Enable the container liveness and readiness probe endpoints. -If the user has enabled the `management.health.probes.enabled` property this Enricher uses the `/actuator/health/liveness` as liveness and `/actuator/health/readiness` as readiness probe endpoints instead. +`/actuator/health` is the default endpoint for the liveness and readiness probes, you can change it by setting the property `management.endpoints.web.base-path`. + +If the user has enabled the `management.endpoint.health.probes.enabled` property this Enricher uses the `/actuator/health/liveness` as liveness and `/actuator/health/readiness` as readiness probe endpoints instead. [source,properties] ---- -management.health.probes.enabled=true +management.endpoint.health.probes.enabled=true ---- The port number is read from the `management.port` option, and will use the default value of `8080` @@ -36,6 +39,7 @@ The enricher will use the following settings by default: * `timeoutSeconds` : __ * `failureThreshold`: `3` * `successThreshold`: `1` +* `actuatorDefaultBasePath`: `/actuator` These values can be configured by the enricher in the `{plugin}` configuration as shown below: diff --git a/jkube-kit/jkube-kit-spring-boot/src/test/java/org/eclipse/jkube/springboot/enricher/AbstractSpringBootHealthCheckEnricherTestSupport.java b/jkube-kit/jkube-kit-spring-boot/src/test/java/org/eclipse/jkube/springboot/enricher/AbstractSpringBootHealthCheckEnricherTestSupport.java index f51ca945e1..51cf2855f6 100644 --- a/jkube-kit/jkube-kit-spring-boot/src/test/java/org/eclipse/jkube/springboot/enricher/AbstractSpringBootHealthCheckEnricherTestSupport.java +++ b/jkube-kit/jkube-kit-spring-boot/src/test/java/org/eclipse/jkube/springboot/enricher/AbstractSpringBootHealthCheckEnricherTestSupport.java @@ -661,7 +661,7 @@ void testCustomPropertiesForLivenessAndReadiness() { @Test void testBuildProbeExplicitPathCreation_whenManagementHealthProbesEnabledIsTrue(){ - props.put("management.health.probes.enabled","true"); + props.put("management.endpoint.health.probes.enabled","true"); writeProps(); Probe readinessProbe = new SpringBootHealthCheckEnricher(context).buildProbe(10, null, null, 3, 1,"/example"); @@ -670,7 +670,7 @@ void testBuildProbeExplicitPathCreation_whenManagementHealthProbesEnabledIsTrue( @Test void testBuildProbeDefaultPathCreation_whenManagementHealthProbesEnabledIsFalse(){ - props.put("management.health.probes.enabled","false"); + props.put("management.endpoint.health.probes.enabled","false"); writeProps(); Probe readinessProbe = new SpringBootHealthCheckEnricher(context).buildProbe(10, null, null, 3, 1,"/example"); @@ -679,7 +679,7 @@ void testBuildProbeDefaultPathCreation_whenManagementHealthProbesEnabledIsFalse( @Test void testLivenessAndReadinessProbesForExplicitPath_whenManagementHealthProbesEnabledIsTrue(){ - props.put("management.health.probes.enabled","true"); + props.put("management.endpoint.health.probes.enabled","true"); writeProps(); when(context.getProjectClassLoaders().isClassInCompileClasspath(true, REQUIRED_CLASSES)) @@ -712,7 +712,7 @@ void testLivenessAndReadinessProbesForDefaultPath_whenDefaultConfigUsed(){ @Test void testLivenessAndReadinessProbesForDefaultPath_whenManagementHealthProbesEnabledIsFalse(){ - props.put("management.health.probes.enabled","false"); + props.put("management.endpoint.health.probes.enabled","false"); writeProps(); when(projectClassLoaders.isClassInCompileClasspath(true, REQUIRED_CLASSES))