forked from eclipse-jkube/jkube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for issue eclipse-jkube#283, Add support for WildFly Bootable JAR
Signed-off-by: JF Denise <[email protected]>
- Loading branch information
Showing
20 changed files
with
907 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2020 Red Hat, Inc. | ||
This program and the accompanying materials are made | ||
available under the terms of the Eclipse Public License 2.0 | ||
which is available at: | ||
https://www.eclipse.org/legal/epl-2.0/ | ||
SPDX-License-Identifier: EPL-2.0 | ||
Contributors: | ||
Red Hat, Inc. - initial API and implementation | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<parent> | ||
<groupId>org.eclipse.jkube</groupId> | ||
<artifactId>jkube-kit-parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<relativePath>../parent/pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>jkube-kit-wildfly-jar</artifactId> | ||
<name>JKube Kit :: WildFly JAR</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.jkube</groupId> | ||
<artifactId>jkube-kit-common-maven</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.jkube</groupId> | ||
<artifactId>jkube-kit-generator-java-exec</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.jkube</groupId> | ||
<artifactId>jkube-kit-enricher-specific</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jmockit</groupId> | ||
<artifactId>jmockit</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
172 changes: 172 additions & 0 deletions
172
...r/src/main/java/org/eclipse/jkube/wildfly/jar/enricher/WildflyJARHealthCheckEnricher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
/** | ||
* Copyright (c) 2020 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.wildfly.jar.enricher; | ||
|
||
import io.fabric8.kubernetes.api.builder.TypedVisitor; | ||
import io.fabric8.kubernetes.api.model.ContainerBuilder; | ||
import io.fabric8.kubernetes.api.model.EnvVarBuilder; | ||
import io.fabric8.kubernetes.api.model.KubernetesListBuilder; | ||
import io.fabric8.kubernetes.api.model.Probe; | ||
import io.fabric8.kubernetes.api.model.ProbeBuilder; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.eclipse.jkube.kit.common.Configs; | ||
import org.eclipse.jkube.kit.enricher.api.JKubeEnricherContext; | ||
import org.eclipse.jkube.kit.enricher.specific.AbstractHealthCheckEnricher; | ||
|
||
import org.eclipse.jkube.kit.common.JavaProject; | ||
import org.eclipse.jkube.kit.common.Plugin; | ||
import org.eclipse.jkube.kit.common.util.JKubeProjectUtil; | ||
import org.eclipse.jkube.kit.config.resource.PlatformMode; | ||
|
||
/** | ||
* Enriches wildfly-jar containers with health checks if the bootable JAR has | ||
* been configured for cloud. | ||
*/ | ||
public class WildflyJARHealthCheckEnricher extends AbstractHealthCheckEnricher { | ||
|
||
public static final String BOOTABLE_JAR_GROUP_ID = "org.wildfly.plugins"; | ||
public static final String BOOTABLE_JAR_ARTIFACT_ID = "wildfly-jar-maven-plugin"; | ||
|
||
public WildflyJARHealthCheckEnricher(JKubeEnricherContext buildContext) { | ||
super(buildContext, "jkube-healthcheck-wildfly-jar"); | ||
} | ||
|
||
@AllArgsConstructor | ||
private enum Config implements Configs.Config { | ||
|
||
SCHEME("scheme", "HTTP"), | ||
PORT("port", "9990"), | ||
FAILURETHRESHOLD("failureThreshold","3"), | ||
SUCCESSTHRESHOLD("successThreshold","1"), | ||
LIVENESSINITIALDELAY("livenessInitialDelay", "60"), | ||
READINESSINITIALDELAY("readinessInitialDelay", "10"), | ||
READINESSPATH("readinessPath", "/health/ready"), | ||
LIVENESSPATH("livenessPath", "/health/live"), | ||
ENFORCEPROBES("enforceProbes","false"); | ||
|
||
@Getter | ||
protected String key; | ||
@Getter | ||
protected String defaultValue; | ||
} | ||
|
||
@Override | ||
protected Probe getReadinessProbe() { | ||
return discoverWildflyJARHealthCheck(true); | ||
} | ||
|
||
@Override | ||
protected Probe getLivenessProbe() { | ||
return discoverWildflyJARHealthCheck(false); | ||
} | ||
|
||
@Override | ||
public void create(PlatformMode platformMode, KubernetesListBuilder builder) { | ||
// Add HOSTNAME | ||
if (PlatformMode.kubernetes.equals(platformMode)) { | ||
final List<ContainerBuilder> containerBuilders = new LinkedList<>(); | ||
builder.accept(new TypedVisitor<ContainerBuilder>() { | ||
@Override | ||
public void visit(ContainerBuilder containerBuilder) { | ||
containerBuilders.add(containerBuilder); | ||
} | ||
}); | ||
for (ContainerBuilder container : containerBuilders) { | ||
container.addToEnv(new EnvVarBuilder() | ||
.withName("HOSTNAME") | ||
.withNewValueFrom() | ||
.withNewFieldRef() | ||
.withFieldPath("metadata.name") | ||
.endFieldRef() | ||
.endValueFrom() | ||
.build()); | ||
} | ||
} | ||
super.create(platformMode, builder); | ||
} | ||
|
||
private Probe discoverWildflyJARHealthCheck(boolean isReadiness) { | ||
|
||
if (isAvailable()) { | ||
Integer port = getPort(); | ||
if (port <= 0) { | ||
return null; | ||
} | ||
int initialDelay = isReadiness ? getReadinessInitialDelay() : getLivenessInitialDelay(); | ||
// scheme must be in upper case in k8s | ||
String scheme = getScheme().toUpperCase(); | ||
String path = isReadiness ? getReadinessPath() : getLivenessPath(); | ||
|
||
return new ProbeBuilder() | ||
.withNewHttpGet().withNewPort(port).withPath(path).withScheme(scheme).endHttpGet() | ||
.withFailureThreshold(getFailureThreshold()) | ||
.withSuccessThreshold(getSuccessThreshold()) | ||
.withInitialDelaySeconds(initialDelay).build(); | ||
} | ||
return null; | ||
} | ||
|
||
private boolean isAvailable() { | ||
if (isProbeEnforced()) { | ||
return true; | ||
} | ||
JavaProject project = ((JKubeEnricherContext) getContext()).getProject(); | ||
Plugin plugin = JKubeProjectUtil.getPlugin(project, BOOTABLE_JAR_GROUP_ID, BOOTABLE_JAR_ARTIFACT_ID); | ||
if (plugin == null) { | ||
return false; | ||
} | ||
Map<String, Object> config = plugin.getConfiguration(); | ||
return config.containsKey("cloud"); | ||
} | ||
|
||
protected int getFailureThreshold() { | ||
return Configs.asInteger(getConfig(Config.FAILURETHRESHOLD)); | ||
} | ||
|
||
protected boolean isProbeEnforced() { | ||
return Configs.asBoolean(getConfig(Config.ENFORCEPROBES)); | ||
} | ||
|
||
protected int getSuccessThreshold() { | ||
return Configs.asInteger(getConfig(Config.SUCCESSTHRESHOLD)); | ||
} | ||
|
||
protected String getScheme() { | ||
return Configs.asString(getConfig(Config.SCHEME)); | ||
} | ||
|
||
protected int getPort() { | ||
return Configs.asInt(getConfig(Config.PORT)); | ||
} | ||
|
||
protected String getLivenessPath() { | ||
return Configs.asString(getConfig(Config.LIVENESSPATH)); | ||
} | ||
|
||
protected int getLivenessInitialDelay() { | ||
return Configs.asInt(getConfig(Config.LIVENESSINITIALDELAY)); | ||
} | ||
|
||
protected String getReadinessPath() { | ||
return Configs.asString(getConfig(Config.READINESSPATH)); | ||
} | ||
|
||
protected int getReadinessInitialDelay() { | ||
return Configs.asInt(getConfig(Config.READINESSINITIALDELAY)); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...ildfly-jar/src/main/java/org/eclipse/jkube/wildfly/jar/generator/WildflyJARGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Copyright (c) 2020 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.wildfly.jar.generator; | ||
|
||
import org.eclipse.jkube.generator.api.GeneratorContext; | ||
import org.eclipse.jkube.generator.javaexec.JavaExecGenerator; | ||
import org.eclipse.jkube.kit.config.image.ImageConfiguration; | ||
import org.eclipse.jkube.kit.common.util.JKubeProjectUtil; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import org.eclipse.jkube.wildfly.jar.enricher.WildflyJARHealthCheckEnricher; | ||
|
||
public class WildflyJARGenerator extends JavaExecGenerator { | ||
|
||
public WildflyJARGenerator(GeneratorContext context) { | ||
super(context, "wildfly-jar"); | ||
} | ||
|
||
@Override | ||
public boolean isApplicable(List<ImageConfiguration> configs) { | ||
return shouldAddGeneratedImageConfiguration(configs) | ||
&& JKubeProjectUtil.hasPlugin(getProject(), | ||
WildflyJARHealthCheckEnricher.BOOTABLE_JAR_GROUP_ID, WildflyJARHealthCheckEnricher.BOOTABLE_JAR_ARTIFACT_ID); | ||
} | ||
|
||
@Override | ||
protected Map<String, String> getEnv(boolean isPrepackagePhase) { | ||
Map<String, String> ret = super.getEnv(isPrepackagePhase); | ||
// Switch off Prometheus agent until logging issue with WildFly Swarm is resolved | ||
// See: | ||
// - https://github.com/fabric8io/fabric8-maven-plugin/issues/1173 | ||
// - https://issues.jboss.org/browse/THORN-1859 | ||
ret.put("AB_PROMETHEUS_OFF", "true"); | ||
ret.put("AB_OFF", "true"); | ||
|
||
// In addition, there is no proper fix in Jolokia to detect that the Bootable JAR is started. | ||
// Can be workarounded by setting JAVA_OPTIONS to contain -Djboss.modules.system.pkgs=org.jboss.byteman | ||
ret.put("AB_JOLOKIA_OFF", "true"); | ||
return ret; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
jkube-kit/jkube-kit-wildfly-jar/src/main/resources/META-INF/jkube/enricher-default
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Healthcheck Enrichers | ||
org.eclipse.jkube.wildfly.jar.enricher.WildflyJARHealthCheckEnricher |
5 changes: 5 additions & 0 deletions
5
jkube-kit/jkube-kit-wildfly-jar/src/main/resources/META-INF/jkube/generator-default
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# The order of the generators used is defined in the active profile | ||
# (which is the profile "default" by default) | ||
# You can find the default profiles in "profiles-default.yml" | ||
|
||
org.eclipse.jkube.wildfly.jar.generator.WildflyJARGenerator |
Oops, something went wrong.