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

[] - Add a JUnit 5 extension to handle the setup of Open Data Hub/OpenShift AI operator prerequisites in case of unmanaged installation #188

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
17 changes: 17 additions & 0 deletions core/src/main/java/org/jboss/intersmash/IntersmashConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ public class IntersmashConfig {
private static final String MYSQL_IMAGE_URL = "intersmash.mysql.image";
private static final String PGSQL_IMAGE_URL = "intersmash.postgresql.image";

// OpenShift AI (Experimental)
private static final String OPEN_DATA_HUB_INSTALL_MODE = "intersmash.ai.odh.install.mode";
public static final String OPEN_DATA_HUB_INSTALL_MODE_MANAGED = "managed";
public static final String OPEN_DATA_HUB_INSTALL_MODE_UNMANAGED = "unmanaged";
private static final String OPEN_DATA_HUB_INSTALL_MODE_DEFAULT = OPEN_DATA_HUB_INSTALL_MODE_MANAGED;
private static final String OPEN_DATA_HUB_INSTALL_MODE_UNMANAGED_CLASS_FQDN = "intersmash.ai.odh.install.unmanaged.class";
private static final String OPEN_DATA_HUB_INSTALL_MODE_UNMANAGED_CLASS_FQDN_DEFAULT = "org.jboss.intersmash.provision.ai.OpenDataHubDefaultPrerequisitesProvisioner";

public static boolean skipDeploy() {
return XTFConfig.get(SKIP_DEPLOY, "false").equals("true");
}
Expand Down Expand Up @@ -402,4 +410,13 @@ public static String keycloakOperatorChannel() {
public static String keycloakOperatorPackageManifest() {
return XTFConfig.get(KEYCLOAK_OPERATOR_PACKAGE_MANIFEST, DEFAULT_KEYCLOAK_OPERATOR_PACKAGE_MANIFEST);
}

public static String openDataHubInstallMode() {
return XTFConfig.get(OPEN_DATA_HUB_INSTALL_MODE, OPEN_DATA_HUB_INSTALL_MODE_DEFAULT);
}

public static String openDataHubUnmanagedInstallClass() {
return XTFConfig.get(OPEN_DATA_HUB_INSTALL_MODE_UNMANAGED_CLASS_FQDN,
OPEN_DATA_HUB_INSTALL_MODE_UNMANAGED_CLASS_FQDN_DEFAULT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Copyright (C) 2024 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.junit5;

import java.io.IOException;

import org.jboss.intersmash.IntersmashConfig;
import org.jboss.intersmash.provision.ai.OpenDataHubSetupManager;
import org.junit.platform.launcher.TestExecutionListener;
import org.junit.platform.launcher.TestPlan;

import cz.xtf.core.config.OpenShiftConfig;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class OpenDataHubExtension implements TestExecutionListener {
protected static boolean handleOpenDataHubSetup = IntersmashConfig.OPEN_DATA_HUB_INSTALL_MODE_UNMANAGED.equals(
IntersmashConfig.openDataHubUnmanagedInstallClass());

@Override
public void testPlanExecutionStarted(TestPlan testPlan) {
if (handleOpenDataHubSetup) {
// Let the ODH Manager place a subscription to track that this session is handled.
// Note: the configured test namespace is used as identifier, so this might not be reliable in case
// a namespace is reused
try {
OpenDataHubSetupManager.getInstance().subscribe(OpenShiftConfig.namespace());
} catch (IOException e) {
throw new IllegalStateException("Cannot subscribe to the Intersmash Open Data Hub manager: " + e);
}
// deploy pre-requisites
try {
if (!OpenDataHubSetupManager.getInstance().isReady() && !OpenDataHubSetupManager.getInstance().isInstalling()) {
OpenDataHubSetupManager.getInstance().setup();
}
} catch (IOException e) {
throw new IllegalStateException("Cannot deploy Open Data Hub prerequisites: " + e);
}
}
}

@Override
public void testPlanExecutionFinished(TestPlan testPlan) {
if (handleOpenDataHubSetup) {
// Let the ODH Manager remove the subscription that tracks that this session is handled.
// Note: the configured test namespace is used as identifier, so this might not be reliable in case
// a namespace is reused
try {
OpenDataHubSetupManager.getInstance().unsubscribe(OpenShiftConfig.namespace());
} catch (IOException e) {
throw new IllegalStateException(
"Cannot remove a subscription from the Intersmash the Open Data Hub manager: " + e);
}
// undeploy pre-requisites, as long as there are no more subscribers
try {
if (OpenDataHubSetupManager.getInstance().getSubscribers().isEmpty()
&& !OpenDataHubSetupManager.getInstance().isInstalling()) {
OpenDataHubSetupManager.getInstance().tearDown();
}
} catch (IOException e) {
throw new IllegalStateException("Cannot undeploy Open Data Hub prerequisites: " + e);
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Copyright (C) 2024 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.provision.ai;

/**
* Provisioner for deploying and undeploying Open Data Hub prerequisites
*/
public interface OpenDataHubPrerequisitesProvisioner {
/**
* Task which will be performed by a provisioner prior to {@link #deploy()} operation.
*/
default void preDeploy() {
}

/**
* Deploy the application.
*/
void deploy();

/**
* Undeploy the application.
*/
void undeploy();

/**
* Task which will be performed by a provisioner after the {@link #undeploy()} operation.
*/
default void postUndeploy() {
}

/**
* Defines an operation for configuring the provisioner, before any deployment related tasks are executed, e.g.:
* for Operator based provisioners this allows for configuring custom catalog sources etc.
*/
default void configure() {
}

/**
* Defines an operation for configuring the provisioner, after all deploy related tasks are executed, e.g.:
* for Operator based provisioners this allows for removing custom catalog sources etc.
*/
default void dismiss() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (C) 2024 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.provision.ai;

public interface OpenDataHubPrerequisitesProvisionerFactory<T extends OpenDataHubPrerequisitesProvisioner> {

default Integer getOrder() {
return 0;
}

/**
* @param fqdn Fully Qualified DOmain Name of the provisioner class that should be looked up and used to
* provision ODH prerequisites
* @return provisioner for the given FQDN or null
*/
T getProvisioner(final String fqdn);
}
Loading