Skip to content

Commit

Permalink
Merge pull request #104 from fabiobrz/add-eap7-provisioners.template
Browse files Browse the repository at this point in the history
[issue 80] - Adding EAP 7.z template provisioner
  • Loading branch information
tommaso-borgato authored Nov 8, 2023
2 parents f78b31e + 167a22a commit f821c23
Show file tree
Hide file tree
Showing 20 changed files with 773 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .ci/openshift-ci/build-root/e2e-test-prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ mvn test -Dmaven.repo.local=./local-repo-prod -pl testsuite/ -Pts.prod \
-Dintersmash.wildfly.helm.charts.name=eap8 \
-Dintersmash.eap7.image=registry.redhat.io/jboss-eap-7/eap74-openjdk17-openshift-rhel8:latest \
-Dintersmash.eap7.runtime.image=registry.redhat.io/jboss-eap-7/eap74-openjdk17-runtime-openshift-rhel8:latest \
-Dintersmash.eap7.templates.base.url=https://raw.githubusercontent.com/jboss-container-images/jboss-eap-openshift-templates/eap74/ \
-Dintersmash.eap7.templates.path=templates/ \
-Dintersmash.activemq.image=registry.redhat.io/amq7/amq-broker-rhel8:7.11.0 \
-Dintersmash.activemq.init.image=registry.redhat.io/amq7/amq-broker-init-rhel8:7.11.0 \
-Dintersmash.activemq.operators.catalog_source=redhat-operators \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ Mapping of implemented provisioners:
| Wildfly & Red Hat JBoss EAP 8 | :heavy_check_mark: | :heavy_check_mark: | WildflyHelmChartOpenShiftApplication | WildflyHelmChartOpenShiftProvisioner | The `wildfly-2.3.2` tag of https://github.com/wildfly/wildfly-charts is used and the model is generated based on the https://raw.githubusercontent.com/wildfly/wildfly-charts/main/charts/wildfly/values.schema.json value schema file |
| Wildfly & Red Hat JBoss EAP 7/8 | :heavy_check_mark: | :heavy_check_mark: | WildflyOperatorApplication | WildflyOperatorProvisioner | Operator based provisioner, see details [below](#operator-based-provisioning) |
| Red Hat JBoss EAP 7 | :x: | :heavy_check_mark: | Eap7ImageOpenShiftApplication | Eap7ImageOpenShiftProvisioner | Available both for Git sources and binary based EAP 7 s2i (legacy) build, i.e. based on a pre-built deployment (i.e. a _WAR archive_) |
| Red Hat JBoss EAP 7 | :x: | :heavy_check_mark: | Eap7TemplateOpenShiftApplication | Eap7TemplateOpenShiftProvisioner | Available Git sources and template based EAP 7 s2i (legacy) build |
| Red Hat SSO 7 | :x: | :heavy_check_mark: | RhSsoOperatorApplication | RhSsoOperatorProvisioner | Based on the archived Keycloak operator project, which contains the latest Red Hat SSO 7.z CRDs definitions, see details [below](#operator-based-provisioning) |


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/**
* Copyright (C) 2023 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.intersmash.deployments.examples;

import javax.inject.Inject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/**
* Copyright (C) 2023 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.intersmash.testsuite;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/**
* Copyright (C) 2023 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.intersmash.testsuite.junit5.categories;

import java.lang.annotation.Retention;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/**
* Copyright (C) 2023 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.intersmash.testsuite.junit5.categories;

import java.lang.annotation.Retention;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/**
* Copyright (C) 2023 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.intersmash.testsuite.provision.openshift;

import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* Copyright (C) 2023 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.intersmash.testsuite.provision.openshift;

import java.util.Optional;

import org.assertj.core.api.Assertions;
import org.assertj.core.api.SoftAssertions;
import org.jboss.intersmash.testsuite.junit5.categories.NotForCommunityExecutionProfile;
import org.jboss.intersmash.tools.application.openshift.Eap7TemplateOpenShiftApplication;
import org.jboss.intersmash.tools.provision.openshift.Eap7TemplateOpenShiftProvisioner;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import cz.xtf.core.openshift.OpenShift;
import cz.xtf.core.openshift.OpenShifts;
import cz.xtf.core.openshift.PodShell;
import cz.xtf.core.openshift.PodShellOutput;
import cz.xtf.junit5.annotations.CleanBeforeAll;
import io.fabric8.openshift.api.model.BuildConfig;
import io.fabric8.openshift.api.model.GitBuildSource;

@CleanBeforeAll
@NotForCommunityExecutionProfile
public class Eap7TemplateProvisionerTestCase {
private static final OpenShift openShift = OpenShifts.master();
private static final Eap7TemplateOpenShiftApplication application = OpenShiftProvisionerTestBase
.getEap7OpenShiftTemplateApplication();
private static final Eap7TemplateOpenShiftProvisioner provisioner = new Eap7TemplateOpenShiftProvisioner(application);

@BeforeAll
public static void deploy() {
provisioner.preDeploy();
provisioner.deploy();
}

@AfterAll
public static void undeploy() {
provisioner.undeploy();
provisioner.postUndeploy();
}

@Test
public void verifyEapConfiguration() {
SoftAssertions softAssertions = new SoftAssertions();
// verify system property added via cli
PodShell rsh = new PodShell(openShift, openShift.getAnyPod(application.getName()));
PodShellOutput output = rsh
.executeWithBash(String.format("$JBOSS_HOME/bin/jboss-cli.sh -c /system-property=%s:read-resource",
OpenShiftProvisionerTestBase.WILDFLY_TEST_PROPERTY));
softAssertions.assertThat(output.getError()).as("CLI configuration check: Error should be empty").isEmpty();
softAssertions.assertThat(output.getOutput()).as("CLI configuration check: Test property was not set by CLI")
.contains("success", OpenShiftProvisionerTestBase.WILDFLY_TEST_PROPERTY);

// verify application git
Optional<BuildConfig> gitBuildConfig = openShift.buildConfigs().list().getItems().stream()
.filter(buildConfig -> buildConfig.getSpec().getSource().getType().equals("Git"))
.findFirst();
softAssertions.assertThat(gitBuildConfig.isPresent()).as("Cannot find a Git build config").isTrue();
if (gitBuildConfig.isPresent()) {
softAssertions.assertThat(gitBuildConfig.get().getMetadata().getName()).contains(application.getName());
GitBuildSource git = gitBuildConfig.get().getSpec().getSource().getGit();
softAssertions.assertThat(git.getUri()).as("Git repository check")
.isEqualTo(OpenShiftProvisionerTestBase.EAP7_TEST_APP_REPO);
softAssertions.assertThat(git.getRef()).as("Git repository reference check")
.isEqualTo(OpenShiftProvisionerTestBase.EAP7_TEST_APP_REF);
}
softAssertions.assertAll();
}

/**
* Any {@code Secret} or {@code ConfigMap} should be created as a preDeploy() operation by a provisioner.
*/
@Test
public void verifyDeployHooks() {
Assertions.assertThat(openShift.getSecret(OpenShiftProvisionerTestBase.TEST_SECRET.getMetadata().getName()))
.isNotNull();
}

@Test
public void scale() {
provisioner.scale(1, true);
openShift.waiters().areExactlyNPodsReady(1, application.getName()).waitFor();
provisioner.scale(2, true);
openShift.waiters().areExactlyNPodsReady(2, application.getName()).waitFor();
}

@Test
public void pods() {
provisioner.scale(2, true);
Assertions.assertThat(provisioner.getPods().size()).isEqualTo(2);
provisioner.scale(3, true);
Assertions.assertThat(provisioner.getPods().size()).isEqualTo(3);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
import org.jboss.intersmash.tools.IntersmashConfig;
import org.jboss.intersmash.tools.application.openshift.BootableJarOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.Eap7ImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.Eap7TemplateOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.KafkaOperatorApplication;
import org.jboss.intersmash.tools.application.openshift.MysqlImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.PostgreSQLImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.WildflyImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.input.BinarySource;
import org.jboss.intersmash.tools.application.openshift.input.BuildInput;
import org.jboss.intersmash.tools.application.openshift.input.BuildInputBuilder;
import org.jboss.intersmash.tools.application.openshift.template.Eap7Template;
import org.jboss.intersmash.tools.util.wildfly.Eap7CliScriptBuilder;

import cz.xtf.builder.builders.SecretBuilder;
Expand Down Expand Up @@ -78,6 +80,44 @@ public class OpenShiftProvisionerTestBase {
static final String EAP7_TEST_APP_REPO = "https://github.com/openshift/openshift-jee-sample.git";
static final String EAP7_TEST_APP_REF = "master";

static Eap7TemplateOpenShiftApplication getEap7OpenShiftTemplateApplication() {
return new Eap7TemplateOpenShiftApplication() {

@Override
public List<String> getCliScript() {
Eap7CliScriptBuilder eapCliScriptBuilder = new Eap7CliScriptBuilder();
eapCliScriptBuilder.addCommand(
String.format("/system-property=%s:add(value=\"%s\")", WILDFLY_TEST_PROPERTY, WILDFLY_TEST_PROPERTY));
return eapCliScriptBuilder.build();
}

@Override
public Map<String, String> getParameters() {
Map<String, String> map = new HashMap<>();
map.put("SOURCE_REPOSITORY_URL", EAP7_TEST_APP_REPO);
map.put("SOURCE_REPOSITORY_REF", EAP7_TEST_APP_REF);
return Collections.unmodifiableMap(map);
}

@Override
public List<Secret> getSecrets() {
List<Secret> secrets = new ArrayList<>();
secrets.add(TEST_SECRET);
return Collections.unmodifiableList(secrets);
}

@Override
public Eap7Template getTemplate() {
return Eap7Template.BASIC;
}

@Override
public String getName() {
return "eap-test-app";
}
};
}

static BootableJarOpenShiftApplication getWildflyBootableJarOpenShiftApplication() {
return new BootableJarOpenShiftApplication() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public class IntersmashConfig {
// EAP 7.z (i.e. Jakarta EE 8 based WildFly)
private static final String EAP7_IMAGE_URL = "intersmash.eap7.image";
private static final String EAP7_RUNTIME_IMAGE_URL = "intersmash.eap7.runtime.image";
private static final String EAP7_TEMPLATES_BASE_URL = "intersmash.eap7.templates.base.url";
private static final String EAP7_TEMPLATES_PATH = "intersmash.eap7.templates.path";

// WildFLy Maven Plugin
private static final String WILDFLY_MAVEN_PLUGIN_GROUPID = "wildfly-maven-plugin.groupId";
Expand Down Expand Up @@ -257,8 +259,23 @@ public static String eap7RuntimeImageUrl() {
return XTFConfig.get(EAP7_RUNTIME_IMAGE_URL);
}

public static String wildflyJakartaEe8ProductCode() {
return getProductCode(eap7ImageURL());
public static String eap7ProductCode() {
final String image = eap7ImageURL();
if (image.matches(".*eap-xp\\d+.*")) {
return image.replaceFirst(".*eap-xp(\\d+).*", "eap-xp$1");
} else if (image.matches(".*eap\\d\\d.*")) {
return image.replaceFirst(".*eap(\\d\\d?).*", "eap$1");
} else {
return IntersmashConfig.getProductCode(image);
}
}

public static String eap7Templates() {
return XTFConfig.get(EAP7_TEMPLATES_BASE_URL) + XTFConfig.get(EAP7_TEMPLATES_PATH);
}

public static String eap7ImageStreams() {
return XTFConfig.get(EAP7_TEMPLATES_BASE_URL);
}

public static String getProductCode(final String image) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import cz.xtf.core.openshift.OpenShifts;
import io.fabric8.openshift.api.model.ImageStream;
import io.fabric8.openshift.api.model.Template;
import io.fabric8.openshift.client.dsl.TemplateResource;

/**
* Provisioner for OpenShift templates. Its goal is to unify the basic operations we need to do with OpenShift templates.
Expand Down Expand Up @@ -62,7 +61,7 @@ default String getTemplateFileUrl(OpenShiftTemplate openShiftTemplate) {

/**
* Get a template file name format. Having a template name (e.g. "basic") is not sufficient, as the actual template
* file name could differ between products (e.g. "datagrid73-basic.json" VS "eap73-basic-s2i.json").
* file name could differ between products.
*
* @param openShiftTemplate template
* @return file name of template source file
Expand Down Expand Up @@ -91,7 +90,7 @@ default Template deployTemplate(OpenShiftTemplate openShiftTemplate) {
String url = getTemplateFileUrl(openShiftTemplate);
try (InputStream is = new URL(url).openStream()) {
// workaround for the API version in the data (v1) does not match the expected API version (image.template.io/v1)
template = (Template) ((TemplateResource) openShift.templates().load(is)).get();
template = openShift.templates().load(is).item();
template.setApiVersion("template.openshift.io/v1");
if (openShift.getTemplate(template.getMetadata().getName()) == null) {
openShift.createTemplate(template);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/**
* Copyright (C) 2023 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.intersmash.tools.application.openshift;

import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (C) 2023 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.intersmash.tools.application.openshift;

import org.jboss.intersmash.tools.application.openshift.template.Eap7Template;
import org.jboss.intersmash.tools.provision.openshift.Eap7TemplateOpenShiftProvisioner;

/**
* End user Application descriptor interface which presents EAP 7 template application on OpenShift Container Platform.
*
* See {@link Eap7Template} for available templates the
* application can represent.
*
* The application will be deployed by:
* <ul>
* <li>{@link Eap7TemplateOpenShiftProvisioner}</li>
* </ul>
*/
public interface Eap7TemplateOpenShiftApplication
extends WildflyOpenShiftApplication, TemplateApplication<Eap7Template> {

}
Loading

0 comments on commit f821c23

Please sign in to comment.