Skip to content

Commit

Permalink
Add option for skip install operator (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
kornys authored Jan 11, 2024
1 parent 26a1d6b commit b90eb62
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
17 changes: 9 additions & 8 deletions src/main/java/io/odh/test/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,23 @@ public class Environment {

private static final Logger LOGGER = LoggerFactory.getLogger(Environment.class);
private static final Map<String, String> VALUES = new HashMap<>();

private static String config;

private static final Map<String, Object> YAML_DATA = loadConfigurationFile();

public static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm");

public static final String USER_PATH = System.getProperty("user.dir");

private static final String CONFIG_FILE_PATH_ENV = "ENV_FILE";

private static final String USERNAME_ENV = "KUBE_USERNAME";
private static final String PASSWORD_ENV = "KUBE_PASSWORD";
private static final String TOKEN_ENV = "KUBE_TOKEN";
private static final String URL_ENV = "KUBE_URL";
private static final String PRODUCT_ENV = "PRODUCT";

private static final String LOG_DIR_ENV = "LOG_DIR";

/**
* Install operator odh/rhoai
*/
private static final String SKIP_INSTALL_OPERATOR_ENV = "SKIP_INSTALL_OPERATOR";

/**
* Install bundle files
*/
Expand Down Expand Up @@ -76,6 +74,9 @@ public class Environment {
public static final String KUBE_TOKEN = getOrDefault(TOKEN_ENV, null);
public static final String KUBE_URL = getOrDefault(URL_ENV, null);

//Install
public static final boolean SKIP_INSTALL_OPERATOR = getOrDefault(SKIP_INSTALL_OPERATOR_ENV, Boolean::valueOf, false);

// YAML Bundle
public static final String INSTALL_FILE_PATH = getOrDefault(INSTALL_FILE_ENV, TestConstants.LATEST_BUNDLE_DEPLOY_FILE);
public static final String INSTALL_FILE_PREVIOUS_PATH = getOrDefault(INSTALL_FILE_RELEASED_ENV, TestConstants.RELEASED_BUNDLE_DEPLOY_FILE);
Expand Down Expand Up @@ -128,7 +129,7 @@ private static <T> T getOrDefault(String var, Function<String, T> converter, T d
}

private static Map<String, Object> loadConfigurationFile() {
config = System.getenv().getOrDefault(CONFIG_FILE_PATH_ENV,
String config = System.getenv().getOrDefault(CONFIG_FILE_PATH_ENV,
Paths.get(System.getProperty("user.dir"), "config.yaml").toAbsolutePath().toString());
Yaml yaml = new Yaml();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package io.odh.test.framework.listeners;

import io.odh.test.Environment;
import io.odh.test.platform.KubeUtils;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
Expand All @@ -12,6 +13,8 @@ public class OdhResourceCleaner implements AfterAllCallback {

@Override
public void afterAll(ExtensionContext extensionContext) {
KubeUtils.clearOdhRemainingResources();
if (!Environment.SKIP_INSTALL_OPERATOR) {
KubeUtils.clearOdhRemainingResources();
}
}
}
31 changes: 14 additions & 17 deletions src/test/java/io/odh/test/e2e/standard/StandardAbstract.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
import io.odh.test.e2e.Abstract;
import io.odh.test.framework.listeners.OdhResourceCleaner;
import io.odh.test.framework.listeners.ResourceManagerDeleteHandler;
import io.odh.test.framework.manager.ResourceManager;
import io.odh.test.install.BundleInstall;
import io.odh.test.install.InstallTypes;
import io.odh.test.install.OlmInstall;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -34,22 +32,21 @@ public abstract class StandardAbstract extends Abstract {

@BeforeAll
void setupEnvironment() throws IOException {
if (Environment.OPERATOR_INSTALL_TYPE.toLowerCase(Locale.ENGLISH)
.equals(InstallTypes.OLM.toString().toLowerCase(Locale.ENGLISH))) {
OlmInstall olmInstall = new OlmInstall();
olmInstall.create();
} else if (Environment.OPERATOR_INSTALL_TYPE.toLowerCase(Locale.ENGLISH)
.equals(InstallTypes.BUNDLE.toString().toLowerCase(Locale.ENGLISH))) {
BundleInstall bundleInstall = new BundleInstall();
bundleInstall.create();
if (Environment.SKIP_INSTALL_OPERATOR) {
LOGGER.info("Operator install is skipped: SKIP_OPERATOR_INSTALL: {}", Environment.SKIP_INSTALL_OPERATOR);
} else {
LOGGER.error("Unknown install type {}! You should implement it at first!", Environment.OPERATOR_INSTALL_TYPE);
fail(String.format("Unknown install type %s! You should implement it at first!", Environment.OPERATOR_INSTALL_TYPE));
if (Environment.OPERATOR_INSTALL_TYPE.toLowerCase(Locale.ENGLISH)
.equals(InstallTypes.OLM.toString().toLowerCase(Locale.ENGLISH))) {
OlmInstall olmInstall = new OlmInstall();
olmInstall.create();
} else if (Environment.OPERATOR_INSTALL_TYPE.toLowerCase(Locale.ENGLISH)
.equals(InstallTypes.BUNDLE.toString().toLowerCase(Locale.ENGLISH))) {
BundleInstall bundleInstall = new BundleInstall();
bundleInstall.create();
} else {
LOGGER.error("Unknown install type {}! You should implement it at first!", Environment.OPERATOR_INSTALL_TYPE);
fail(String.format("Unknown install type %s! You should implement it at first!", Environment.OPERATOR_INSTALL_TYPE));
}
}
}

@AfterAll
void teardownEnvironment() {
ResourceManager.getInstance().deleteResources();
}
}

0 comments on commit b90eb62

Please sign in to comment.