Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
Fix #1444: Option to Disable Liveness/readiness checks
Browse files Browse the repository at this point in the history
+ Added an option fabric8.disableHealthChecks to disable readiness/liveness checks
+ Added path option in SpringBootHealthCheckEnricher to overwrite path for liveness/readiness
  • Loading branch information
rohanKanojia committed Mar 13, 2019
1 parent 5ea9d46 commit 7e69e43
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ After this we will switch probably to real [Semantic Versioning 2.0.0](http://se
* Fix 1522: Remove need to initialize DockerAccess when on Openshift
* Fix 1570: Failure in applying Deployments using fabric8-maven-plugin
* Fix 1517: update vmp groupid and vert.x version
* Fix 1444: Option to Disable Liveness/readiness checks
* Feature 456: Add labels from label-schema.org to the generator images.

### 4.0.0-M2 (2018-12-14)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,28 @@ public AbstractHealthCheckEnricher(MavenEnricherContext buildContext, String nam

@Override
public void create(PlatformMode platformMode, KubernetesListBuilder builder) {

builder.accept(new TypedVisitor<ContainerBuilder>() {
@Override
public void visit(ContainerBuilder container) {
if (!container.hasReadinessProbe()) {
Probe probe = getReadinessProbe(container);
if (probe != null) {
log.info("Adding readiness " + describe(probe));
container.withReadinessProbe(probe);
if(!checkIfhealthChecksDisabled(false)) {
builder.accept(new TypedVisitor<ContainerBuilder>() {
@Override
public void visit(ContainerBuilder container) {
if (!container.hasReadinessProbe()) {
Probe probe = getReadinessProbe(container);
if (probe != null) {
log.info("Adding readiness " + describe(probe));
container.withReadinessProbe(probe);
}
}
}

if (!container.hasLivenessProbe()) {
Probe probe = getLivenessProbe(container);
if (probe != null) {
log.info("Adding liveness " + describe(probe));
container.withLivenessProbe(probe);
if (!container.hasLivenessProbe()) {
Probe probe = getLivenessProbe(container);
if (probe != null) {
log.info("Adding liveness " + describe(probe));
container.withLivenessProbe(probe);
}
}
}
}
});
});
}
}

private String describe(Probe probe) {
Expand Down Expand Up @@ -83,6 +84,14 @@ private String describe(Probe probe) {
return desc.toString();
}

protected Boolean checkIfhealthChecksDisabled(Boolean defaultValue) {
if(getContext().getProperty("fabric8.skipHealthCheck") != null) {
return Boolean.parseBoolean(getContext().getProperty("fabric8.skipHealthCheck").toString());
} else {
return defaultValue;
}
}

/**
* Override this method to create a per-container readiness probe.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class SpringBootHealthCheckEnricher extends AbstractHealthCheckEnricher {
private enum Config implements Configs.Key {
readinessProbeInitialDelaySeconds {{ d = "10"; }},
readinessProbePeriodSeconds,
path {{ d = "/health"; }},
livenessProbeInitialDelaySeconds {{ d = "180"; }},
livenessProbePeriodSeconds,
failureThreshold {{ d = "3"; }},
Expand Down Expand Up @@ -118,7 +119,7 @@ protected Probe buildProbe(Properties springBootProperties, Integer initialDelay

// lets default to adding a spring boot actuator health check
ProbeBuilder probeBuilder = new ProbeBuilder().
withNewHttpGet().withNewPort(port).withPath(prefix + actuatorBasePath + "/health").withScheme(scheme).endHttpGet();
withNewHttpGet().withNewPort(port).withPath(prefix + actuatorBasePath + Configs.asString(getConfig(Config.path))).withScheme(scheme).endHttpGet();

if (initialDelay != null) {
probeBuilder = probeBuilder.withInitialDelaySeconds(initialDelay);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ public class ResourceMojo extends AbstractFabric8Mojo {
@Parameter(property = "fabric8.namespace")
private String namespace;

@Parameter(property = "fabric8.skipHealthCheck", defaultValue = "false")
private Boolean skipHealthCheck;

/**
* The OpenShift deploy timeout in seconds:
* See this issue for background of why for end users on slow wifi on their laptops
Expand Down

0 comments on commit 7e69e43

Please sign in to comment.