Skip to content

Commit

Permalink
Merge pull request #109 from fabiobrz/add-rhsso-template-prov
Browse files Browse the repository at this point in the history
[issue 105] - Adding the RHSSO Template provisioner
  • Loading branch information
tommaso-borgato authored Nov 21, 2023
2 parents 58cc594 + e88d246 commit 9dddd26
Show file tree
Hide file tree
Showing 14 changed files with 517 additions and 5 deletions.
1 change: 1 addition & 0 deletions .ci/openshift-ci/build-root/e2e-test-prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ mvn test -Dmaven.repo.local=./local-repo-prod -pl testsuite/ -Pts.prod \
-Dintersmash.rhsso.image=registry.redhat.io/rh-sso-7/sso76-openshift-rhel8:latest \
-Dintersmash.rhsso.operators.catalog_source=redhat-operators \
-Dintersmash.rhsso.operators.package_manifest=rhsso-operator \
-Dintersmash.rhsso.templates=https://raw.githubusercontent.com/jboss-container-images/redhat-sso-7-openshift-image/sso76-dev/templates/ \
-Dintersmash.infinispan.image=registry.redhat.io/jboss-datagrid-7/datagrid73-openshift:latest \
-Dintersmash.infinispan.operators.catalog_source=redhat-operators \
-Dintersmash.infinispan.operators.package_manifest=datagrid \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.jboss.intersmash.testsuite.provision.openshift;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand All @@ -38,12 +40,15 @@
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.RhSsoTemplateOpenShiftApplication;
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.openshift.WildflyOpenShiftUtils;
import org.jboss.intersmash.tools.application.openshift.template.RhSsoTemplate;
import org.jboss.intersmash.tools.util.ProcessKeystoreGenerator;
import org.jboss.intersmash.tools.util.wildfly.Eap7CliScriptBuilder;

