Skip to content

Commit

Permalink
[issue 123] - Implement WildFly/EAP 8 Helm Charts provisioning differ…
Browse files Browse the repository at this point in the history
…entiation
  • Loading branch information
fabiobrz committed Dec 19, 2023
1 parent 02bc828 commit 7a14207
Show file tree
Hide file tree
Showing 17 changed files with 14,464 additions and 107 deletions.
11,825 changes: 11,825 additions & 0 deletions stoca.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@
*/
package org.jboss.intersmash.testsuite.provision.openshift;

import java.net.URL;
import java.nio.file.Path;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jboss.intersmash.deployments.IntersmashDelpoyableWildflyApplication;
import org.jboss.intersmash.model.helm.charts.values.eap8.HelmEap8Release;
import org.jboss.intersmash.model.helm.charts.values.wildfly.HelmWildflyRelease;
import org.jboss.intersmash.testsuite.IntersmashTestsuiteProperties;
import org.jboss.intersmash.tools.IntersmashConfig;
import org.jboss.intersmash.tools.application.openshift.helm.HelmChartRelease;
import org.jboss.intersmash.tools.application.openshift.helm.WildflyHelmChartOpenShiftApplication;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import org.jboss.intersmash.tools.provision.helm.wildfly.WildFlyHelmChartReleaseAdapter;
import org.jboss.intersmash.tools.provision.helm.wildfly.eap8.Eap8HelmChartReleaseAdapter;

import io.fabric8.kubernetes.api.model.Secret;

Expand All @@ -42,7 +40,7 @@ public class WildflyHelmChartExistingValuesOpenShiftExampleApplicaton
private final Map<String, String> setOverrides = new HashMap<>();

public WildflyHelmChartExistingValuesOpenShiftExampleApplicaton() {
this.release = new HelmChartRelease(loadRelease());
this.release = loadRelease();
}

