Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tommaso-borgato committed May 16, 2023
1 parent e201f43 commit 2525685
Show file tree
Hide file tree
Showing 9 changed files with 5,478 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<version.io.strimzi-api>0.28.0</version.io.strimzi-api>
<version.com.fasterxml.jackson>2.13.1</version.com.fasterxml.jackson>
<version.io.fabric8>6.6.0</version.io.fabric8>
<version.openshift-client>5.12.2</version.openshift-client>

<!--
Version used for the activemq-artemis-operator;
Expand Down Expand Up @@ -285,6 +286,10 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</exclusion>
<exclusion>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-common</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- The following ones are used by the generated code for the Hyperfoil APIs -->
Expand Down
5 changes: 5 additions & 0 deletions testsuite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
<groupId>org.jboss.intersmash</groupId>
<artifactId>intersmash-deployments-provider</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client</artifactId>
<version>${version.openshift-client}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ public class IntersmashConfig {
private static final String PRODUCT_INFINISPAN_OPERATOR_PACKAGE_MANIFEST = "datagrid";
private static final String DEFAULT_INFINISPAN_OPERATOR_PACKAGE_MANIFEST = COMMUNITY_INFINISPAN_OPERATOR_PACKAGE_MANIFEST;
private static final String KEYCLOAK_OPERATOR_CATALOG_SOURCE_NAME = "intersmash.keycloak.operators.catalog_source";
private static final String KEYCLOAK_QUARKUS_OPERATOR_CATALOG_SOURCE_NAME = "intersmash.keycloak.quarkus.operators.catalog_source";

private static final String KEYCLOAK_OPERATOR_INDEX_IMAGE = "intersmash.keycloak.operators.index_image";
private static final String KEYCLOAK_QUARKUS_OPERATOR_INDEX_IMAGE = "intersmash.keycloak.quarkus.operators.index_image";
private static final String KEYCLOAK_OPERATOR_CHANNEL = "intersmash.keycloak.operators.channel";
private static final String KEYCLOAK_QUARKUS_OPERATOR_CHANNEL = "intersmash.keycloak.quarkus.operators.channel";
private static final String KEYCLOAK_OPERATOR_PACKAGE_MANIFEST = "intersmash.keycloak.operators.package_manifest";
private static final String KEYCLOAK_QUARKUS_OPERATOR_PACKAGE_MANIFEST = "intersmash.keycloak.quarkus.operators.package_manifest";
private static final String COMMUNITY_KEYCLOAK_OPERATOR_PACKAGE_MANIFEST = "keycloak-operator";
private static final String PRODUCT_KEYCLOAK_OPERATOR_PACKAGE_MANIFEST = "rhsso-operator";
private static final String DEFAULT_KEYCLOAK_OPERATOR_PACKAGE_MANIFEST = COMMUNITY_KEYCLOAK_OPERATOR_PACKAGE_MANIFEST;
private static final String DEFAULT_KEYCLOAK_QUARKUS_OPERATOR_PACKAGE_MANIFEST = COMMUNITY_KEYCLOAK_OPERATOR_PACKAGE_MANIFEST;
private static final String WILDFLY_OPERATOR_CATALOG_SOURCE_NAME = "intersmash.wildfly.operators.catalog_source";
private static final String WILDFLY_OPERATOR_INDEX_IMAGE = "intersmash.wildfly.operators.index_image";
private static final String WILDFLY_OPERATOR_CHANNEL = "intersmash.wildfly.operators.channel";
Expand Down Expand Up @@ -163,6 +169,10 @@ public static String keycloakOperatorPackageManifest() {
return XTFConfig.get(KEYCLOAK_OPERATOR_PACKAGE_MANIFEST, DEFAULT_KEYCLOAK_OPERATOR_PACKAGE_MANIFEST);
}

public static String keycloakOperatorQuarkusPackageManifest() {
return XTFConfig.get(KEYCLOAK_OPERATOR_PACKAGE_MANIFEST, DEFAULT_KEYCLOAK_OPERATOR_PACKAGE_MANIFEST);
}

public static String wildflyOperatorCatalogSource() {
return XTFConfig.get(WILDFLY_OPERATOR_CATALOG_SOURCE_NAME, DEFAULT_OPERATOR_CATALOG_SOURCE_NAME);
}
Expand Down Expand Up @@ -386,4 +396,20 @@ public static String getWildflyHelmChartsRepo() {
public static String getWildflyHelmChartsBranch() {
return XTFConfig.get(WILDFLY_HELM_CHARTS_BRANCH);
}

public static String keycloakQuarkusOperatorCatalogSource() {
return XTFConfig.get(KEYCLOAK_QUARKUS_OPERATOR_CATALOG_SOURCE_NAME, DEFAULT_OPERATOR_CATALOG_SOURCE_NAME);
}

public static String keycloakQuarkusOperatorIndexImage() {
return XTFConfig.get(KEYCLOAK_QUARKUS_OPERATOR_INDEX_IMAGE);
}

public static String keycloakQuarkusOperatorChannel() {
return XTFConfig.get(KEYCLOAK_QUARKUS_OPERATOR_CHANNEL);
}

public static String keycloakQuarkusOperatorPackageManifest() {
return XTFConfig.get(KEYCLOAK_QUARKUS_OPERATOR_PACKAGE_MANIFEST, DEFAULT_KEYCLOAK_QUARKUS_OPERATOR_PACKAGE_MANIFEST);
}
}
4 changes: 4 additions & 0 deletions tools/intersmash-tools-provisioners/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,13 @@
<configuration>
<target>target/generated-sources</target>
<urls>
<!-- ActiveMQ Operator -->
<url>https://raw.githubusercontent.com/artemiscloud/activemq-artemis-operator/${version.intersmash.activemq.operators}/bundle/manifests/broker.amq.io_activemqartemises.yaml</url>
<url>https://raw.githubusercontent.com/artemiscloud/activemq-artemis-operator/${version.intersmash.activemq.operators}/bundle/manifests/broker.amq.io_activemqartemisaddresses.yaml</url>
<url>https://raw.githubusercontent.com/artemiscloud/activemq-artemis-operator/${version.intersmash.activemq.operators}/bundle/manifests/broker.amq.io_activemqartemisscaledowns.yaml</url>
<!-- Keycloak Operator -->
<url>https://raw.githubusercontent.com/keycloak/keycloak-k8s-resources/21.1.1/kubernetes/keycloaks.k8s.keycloak.org-v1.yml</url>
<url>https://raw.githubusercontent.com/keycloak/keycloak-k8s-resources/21.1.1/kubernetes/keycloakrealmimports.k8s.keycloak.org-v1.yml</url>
</urls>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* 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;
import java.util.List;

import org.jboss.intersmash.tools.provision.openshift.KeycloakQuarkusOperatorProvisioner;
import org.keycloak.k8s.v2alpha1.Keycloak;
import org.keycloak.k8s.v2alpha1.KeycloakRealmImport;

/**
* End user Application interface which presents Keycloak operator application on OpenShift Container Platform.
*
* The application will be deployed by:
* <ul>
* <li>{@link KeycloakQuarkusOperatorProvisioner}</li>
* </ul>
*/
public interface KeycloakQuarkusOperatorApplication extends OperatorApplication {

Keycloak getKeycloak();

default List<KeycloakRealmImport> getKeycloakRealmImports() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/**
* 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.provision.openshift;

import cz.xtf.core.event.helpers.EventHelper;
import cz.xtf.core.waiting.failfast.FailFastCheck;
import io.fabric8.kubernetes.api.model.KubernetesResourceList;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import lombok.NonNull;
import org.assertj.core.util.Strings;
import org.jboss.intersmash.tools.IntersmashConfig;
import org.jboss.intersmash.tools.application.openshift.KeycloakQuarkusOperatorApplication;
import org.jboss.intersmash.tools.provision.openshift.operator.OperatorProvisioner;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.realm.KeycloakRealm;
import org.keycloak.k8s.v2alpha1.Keycloak;
import org.keycloak.k8s.v2alpha1.KeycloakRealmImport;

import java.util.List;
import java.util.Map;

/**
* Keycloak operator provisioner
*/
public class KeycloakQuarkusOperatorProvisioner extends OperatorProvisioner<KeycloakQuarkusOperatorApplication> {

private static final String OPERATOR_ID = IntersmashConfig.keycloakQuarkusOperatorPackageManifest();
protected FailFastCheck ffCheck = () -> false;

public KeycloakQuarkusOperatorProvisioner(@NonNull KeycloakQuarkusOperatorApplication application) {
super(application, OPERATOR_ID);
}

public static String getOperatorId() {
return OPERATOR_ID;
}

@Override
public void subscribe() {
if (Strings.isNullOrEmpty(IntersmashConfig.keycloakImageURL())) {
super.subscribe();
} else {
// RELATED_IMAGE_RHSSO_OPENJ9 and RELATED_IMAGE_RHSSO_OPENJDK, determine the final value for RELATED_IMAGE_RHSSO
subscribe(
INSTALLPLAN_APPROVAL_MANUAL,
Map.of(
"RELATED_IMAGE_RHSSO", IntersmashConfig.keycloakImageURL(),
"PROFILE", "RHSSO"));
}
}

@Override
public void deploy() {
ffCheck = FailFastUtils.getFailFastCheck(EventHelper.timeOfLastEventBMOrTestNamespaceOrEpoch(),
getApplication().getName());
// Keycloak Operator codebase contains the name of the Keycloak image to deploy: user can override Keycloak image to
// deploy using environment variables in Keycloak Operator Subscription
subscribe();

// create custom resources
keycloakClient().createOrReplace(getApplication().getKeycloak());
if (getApplication().getKeycloakRealmImports().size() > 0)
keycloakRealmImportClient().createOrReplace(getApplication().getKeycloakRealmImports().stream().toArray(KeycloakRealmImport[]::new));
}

@Override
public void undeploy() {

}

@Override
public List<Pod> getPods() {
return null;
}

@Override
public void scale(int replicas, boolean wait) {

}

@Override
protected String getOperatorCatalogSource() {
return IntersmashConfig.keycloakQuarkusOperatorCatalogSource();
}

@Override
protected String getOperatorIndexImage() {
return IntersmashConfig.keycloakQuarkusOperatorIndexImage();
}

@Override
protected String getOperatorChannel() {
return IntersmashConfig.keycloakQuarkusOperatorChannel();
}

public MixedOperation<Keycloak, KubernetesResourceList<Keycloak>, Resource<Keycloak>> keycloakClient() {
try (KubernetesClient kubernetesClient = new DefaultKubernetesClient()) {
MixedOperation<Keycloak, KubernetesResourceList<Keycloak>, Resource<Keycloak>> keycloakClient = kubernetesClient
.resources(Keycloak.class);
return keycloakClient;
}
}

public MixedOperation<KeycloakRealmImport, KubernetesResourceList<KeycloakRealmImport>, Resource<KeycloakRealmImport>> keycloakRealmImportClient() {
try (KubernetesClient kubernetesClient = new DefaultKubernetesClient()) {
MixedOperation<KeycloakRealmImport, KubernetesResourceList<KeycloakRealmImport>, Resource<KeycloakRealmImport>> keycloakRealmImportClient = kubernetesClient
.resources(KeycloakRealmImport.class);
return keycloakRealmImportClient;
}
}


/*
try (KubernetesClient kubernetesClient = new DefaultKubernetesClient()) {
OpenShiftClient oClient = kubernetesClient.adapt(OpenShiftClient.class);
MixedOperation<Keycloak, KubernetesResourceList<Keycloak>, Resource<Keycloak>> keycloakClient = kubernetesClient
.resources(Keycloak.class);
keycloakClient.inNamespace(OpenShiftConfig.namespace()).list();
MixedOperation<KeycloakRealmImport, KubernetesResourceList<KeycloakRealmImport>, Resource<KeycloakRealmImport>> keycloakRealmImportClient = kubernetesClient
.resources(KeycloakRealmImport.class);
keycloakRealmImportClient.inNamespace(OpenShiftConfig.namespace()).list();
}
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* 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.provision.openshift;

import org.jboss.intersmash.tools.application.Application;
import org.jboss.intersmash.tools.application.openshift.KeycloakQuarkusOperatorApplication;
import org.jboss.intersmash.tools.provision.ProvisionerFactory;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class KeycloakQuarkusOperatorProvisionerFactory implements ProvisionerFactory<KeycloakQuarkusOperatorProvisioner> {

@Override
public KeycloakQuarkusOperatorProvisioner getProvisioner(Application application) {
if (KeycloakQuarkusOperatorApplication.class.isAssignableFrom(application.getClass()))
return new KeycloakQuarkusOperatorProvisioner((KeycloakQuarkusOperatorApplication) application);
return null;
}
}
Loading

0 comments on commit 2525685

Please sign in to comment.