import cz.xtf.builder.builders.SecretBuilder;
Expand Down Expand Up @@ -83,6 +88,56 @@ 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 RhSsoTemplateOpenShiftApplication getHttpsRhSso() {
return new RhSsoTemplateOpenShiftApplication() {
private final String secureAppHostname = "secure-" + getOpenShiftHostName();
private final Path keystore = ProcessKeystoreGenerator.generateKeystore(secureAppHostname);
private final String jceksFileName = "jgroups.jceks";
private final Path truststore = ProcessKeystoreGenerator.getTruststore();

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

@Override
public Map<String, String> getParameters() {
Map<String, String> parameters = new HashMap<>();

parameters.put("APPLICATION_NAME", getName());
parameters.put("SSO_REALM", "eap-realm");
parameters.put("SSO_SERVICE_USERNAME", "client");
parameters.put("SSO_SERVICE_PASSWORD", "creator");
parameters.put("SSO_ADMIN_USERNAME", "admin");
parameters.put("SSO_ADMIN_PASSWORD", "admin");
parameters.put("JGROUPS_CLUSTER_PASSWORD", "xpaasQEpassword");
parameters.put("IMAGE_STREAM_NAMESPACE", OpenShiftConfig.namespace());

return Collections.unmodifiableMap(parameters);
}

@Override
public List<Secret> getSecrets() {
SecretBuilder sb;
try (InputStream is = getClass().getClassLoader().getResourceAsStream("certs/jgroups.jceks")) {
sb = new SecretBuilder(getName() + "-secret")
.addData(keystore.getFileName().toString(), keystore)
.addData(jceksFileName, is)
.addData(truststore.getFileName().toString(), truststore);
} catch (IOException e) {
throw new RuntimeException(e);
}

return Collections.singletonList(sb.build());
}

@Override
public RhSsoTemplate getTemplate() {
return RhSsoTemplate.X509_HTTPS;
}
};
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.jboss.intersmash.tools.provision.openshift.MysqlImageOpenShiftProvisioner;
import org.jboss.intersmash.tools.provision.openshift.OpenShiftProvisioner;
import org.jboss.intersmash.tools.provision.openshift.PostgreSQLImageOpenShiftProvisioner;
import org.jboss.intersmash.tools.provision.openshift.RhSsoTemplateOpenShiftProvisioner;
import org.jboss.intersmash.tools.provision.openshift.WildflyBootableJarImageOpenShiftProvisioner;
import org.jboss.intersmash.tools.provision.openshift.WildflyImageOpenShiftProvisioner;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -51,7 +52,8 @@ private static Stream<OpenShiftProvisioner> provisionerProvider() {
} else if (IntersmashTestsuiteProperties.isProductizedTestExecutionProfileEnabled()) {
return Stream.of(
new WildflyImageOpenShiftProvisioner(
OpenShiftProvisionerTestBase.getWildflyOpenShiftLocalBinaryTargetServerApplication()));
OpenShiftProvisionerTestBase.getWildflyOpenShiftLocalBinaryTargetServerApplication()),
new RhSsoTemplateOpenShiftProvisioner(OpenShiftProvisionerTestBase.getHttpsRhSso()));
} else {
throw new IllegalStateException(
String.format("Unknown Intersmash test suite execution profile: %s",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.jboss.intersmash.testsuite.provision.openshift;

import org.assertj.core.api.Assertions;
import org.jboss.intersmash.testsuite.junit5.categories.NotForCommunityExecutionProfile;
import org.jboss.intersmash.tools.application.openshift.RhSsoTemplateOpenShiftApplication;
import org.jboss.intersmash.tools.provision.openshift.RhSsoTemplateOpenShiftProvisioner;
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.junit5.annotations.CleanBeforeAll;

@CleanBeforeAll
@NotForCommunityExecutionProfile
public class RhSsoTemplateTestCase {
private static final OpenShift openShift = OpenShifts.master();
private static final RhSsoTemplateOpenShiftApplication application = OpenShiftProvisionerTestBase.getHttpsRhSso();
private static final RhSsoTemplateOpenShiftProvisioner provisioner = new RhSsoTemplateOpenShiftProvisioner(application);

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

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

@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 @@ -111,8 +111,9 @@ public class IntersmashConfig {
private static final String INFINISPAN_IMAGE_URL = "intersmash.infinispan.image";

// KEYCLOAK/RHSSO
private static final String RHSSO_IMAGE_URL = "intersmash.rhsso.image";
private static final String KEYCLOAK_IMAGE_URL = "intersmash.keycloak.image";
private static final String RHSSO_IMAGE_URL = "intersmash.rhsso.image";
private static final String RHSSO_TEMPLATES = "intersmash.rhsso.templates";

// ACTIVEMQ
private static final String ACTIVEMQ_IMAGE_URL = "intersmash.activemq.image";
Expand Down Expand Up @@ -319,6 +320,10 @@ public static String rhSsoProductCode() {
return getProductCode(rhSsoImageURL());
}

public static String rhSsoTemplates() {
return XTFConfig.get(RHSSO_TEMPLATES);
}

public static String activeMQImageUrl() {
return XTFConfig.get(ACTIVEMQ_IMAGE_URL);
}
Expand Down
1 change: 1 addition & 0 deletions tools/intersmash-tools-provisioners/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class PostgresqlProvisionTest {
| Red Hat JBoss EAP 7 | :x: | :heavy_check_mark: | Eap7TemplateOpenShiftApplication | Eap7TemplateOpenShiftProvisioner | Available Git sources and template based EAP 7 s2i (legacy) build |
| Red Hat JBoss EAP 7 | :x: | :heavy_check_mark: | Eap7LegacyS2iBuildTemplateApplication | Eap7LegacyS2iBuildTemplateProvisioner | Git based EAP 7 s2i (legacy) build, used to generate image streams that can be deployed by WildflyOperatorProvisioner |
| 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) |
| Red Hat SSO 7 | :x: | :heavy_check_mark: | RhSsoTemplateOpenShiftApplication | RhSsoTemplateOpenShiftProvisioner | Allows provisioning Red Hat SSO 7.6.z based on latest templates, see https://raw.githubusercontent.com/jboss-container-images/redhat-sso-7-openshift-image/sso76-dev/templates/ |


The only thing users have to take care of is to implement the correct `Application` (see the table above) interface and
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.jboss.intersmash.tools.application.openshift;

import java.nio.file.Path;

import org.jboss.intersmash.tools.application.openshift.template.RhSsoTemplate;

/**
* End user Application interface which presents RH-SSO template application on OpenShift Container Platform.
* <p>
* RH-SSO application that is supposed to run on OpenShift needs to implement this interface.
* Usage:
* <pre>
* &#064;Appsint(
* &#064;Service(RhssoApp.class)
* })
* </pre>
* The application will be deployed by:
* <ul>
* <li>{@link RhSsoTemplateOpenShiftProvisioner}</li>
* </ul>
* <p>
* See {@link RhSsoTemplate} for available templates the
* application can represent.
*/
public interface RhSsoTemplateOpenShiftApplication extends TemplateApplication<RhSsoTemplate>, HasSecrets {

default String getName() {
return "rh-sso";
}

/**
* Realm configuration in json format for Keycloak partial import
* <p>
* https://www.keycloak.org/docs/9.0/server_admin/index.html#importing-a-realm-from-exported-json-file
* <p>
* Requires template parameters SSO_REALM, SSO_SERVICE_USERNAME, SSO_SERVICE_PASSWORD to be set
*
* @return Instance of {@link Path} representing a YAML definition for the desired realm configuration
*/
default Path getRealmConfigurationFilePath() {
return null;
}

/**
* Non x509 templates expose an HTTP route named after the application name;
* x509 templates don't expose an HTTP route;
*
* @return The service HTTP route
*/
default String getHttpRouteName() {
return getTemplate().isX509() ? null : getName();
}

/**
* Non x509 templates expose an HTTPS route named after the application name with the "secure-" prefix;
* x509 templates expose an HTTPS route named after the application name;
*
* @return The service HTTPS route
*/
default String getHttpsRouteName() {
return getTemplate().isX509() ? getName() : String.format("secure-%s", getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.jboss.intersmash.tools.application.openshift.template;

import java.util.HashMap;
import java.util.Map;

import org.jboss.intersmash.tools.provision.openshift.template.OpenShiftTemplate;

/**
* OpenShift template for RH-SSO.
* <p>
* See https://github.com/jboss-container-images/redhat-sso-7-openshift-image
*/
public enum RhSsoTemplate implements OpenShiftTemplate {
HTTPS("https"),
POSTGRESQL("postgresql"),
POSTGRESQL_PERSISTENT("postgresql-persistent"),
X509_HTTPS("x509-https"),
X509_POSTGRESQL_PERSISTENT("x509-postgresql-persistent");

private static final Map<String, RhSsoTemplate> BY_LABEL = new HashMap<>();

static {
for (RhSsoTemplate e : values()) {
BY_LABEL.put(e.label, e);
}
}

private String label;

RhSsoTemplate(String label) {
this.label = label;
}

@Override
public String getLabel() {
return label;
}

public boolean isX509() {
return label.contains("x509");
}

public static RhSsoTemplate valueOfLabel(String label) {
return BY_LABEL.get(label);
}
}
Loading

0 comments on commit 9dddd26

Please sign in to comment.