Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# Red Hat, Inc. - initial API and implementation
#

management.health.probes.enabled=true
management.endpoint.health.probes.enabled=true
Original file line number Diff line number Diff line change
Expand Up @@ -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('.')));
Expand All @@ -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"))
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -36,6 +39,7 @@ The enricher will use the following settings by default:
* `timeoutSeconds` : _<kubernetes-default>_
* `failureThreshold`: `3`
* `successThreshold`: `1`
* `actuatorDefaultBasePath`: `/actuator`

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
Loading