Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[issue 123] - Implement WildFly/EAP 8 Helm Charts provisioning differentiation #124

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.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.WildflyDeploymentApplicationConfiguration;
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.HelmChartReleaseAdapter;
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 +41,7 @@ public class WildflyHelmChartExistingValuesOpenShiftExampleApplication
private final Map<String, String> setOverrides = new HashMap<>();

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

WildflyHelmChartExistingValuesOpenShiftExampleApplication addSetOverride(String name, String value) {
Expand All @@ -55,20 +54,21 @@ 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()) {
HelmWildflyRelease helmRelease = HelmChartReleaseAdapter.<HelmWildflyRelease> fromValuesFile(
this.getClass().getResource("wildfly-helm-values.yaml"), HelmWildflyRelease.class);
return new WildFlyHelmChartReleaseAdapter(helmRelease)
.withJdk17BuilderImage(IntersmashConfig.wildflyImageURL())
.withJdk17RuntimeImage(IntersmashConfig.wildflyRuntimeImageURL());
} else if (IntersmashTestsuiteProperties.isProductizedTestExecutionProfileEnabled()) {
HelmEap8Release helmRelease = HelmChartReleaseAdapter.<HelmEap8Release> fromValuesFile(
this.getClass().getResource("eap8-helm-values.yaml"), HelmEap8Release.class);
return new Eap8HelmChartReleaseAdapter(helmRelease)
.withJdk17BuilderImage(IntersmashConfig.wildflyImageURL())
.withJdk17RuntimeImage(IntersmashConfig.wildflyRuntimeImageURL());
} 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 @@ -37,9 +37,7 @@ public void basicProvisioningTest() {
final WildflyHelmChartExistingValuesOpenShiftExampleApplication application = new WildflyHelmChartExistingValuesOpenShiftExampleApplication();
application
.addSetOverride("build.uri", IntersmashConfig.deploymentsRepositoryUrl())
.addSetOverride("build.ref", IntersmashConfig.deploymentsRepositoryRef())
.addSetOverride("deploy.builderImage", application.getBuilderImage())
.addSetOverride("deployRuntimeImage", application.getRuntimeImage());
.addSetOverride("build.ref", IntersmashConfig.deploymentsRepositoryRef());

// 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,23 @@
*/
package org.jboss.intersmash.testsuite.provision.openshift;

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

import org.assertj.core.util.Strings;
import org.jboss.intersmash.deployments.IntersmashSharedDeploymentsProperties;
import org.jboss.intersmash.deployments.WildflyDeploymentApplicationConfiguration;
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 +42,15 @@ public class WildflyHelmChartOpenShiftExampleApplication
private final HelmChartRelease release;

public WildflyHelmChartOpenShiftExampleApplication() {
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";
tommaso-borgato marked this conversation as resolved.
Show resolved Hide resolved
// let's add configurable deployment additional args:
Expand All @@ -55,24 +60,21 @@ 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")
.withJdk17BuilderImage(IntersmashConfig.wildflyImageURL())
.withJdk17RuntimeImage(IntersmashConfig.wildflyRuntimeImageURL())
.withBuildEnvironmentVariable("MAVEN_ARGS_APPEND", mavenAdditionalArgs);
List<String> channelDefinition = Arrays.asList(this.eeChannelGroupId(), this.eeChannelArtifactId(),
this.eeChannelVersion());
if (!channelDefinition.isEmpty()) {
// an example of EAP channel usage, not working with EAP 7.4.x or WildFly
release.withS2iChannel(channelDefinition.stream().collect(Collectors.joining(":")));
}
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:': []
15 changes: 14 additions & 1 deletion tools/intersmash-tools-provisioners/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
<source>src/main/resources/crds</source>
<!--
This is needed to force the Java generator from CRD to stick with the original names
for enums, and avoi to uppercase them, since this could generate duplicate names,
for enums, and avoid to uppercase them, since this could generate duplicate names,
as in https://github.com/infinispan/infinispan-operator/blob/2.3.4.Final/config/crd/bases/infinispan.org_infinispans.yaml#L1473-L1477
-->
<enumUppercase>false</enumUppercase>
Expand All @@ -228,11 +228,24 @@
<goal>generate</goal>
</goals>
<configuration>
<!-- WildFly Helm Chart model is generated from JSON schema at https://github.com/wildfly/wildfly-charts/blob/wildfly-2.3.2/charts/wildfly/values.schema.json -->
<sourceDirectory>${basedir}/src/main/resources/org/jboss/intersmash/tools/provision/helm/values/schema/wildfly</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources/</outputDirectory>
<targetPackage>org.jboss.intersmash.model.helm.charts.values.wildfly</targetPackage>
</configuration>
</execution>
<execution>
<id>charts.values.generate-schema-model.eap8</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!-- JBoss EAP 8 Helm Chart model is generated from JSON schema at https://github.com/jbossas/eap-charts/blob/eap8-1.1.1/charts/eap8/values.schema.json -->
<sourceDirectory>${basedir}/src/main/resources/org/jboss/intersmash/tools/provision/helm/values/schema/eap8</sourceDirectory>
tommaso-borgato marked this conversation as resolved.
Show resolved Hide resolved
<outputDirectory>${project.build.directory}/generated-sources/</outputDirectory>
<targetPackage>org.jboss.intersmash.model.helm.charts.values.eap8</targetPackage>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
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
Expand Up @@ -100,7 +100,7 @@ public void deploy() {
@Override
public void undeploy() {
helmBinary.execute(getHelmChartUninstallArguments(this.getApplication().getName()));
OpenShiftWaiters.get(openShift, ffCheck).areExactlyNPodsReady(0, "app.kubernetes.io/instance", application.getName())
OpenShiftWaiters.get(openShift, ffCheck).areNoPodsPresent("app.kubernetes.io/instance", application.getName())
.level(Level.DEBUG)
.waitFor();
}
Expand Down
Loading