WildflyHelmChartExistingValuesOpenShiftExampleApplicaton addSetOverride(String name, String value) {
Expand All @@ -55,20 +53,17 @@ public Map<String, String> getSetOverrides() {
return setOverrides;
}

private HelmWildflyRelease loadRelease() {
URL url = this.getClass().getResource("wildfly-helm-values.yaml");
if (url == null) {
throw new IllegalStateException("No wildfly-helm-values.yaml found");
}
try {
Path valuePath = Path.of(url.toURI());
ObjectMapper mapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));
return mapper.readValue(valuePath.toFile(), HelmWildflyRelease.class);
} catch (Error | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
private HelmChartRelease loadRelease() {
if (IntersmashTestsuiteProperties.isCommunityTestExecutionProfileEnabled()) {
WildFlyHelmChartReleaseAdapter adapter = new WildFlyHelmChartReleaseAdapter(new HelmWildflyRelease());
adapter.fromValuesFile(this.getClass().getResource("wildfly-helm-values.yaml"), HelmWildflyRelease.class);
return adapter;
} else if (IntersmashTestsuiteProperties.isProductizedTestExecutionProfileEnabled()) {
Eap8HelmChartReleaseAdapter adapter = new Eap8HelmChartReleaseAdapter(new HelmEap8Release());
adapter.fromValuesFile(this.getClass().getResource("eap8-helm-values.yaml"), HelmEap8Release.class);
return adapter;
} else
throw new IllegalStateException("Not a valid testing profile!");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.jboss.intersmash.tools.IntersmashConfig;
import org.jboss.intersmash.tools.provision.helm.HelmChartOpenShiftProvisioner;
import org.jboss.intersmash.tools.provision.helm.WildflyHelmChartOpenShiftProvisioner;
import org.jboss.intersmash.tools.provision.helm.wildfly.WildflyHelmChartOpenShiftProvisioner;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -39,7 +39,7 @@ public void basicProvisioningTest() {
.addSetOverride("build.uri", IntersmashConfig.deploymentsRepositoryUrl())
.addSetOverride("build.ref", IntersmashConfig.deploymentsRepositoryRef())
.addSetOverride("deploy.builderImage", application.getBuilderImage())
.addSetOverride("deployRuntimeImage", application.getRuntimeImage());
.addSetOverride("deploy.runtimeImage", application.getRuntimeImage());

// and now get an EAP 8/WildFly provisioner for that application
final WildflyHelmChartOpenShiftProvisioner provisioner = new WildflyHelmChartOpenShiftProvisioner(application);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@
*/
package org.jboss.intersmash.testsuite.provision.openshift;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.assertj.core.util.Strings;
import org.jboss.intersmash.deployments.IntersmashDelpoyableWildflyApplication;
import org.jboss.intersmash.deployments.IntersmashSharedDeploymentsProperties;
import org.jboss.intersmash.model.helm.charts.values.wildfly.Build;
import org.jboss.intersmash.model.helm.charts.values.wildfly.Deploy;
import org.jboss.intersmash.model.helm.charts.values.wildfly.Env;
import org.jboss.intersmash.model.helm.charts.values.eap8.HelmEap8Release;
import org.jboss.intersmash.model.helm.charts.values.wildfly.HelmWildflyRelease;
import org.jboss.intersmash.model.helm.charts.values.wildfly.S2i;
import org.jboss.intersmash.testsuite.IntersmashTestsuiteProperties;
import org.jboss.intersmash.tools.IntersmashConfig;
import org.jboss.intersmash.tools.application.openshift.helm.HelmChartRelease;
import org.jboss.intersmash.tools.application.openshift.helm.WildflyHelmChartOpenShiftApplication;
import org.jboss.intersmash.tools.provision.helm.wildfly.WildFlyHelmChartReleaseAdapter;
import org.jboss.intersmash.tools.provision.helm.wildfly.WildflyHelmChartRelease;
import org.jboss.intersmash.tools.provision.helm.wildfly.eap8.Eap8HelmChartReleaseAdapter;

import io.fabric8.kubernetes.api.model.Secret;

Expand All @@ -41,11 +40,15 @@ public class WildflyHelmChartOpenShiftExampleApplicaton
private final HelmChartRelease release;

public WildflyHelmChartOpenShiftExampleApplicaton() {
this.release = new HelmChartRelease(loadRelease());
if (IntersmashTestsuiteProperties.isCommunityTestExecutionProfileEnabled()) {
release = loadRelease(new WildFlyHelmChartReleaseAdapter(new HelmWildflyRelease()));
} else if (IntersmashTestsuiteProperties.isProductizedTestExecutionProfileEnabled()) {
release = loadRelease(new Eap8HelmChartReleaseAdapter(new HelmEap8Release()));
} else
throw new IllegalStateException("Not a valid testing profile!");
}

private HelmWildflyRelease loadRelease() {
HelmWildflyRelease release = new HelmWildflyRelease();
private HelmChartRelease loadRelease(final WildflyHelmChartRelease release) {
// let's compute some additional maven args for our s2i build to happen on a Pod
String mavenAdditionalArgs = "-Denforcer.skip=true";
// let's add configurable deployment additional args:
Expand All @@ -55,24 +58,17 @@ private HelmWildflyRelease loadRelease() {
(Strings.isNullOrEmpty(IntersmashSharedDeploymentsProperties.getWildflyDeploymentsBuildProfile()) ? ""
: " -Pwildfly-deployments-build."
+ IntersmashSharedDeploymentsProperties.getWildflyDeploymentsBuildProfile()));
// ok, let's configure the release via the fluent(-ish) API
List<Env> environmentVariables = new ArrayList();
// ok, let's configure the release via the WildflyHelmChartRelease fluent(-ish) API,
// which offers a common reference for both WildFly and EAP (latest)
release
.withBuild(
new Build()
.withUri(IntersmashConfig.deploymentsRepositoryUrl())
.withRef(IntersmashConfig.deploymentsRepositoryRef())
.withContextDir("deployments/openshift-jakarta-sample-standalone")
.withEnv(
Arrays.asList(
new Env()
.withName("MAVEN_ARGS_APPEND")
.withValue(mavenAdditionalArgs)))
.withS2i(
new S2i()
.withBuilderImage(IntersmashConfig.wildflyImageURL())
.withRuntimeImage(IntersmashConfig.wildflyRuntimeImageURL())))
.withDeploy(new Deploy().withReplicas(1));
.withSourceRepositoryUrl(IntersmashConfig.deploymentsRepositoryUrl())
.withSourceRepositoryRef(IntersmashConfig.deploymentsRepositoryRef())
.withContextDir("deployments/openshift-jakarta-sample-standalone")
// an example, not working with EAP 7.4.x or WildFly and commented in the deployment POM
.withS2iChannel(IntersmashConfig.getWildflyEeChannelLocation())
.withJdk17BuilderImage(IntersmashConfig.wildflyImageURL())
.withJdk17RuntimeImage(IntersmashConfig.wildflyRuntimeImageURL())
.withBuildEnvironmentVariable("MAVEN_ARGS_APPEND", mavenAdditionalArgs);
return release;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.jboss.intersmash.tools.application.openshift.helm.WildflyHelmChartOpenShiftApplication;
import org.jboss.intersmash.tools.provision.helm.HelmChartOpenShiftProvisioner;
import org.jboss.intersmash.tools.provision.helm.WildflyHelmChartOpenShiftProvisioner;
import org.jboss.intersmash.tools.provision.helm.wildfly.WildflyHelmChartOpenShiftProvisioner;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
build:
enabled: true
mode: "s2i"
# uri and ref will be specified via Helm --set arguments
contextDir: "deployments/openshift-jakarta-sample-standalone"
env:
- name: "MAVEN_ARGS_APPEND"
value: "-Denforcer.skip=true -Pwildfly-deployments-build.eap"
s2i:
kind: "DockerImage"
buildApplicationImage: true
# builderImage and runtimeImage will be specified via Helm --set arguments
deploy:
enabled: true
replicas: 1
env: []
envFrom: []
volumeMounts: []
volumes: []
initContainers: []
extraContainers: []
'imagePullSecrets:': []
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,20 @@
*/
package org.jboss.intersmash.tools.application.openshift.helm;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.jboss.intersmash.model.helm.charts.values.wildfly.HelmWildflyRelease;
import org.jboss.intersmash.tools.provision.helm.HelmChartOpenShiftProvisioner;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;

/**
* Defines the contract for implementing classes to represent a Helm Charts release, as seen by the provisioning
* tooling.
*/
public class HelmChartRelease implements SerializableHelmChartRelease {

private final HelmWildflyRelease wildflyRelease;
private final List<Path> additionalValuesFiles = new ArrayList<>();

public HelmChartRelease(HelmWildflyRelease wildflyRelease) {
this(wildflyRelease, null);
}

public HelmChartRelease(HelmWildflyRelease wildflyRelease, List<Path> additionalValuesFiles) {
this.wildflyRelease = wildflyRelease;
if (additionalValuesFiles != null) {
this.additionalValuesFiles.addAll(additionalValuesFiles.stream().collect(Collectors.toList()));
}
}
/**
* Defines the contract for implementing classes to represent a Helm Charts release, as seen by the provisioning
* tooling.
*/
public interface HelmChartRelease extends SerializableHelmChartRelease {

/**
* Read the number of replicas that the release should generate
Expand All @@ -57,9 +37,7 @@ public HelmChartRelease(HelmWildflyRelease wildflyRelease, List<Path> additional
*
* @return {@link Integer} representing the number of replicas that the release should generate
*/
public Integer getReplicas() {
return wildflyRelease.getDeploy().getReplicas();
}
Integer getReplicas();

/**
* Set the number of replicas that should be generated by the release
Expand All @@ -68,9 +46,7 @@ public Integer getReplicas() {
*
* @param replicas Number of replicas that should be generated by the release
*/
public void setReplicas(Integer replicas) {
this.wildflyRelease.getDeploy().setReplicas(replicas);
}
void setReplicas(Integer replicas);

/**
* Access the additional values files collection
Expand All @@ -79,27 +55,5 @@ public void setReplicas(Integer replicas) {
* @return List of {@link Path} instances representing the location of additional values files that make the
* release
*/
public List<Path> getAdditionalValuesFiles() {
return this.additionalValuesFiles;
}

@Override
public Path toValuesFile() {
// Handle the values file creation
Path temp;
try {
temp = Files.createTempFile("values", ".yaml");
} catch (IOException e) {
throw new IllegalStateException("Temporary Helm Chart values file creation failed.", e);
}
ObjectMapper mapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
try {
mapper.writeValue(temp.toFile(), wildflyRelease);
} catch (IOException e) {
throw new IllegalStateException("Helm Chart values serialization failed.", e);
}
return temp;
}

List<Path> getAdditionalValuesFiles();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.jboss.intersmash.tools.provision.helm;

import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import org.jboss.intersmash.tools.application.openshift.helm.SerializableHelmChartRelease;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;

import lombok.NonNull;

/**
* An adapter that implements a valid {@link org.jboss.intersmash.tools.application.openshift.helm.HelmChartRelease} by exposing an internal generic instance of a POJO
* that represents the release data and that can be serialized to a values file, as an output for
* {@link org.jboss.intersmash.tools.application.openshift.helm.HelmChartRelease#toValuesFile()}
*/
public class HelmChartReleaseAdapter<A extends Object> implements SerializableHelmChartRelease {

protected final A adaptee;
protected final List<Path> additionalValuesFiles;

public HelmChartReleaseAdapter(@NonNull A release) {
this(release, new ArrayList<>());
}

public HelmChartReleaseAdapter(@NonNull A release, List<Path> additionalValuesFiles) {
this.adaptee = release;
this.additionalValuesFiles = additionalValuesFiles;
}

public A getAdaptee() {
return adaptee;
}

@Override
public Path toValuesFile() {
// Handle the values file creation
Path temp;
try {
temp = Files.createTempFile("values", ".yaml");
} catch (IOException e) {
throw new IllegalStateException("Temporary Helm Chart values file creation failed.", e);
}
ObjectMapper mapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
try {
mapper.writeValue(temp.toFile(), adaptee);
} catch (IOException e) {
throw new IllegalStateException("Helm Chart values serialization failed.", e);
}
return temp;
}

/**
* Implementors must generate the POJO by deserializing the data at each call and reflect the information held by
* the concrete instance
* @param valuesFileUrl Source values file URL
* @param typeClazz Deserialized POJO type
* @return A concrete instance of {@link A} generated from a source values file
*/
public A fromValuesFile(final URL valuesFileUrl, Class<A> typeClazz) {
if (valuesFileUrl == null) {
throw new IllegalStateException("No values file provided!");
}
try {
Path valuePath = Path.of(valuesFileUrl.toURI());
ObjectMapper mapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));
return mapper.readValue(valuePath.toFile(), typeClazz);
} catch (Error | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public List<Path> getAdditionalValuesFiles() {
return additionalValuesFiles;
}
}
Loading

0 comments on commit 7a14207

Please sign in to comment.