Skip to content

Commit

Permalink
Fix fabric8io#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 12, 2019
1 parent f253a34 commit e1a795e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ After this we will switch probably to real [Semantic Versioning 2.0.0](http://se
* Feature 1498: Allow users to define secrets from annotations
* Fix 1522: Remove need to initialize DockerAccess when on Openshift
* 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
22 changes: 18 additions & 4 deletions doc/src/main/asciidoc/inc/goals/build/_fabric8-resource.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,29 @@ spec:

In case both the label and the property have been set with conflicting values, precedence will be given to the property value, so if you set the label to `true` but set the property to `false` then no Route descriptor will be generated because precedence will be given to the property value.

[[disable-automatic-deployments]]
=== Disable Automatic Deployments
[[Other-flags]]
=== Other flags

.Automatic Trigger Configuration
[cols="1.6.1"]
.Other options available with resource goal
[cols="1.6.3"]
|===
| Configuration | Description | Default

| *fabric8.openshift.enableAutomaticTrigger*
| If the value is set to `false` then automatic deployments would be disabled.
| `true`

| *fabric8.skipHealthChecks*
| If the value is set to `true` then no readiness/liveness checks would be added to any containers.
| `false`

| *fabric8.openshift.deployTimeoutSeconds*
| The OpenShift deploy timeout in seconds.
| 3600

| *fabric8.openshift.imageChangeTrigger*
| Add ImageChange triggers to DeploymentConfigs when on openshift.
| `true`
|===

[[Other-flags]]
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.skipHealthChecks") != null) {
return Boolean.parseBoolean(getContext().getProperty("fabric8.skipHealthChecks").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.skipHealthChecks", defaultValue = "false")
private Boolean skipHealthChecks;

/**
* 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 e1a795e

Please sign in to comment.