Skip to content

Commit

Permalink
fix (jkube-kit) : QuarkusHealthCheckEnricher adds Kubernetes Startup …
Browse files Browse the repository at this point in the history
…probes when Quarkus version >= 2.1

Looks like Quarkus only seems to support these new `/q/health/started`
endpoints since `2.1.0.Final`. Add a check to only add startup probes in
projects using Quarkus 2.1.x and later.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
  • Loading branch information
rohanKanojia authored and manusa committed Jul 6, 2022
1 parent be63f1f commit 4ffc29f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class QuarkusUtils {
private static final String QUARKUS_MAVEN_PLUGIN_ARTIFACTID = "quarkus-maven-plugin";
private static final int QUARKUS_MAJOR_VERSION_SINCE_PATH_RESOLUTION_CHANGE = 1;
private static final int QUARKUS_MINOR_VERSION_SINCE_PATH_RESOLUTION_CHANGE = 11;
private static final int QUARKUS_MAJOR_VERSION_SINCE_STARTUP_CHANGE = 2;
private static final int QUARKUS_MINOR_VERSION_SINCE_STARTUP_CHANGE = 1;
private static final int QUARKUS2_MAJOR_VERSION = 2;
private static final int QUARKUS2_MINOR_VERSION = 0;
private static final String DEFAULT_ROOT_PATH = "/";
Expand Down Expand Up @@ -203,6 +205,17 @@ public static String resolveCompleteQuarkusHealthRootPath(JavaProject javaProjec
return ret;
}

/**
* Check whether given Quarkus version supports startup endpoint or not by checking
* Quarkus version is greater than 2.1.
*
* @param javaProject current project
* @return boolean value indicating whether it's supported or not.
*/
public static boolean isStartupEndpointSupported(JavaProject javaProject) {
return isVersionAtLeast(QUARKUS_MAJOR_VERSION_SINCE_STARTUP_CHANGE, QUARKUS_MINOR_VERSION_SINCE_STARTUP_CHANGE, findQuarkusVersion(javaProject));
}

private static String resolveQuarkusNonApplicationRootPath(String quarkusVersion, Properties quarkusProperties) {
final String defaultValue = isVersionAtLeast(QUARKUS2_MAJOR_VERSION, QUARKUS2_MINOR_VERSION, quarkusVersion) ?
DEFAULT_NON_APPLICATION_ROOT_AFTER_2_0 : DEFAULT_NON_APPLICATION_ROOT_BEFORE_2_0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static org.eclipse.jkube.kit.common.Configs.asInteger;
import static org.eclipse.jkube.quarkus.QuarkusUtils.QUARKUS_GROUP_ID;
import static org.eclipse.jkube.quarkus.QuarkusUtils.concatPath;
import static org.eclipse.jkube.quarkus.QuarkusUtils.isStartupEndpointSupported;
import static org.eclipse.jkube.quarkus.QuarkusUtils.resolveCompleteQuarkusHealthRootPath;

/**
Expand Down Expand Up @@ -73,8 +74,11 @@ protected Probe getLivenessProbe() {

@Override
protected Probe getStartupProbe() {
return discoverQuarkusHealthCheck(asInteger(getConfig(Config.STARTUP_INITIAL_DELAY, "5")),
if (isStartupEndpointSupported(getContext().getProject())) {
return discoverQuarkusHealthCheck(asInteger(getConfig(Config.STARTUP_INITIAL_DELAY, "5")),
QuarkusUtils::resolveQuarkusStartupPath);
}
return null;
}

private Probe discoverQuarkusHealthCheck(int initialDelay, Function<JavaProject, String> pathResolver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static org.eclipse.jkube.quarkus.QuarkusUtils.extractPort;
import static org.eclipse.jkube.quarkus.QuarkusUtils.findQuarkusVersion;
import static org.eclipse.jkube.quarkus.QuarkusUtils.getQuarkusConfiguration;
import static org.eclipse.jkube.quarkus.QuarkusUtils.isStartupEndpointSupported;
import static org.eclipse.jkube.quarkus.QuarkusUtils.resolveCompleteQuarkusHealthRootPath;
import static org.eclipse.jkube.quarkus.QuarkusUtils.resolveQuarkusLivenessPath;
import static org.eclipse.jkube.quarkus.QuarkusUtils.resolveQuarkusStartupPath;
Expand Down Expand Up @@ -296,6 +297,30 @@ public void resolveQuarkusStartupPath_withStartupPathSet_shouldReturnValidPath()
.isEqualTo("startup");
}

@Test
public void isStartupEndpointSupported_withQuarkusVersionBefore2_1_shouldReturnFalse() {
// Given
javaProject.setDependencies(quarkusDependencyWithVersion("2.0.3.Final"));

// When
boolean result = isStartupEndpointSupported(javaProject);

// Then
assertThat(result).isFalse();
}

@Test
public void isStartupEndpointSupported_withQuarkusVersionAfter2_1_shouldReturnTrue() {
// Given
javaProject.setDependencies(quarkusDependencyWithVersion("2.9.2.Final"));

// When
boolean result = isStartupEndpointSupported(javaProject);

// Then
assertThat(result).isTrue();
}

@Test
public void concatPath_withEmptyRootAndPrefixed() {
assertThat(concatPath("/", "/liveness")).isEqualTo("/liveness");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void create_withCustomPath_shouldReturnCustomPath() {
// When
new QuarkusHealthCheckEnricher(context).create(PlatformMode.kubernetes, klb);
// Then
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/my-custom-path/live", "HTTP", "/my-custom-path/ready", "HTTP", "/my-custom-path/started"));
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/my-custom-path/live", "HTTP", "/my-custom-path/ready", null, null));
}

@Test
Expand All @@ -101,7 +101,7 @@ public void create_withDefaultsAndQuarkus1_shouldReturnDefaults() {
// When
new QuarkusHealthCheckEnricher(context).create(PlatformMode.kubernetes, klb);
// Then
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/health/live", "HTTP", "/health/ready", "HTTP", "/health/started"));
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/health/live", "HTTP", "/health/ready", null, null));
}

@Test
Expand All @@ -112,7 +112,7 @@ public void create_withDefaultsAndQuarkus2_shouldReturnPrefixedDefaults() {
// When
new QuarkusHealthCheckEnricher(context).create(PlatformMode.kubernetes, klb);
// Then
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/q/health/live", "HTTP", "/q/health/ready", "HTTP", "/q/health/started"));
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/q/health/live", "HTTP", "/q/health/ready", null, null));
}

@Test
Expand All @@ -129,7 +129,7 @@ public void create_withQuarkus2AndApplicationProperties_shouldReturnCustomizedPa
// When
new QuarkusHealthCheckEnricher(context).create(PlatformMode.kubernetes, klb);
// Then
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/not-app/health/im-alive", "HTTP", "/not-app/health/im-ready", "HTTP", "/not-app/health/im-started"));
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/not-app/health/im-alive", "HTTP", "/not-app/health/im-ready", null, null));
}

@Test
Expand All @@ -144,7 +144,7 @@ public void create_withQuarkus2AndCustomRootProperty_shouldReturnCustomizedPaths
// When
new QuarkusHealthCheckEnricher(context).create(PlatformMode.kubernetes, klb);
// Then
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/root/q/health/liveness", "HTTP", "/root/q/health/ready", "HTTP", "/root/q/health/started"));
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/root/q/health/liveness", "HTTP", "/root/q/health/ready", null, null));
}

@Test
Expand Down Expand Up @@ -195,7 +195,7 @@ public void create_withQuarkus1_0AndAbsoluteLivenessPathProperty_shouldIgnoreLea
// When
new QuarkusHealthCheckEnricher(context).create(PlatformMode.kubernetes, klb);
// Then
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/health/absolute/liveness", "HTTP", "/health/ready", "HTTP", "/health/started"));
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/health/absolute/liveness", "HTTP", "/health/ready", null, null));
}

@Test
Expand All @@ -207,7 +207,7 @@ public void create_withQuarkus1_0AndAbsoluteReadinessPathProperty_shouldIgnoreLe
// When
new QuarkusHealthCheckEnricher(context).create(PlatformMode.kubernetes, klb);
// Then
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/health/live", "HTTP", "/health/absolute/readiness", "HTTP", "/health/started"));
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/health/live", "HTTP", "/health/absolute/readiness", null, null));
}

@Test
Expand All @@ -221,7 +221,7 @@ public void create_withQuarkus2AndAbsoluteHealthPathProperty_shouldReturnCustomi
// When
new QuarkusHealthCheckEnricher(context).create(PlatformMode.kubernetes, klb);
// Then
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/absolute/health/live", "HTTP", "/absolute/health/ready", "HTTP", "/absolute/health/started"));
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/absolute/health/live", "HTTP", "/absolute/health/ready", null, null));
}

@Test
Expand All @@ -234,7 +234,7 @@ public void create_withQuarkus1_0AndAbsoluteHealthPathProperty_shouldIgnoreLeadi
// When
new QuarkusHealthCheckEnricher(context).create(PlatformMode.kubernetes, klb);
// Then
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/not-ignored/absolute/live", "HTTP", "/not-ignored/absolute/ready", "HTTP", "/not-ignored/absolute/started"));
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/not-ignored/absolute/live", "HTTP", "/not-ignored/absolute/ready", null, null));
}

@Test
Expand All @@ -246,7 +246,7 @@ public void create_withQuarkus1_0AndAbsoluteStartupPathProperty_shouldIgnoreLead
// When
new QuarkusHealthCheckEnricher(context).create(PlatformMode.kubernetes, klb);
// Then
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/health/live", "HTTP", "/health/ready", "HTTP", "/health/absolute/startup"));
assertLivenessReadinessStartupProbes(klb, tuple("HTTP", "/health/live", "HTTP", "/health/ready", null, null));
}

@Test
Expand Down

0 comments on commit 4ffc29f

Please sign in to comment.