Skip to content

Commit ad3dd37

Browse files
committed
fix(jkube-healthcheck-spring-boot enricher)!: rename property management.health.probes.enabled
BREAKING CHANGE: Rename management.health.probes.enabled to management.endpoint.health.probes.enabled, since spring boot 2.3.2 Fix #3690
1 parent 9c7d1e4 commit ad3dd37

File tree

6 files changed

+46
-11
lines changed

6 files changed

+46
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Usage:
2121
./scripts/extract-changelog-for-version.sh 1.3.37 5
2222
```
2323
### 1.19-SNAPSHOT
24+
* Fix #3690: jkube-healthcheck-spring-boot enricher: rename property management.health.probes.enabled
2425

2526
### 1.18.1 (2025-02-11)
2627
* Fix #3642: Config properties resolved for generated images

gradle-plugin/it/src/it/spring-boot-managementhealthprobes/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# Red Hat, Inc. - initial API and implementation
1313
#
1414

15-
management.health.probes.enabled=true
15+
management.endpoint.health.probes.enabled=true

jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/SpringBootConfiguration.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public static SpringBootConfiguration from(JavaProject project) {
4242
final Properties properties = SpringBootUtil.getSpringBootApplicationProperties(
4343
SpringBootUtil.getSpringBootActiveProfile(project),
4444
JKubeProjectUtil.getClassLoader(project));
45-
final int majorVersion = SpringBootUtil.getSpringBootVersion(project)
45+
Optional<String> springBootVersion = SpringBootUtil.getSpringBootVersion(project);
46+
final int majorVersion = springBootVersion
4647
.map(semVer -> {
4748
try {
4849
return Integer.parseInt(semVer.substring(0, semVer.indexOf('.')));
@@ -52,13 +53,23 @@ public static SpringBootConfiguration from(JavaProject project) {
5253
})
5354
// Defaults to Spring 1
5455
.orElse(1);
56+
final int minorVersion = springBootVersion
57+
.map(semVer -> {
58+
try {
59+
return Integer.parseInt(semVer.substring(semVer.indexOf('.'), semVer.lastIndexOf('.')));
60+
} catch (Exception e) {
61+
return null;
62+
}
63+
})
64+
// Defaults to Spring 1
65+
.orElse(1);
5566
final SpringBootConfiguration.SpringBootConfigurationBuilder configBuilder = SpringBootConfiguration.builder();
5667
// Spring Boot 1 and common properties
5768
configBuilder
5869
.managementPort(Optional.ofNullable(properties.getProperty("management.port")).map(Integer::parseInt).orElse(null))
5970
.serverPort(Integer.parseInt(properties.getProperty("server.port", DEFAULT_SERVER_PORT)))
6071
.serverKeystore(properties.getProperty("server.ssl.key-store"))
61-
.managementHealthProbesEnabled(Boolean.parseBoolean(properties.getProperty("management.health.probes.enabled")))
72+
.managementHealthProbesEnabled(Boolean.parseBoolean(properties.getProperty("management.endpoint.health.probes.enabled")))
6273
.managementKeystore(properties.getProperty("management.ssl.key-store"))
6374
.servletPath(properties.getProperty("server.servlet-path"))
6475
.serverContextPath(properties.getProperty("server.context-path"))
@@ -81,6 +92,11 @@ public static SpringBootConfiguration from(JavaProject project) {
8192
.servletPath(properties.getProperty("spring.mvc.servlet.path"))
8293
.managementContextPath(properties.getProperty("management.server.base-path"));
8394
}
95+
// keep backward compatibility with spring-boot < 2.3.x
96+
// prioritize the new property in case both are set
97+
if (majorVersion < 3 && minorVersion < 4 && properties.getProperty("management.endpoint.health.probes.enabled") == null) {
98+
configBuilder.managementHealthProbesEnabled(Boolean.parseBoolean(properties.getProperty("management.health.probes.enabled")));
99+
}
84100
return configBuilder.build();
85101
}
86102
}

jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/util/SpringBootConfigurationTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ void setUp(@TempDir Path target) throws IOException {
5454
properties.put("management.context-path", "management.context-path");
5555
properties.put("management.server.servlet.context-path", "management.server.servlet.context-path");
5656
properties.put("management.endpoints.web.base-path", "management.endpoints.web.base-path");
57+
properties.put("management.health.probes.enabled", "true");
58+
properties.put("management.endpoint.health.probes.enabled", "true");
5759
try (OutputStream fos = Files.newOutputStream(target.resolve("application.properties"))) {
5860
properties.store(fos, null);
5961
}
@@ -134,6 +136,12 @@ void getActuatorBasePath() {
134136
void getActuatorDefaultBasePath() {
135137
assertThat(springBootConfiguration.getActuatorDefaultBasePath()).isEqualTo("/actuator");
136138
}
139+
140+
@Test
141+
@DisplayName("getManagementHealthProbesEnabled defaults to 'true'")
142+
void getManagementHealthProbesEnabled() {
143+
assertThat(springBootConfiguration.isManagementHealthProbesEnabled()).isTrue();
144+
}
137145
}
138146

139147
@Nested
@@ -150,6 +158,12 @@ void setUp() {
150158
.build());
151159
}
152160

161+
@Test
162+
@DisplayName("getManagementHealthProbesEnabled defaults to 'true'")
163+
void getManagementHealthProbesEnabled() {
164+
assertThat(springBootConfiguration.isManagementHealthProbesEnabled()).isTrue();
165+
}
166+
153167
@Test
154168
@DisplayName("getManagementPort defaults to 'management.server.port'")
155169
void getManagementPort() {

jkube-kit/doc/src/main/asciidoc/inc/enricher/spring-boot-healthcheck/_jkube_healthcheck_spring_boot.adoc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ endif::[]
1414

1515
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.
1616

17-
The enricher will try to discover the settings from the `application.properties` / `application.yaml` Spring Boot configuration file.
17+
The enricher will try to discover the settings from the `application.properties` / `application.yaml` Spring Boot configuration file. The configuration properties are:
1818

19-
`/actuator/health` is the default endpoint for the liveness and readiness probes.
19+
* `management.endpoints.web.base-path`: The prefix for the health endpoint. The default is `/actuator`
20+
* `management.endpoint.health.probes.enabled`: Enable the container liveness and readiness probe endpoints.
2021

21-
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.
22+
`/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`.
23+
24+
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.
2225
[source,properties]
2326
----
24-
management.health.probes.enabled=true
27+
management.endpoint.health.probes.enabled=true
2528
----
2629

2730
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:
3639
* `timeoutSeconds` : _<kubernetes-default>_
3740
* `failureThreshold`: `3`
3841
* `successThreshold`: `1`
42+
* `actuatorDefaultBasePath`: `/actuator`
3943

4044
These values can be configured by the enricher in the `{plugin}` configuration as shown below:
4145

jkube-kit/jkube-kit-spring-boot/src/test/java/org/eclipse/jkube/springboot/enricher/AbstractSpringBootHealthCheckEnricherTestSupport.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ void testCustomPropertiesForLivenessAndReadiness() {
661661

662662
@Test
663663
void testBuildProbeExplicitPathCreation_whenManagementHealthProbesEnabledIsTrue(){
664-
props.put("management.health.probes.enabled","true");
664+
props.put("management.endpoint.health.probes.enabled","true");
665665
writeProps();
666666

667667
Probe readinessProbe = new SpringBootHealthCheckEnricher(context).buildProbe(10, null, null, 3, 1,"/example");
@@ -670,7 +670,7 @@ void testBuildProbeExplicitPathCreation_whenManagementHealthProbesEnabledIsTrue(
670670

671671
@Test
672672
void testBuildProbeDefaultPathCreation_whenManagementHealthProbesEnabledIsFalse(){
673-
props.put("management.health.probes.enabled","false");
673+
props.put("management.endpoint.health.probes.enabled","false");
674674
writeProps();
675675

676676
Probe readinessProbe = new SpringBootHealthCheckEnricher(context).buildProbe(10, null, null, 3, 1,"/example");
@@ -679,7 +679,7 @@ void testBuildProbeDefaultPathCreation_whenManagementHealthProbesEnabledIsFalse(
679679

680680
@Test
681681
void testLivenessAndReadinessProbesForExplicitPath_whenManagementHealthProbesEnabledIsTrue(){
682-
props.put("management.health.probes.enabled","true");
682+
props.put("management.endpoint.health.probes.enabled","true");
683683
writeProps();
684684

685685
when(context.getProjectClassLoaders().isClassInCompileClasspath(true, REQUIRED_CLASSES))
@@ -712,7 +712,7 @@ void testLivenessAndReadinessProbesForDefaultPath_whenDefaultConfigUsed(){
712712

713713
@Test
714714
void testLivenessAndReadinessProbesForDefaultPath_whenManagementHealthProbesEnabledIsFalse(){
715-
props.put("management.health.probes.enabled","false");
715+
props.put("management.endpoint.health.probes.enabled","false");
716716
writeProps();
717717

718718
when(projectClassLoaders.isClassInCompileClasspath(true, REQUIRED_CLASSES))

0 commit comments

Comments
 (0)