Skip to content

Commit

Permalink
Added the Uninstall test
Browse files Browse the repository at this point in the history
  • Loading branch information
jstourac committed Jan 31, 2024
1 parent e4ab9aa commit 7b67041
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/io/odh/test/OdhConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ private OdhConstants() { }
private static final String RHOAI_CONTROLLERS_NAMESPACE = "redhat-ods-applications";
private static final String RHOAI_DASHBOARD_ROUTE_NAME = "rhods-dashboard";
private static final String RHOAI_DASHBOARD_CONTROLLER = "rhods-dashboard";
private static final String RHOAI_NOTEBOOKS_NAMESPACE = "rhods-notebooks";
private static final String RHOAI_DSCI_NAME = "default-dsci";
// RHOAI OLM
private static final String RHOAI_OLM_OPERATOR_NAME = "rhods-operator";
Expand Down Expand Up @@ -68,6 +69,7 @@ private OdhConstants() { }
public static final String CONTROLLERS_NAMESPACE = getOdhOrRhoai("CONTROLLERS_NAMESPACE", ODH_CONTROLLERS_NAMESPACE, RHOAI_CONTROLLERS_NAMESPACE);
public static final String DASHBOARD_ROUTE_NAME = getOdhOrRhoai("DASHBOARD_ROUTE_NAME", ODH_DASHBOARD_ROUTE_NAME, RHOAI_DASHBOARD_ROUTE_NAME);
public static final String DASHBOARD_CONTROLLER = getOdhOrRhoai("DASHBOARD_CONTROLLER", ODH_DASHBOARD_CONTROLLER, RHOAI_DASHBOARD_CONTROLLER);
public static final String NOTEBOOKS_NAMESPACE = getOdhOrRhoai("NOTEBOOKS_NAMESPACE", ODH_CONTROLLERS_NAMESPACE, RHOAI_NOTEBOOKS_NAMESPACE);
public static final String BUNDLE_OPERATOR_NAMESPACE = getOdhOrRhoai("BUNDLE_OPERATOR_NAMESPACE", ODH_BUNDLE_OPERATOR_NAME, RHOAI_OLM_OPERATOR_NAME);
public static final String DEFAULT_DSCI_NAME = getOdhOrRhoai("DSCI_NAME", ODH_DSCI_NAME, RHOAI_DSCI_NAME);
public static final String MONITORING_NAMESPACE = getOdhOrRhoai("MONITORING_NAMESPACE", ODH_MONITORING_NAMESPACE, RHOAI_MONITORING_NAMESPACE);
Expand Down
91 changes: 91 additions & 0 deletions src/test/java/io/odh/test/e2e/standard/UninstallST.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright Skodjob authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.odh.test.e2e.standard;

import java.util.Map;

import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
import io.odh.test.OdhConstants;
import io.odh.test.TestUtils;
import io.odh.test.framework.manager.ResourceManager;
import io.odh.test.utils.DscUtils;
import io.odh.test.utils.NamespaceUtils;
import io.opendatahub.datasciencecluster.v1.DataScienceCluster;
import io.opendatahub.dscinitialization.v1.DSCInitialization;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class UninstallST extends StandardAbstract {

private static final String DS_PROJECT_NAME = "test-uninstall";
private static final String DELETE_CONFIG_MAP_NAME = "delete-self-managed-odh";
private static final String DELETE_ANNOTATION = "api.openshift.com/addon-managed-odh-delete";

/**
* Following the official Uninstallation steps for RHOAI:
* <pre>
* <a href="https://access.redhat.com/documentation/en-us/red_hat_openshift_ai_self-managed/2.5/html-single/installing_and_uninstalling_openshift_ai_self-managed/index#installing-openshift-ai-self-managed_uninstalling-openshift-ai-self-managed">Uninstalling Red Hat OpenShift AI Self-Managed by using the CLI</a>
* </pre>
*
* Known issue <a href="https://issues.redhat.com/browse/RHOAIENG-499">RHOAIENG-499</a>
*/
@Test
void testUninstallSimpleScenario() {
if (!ResourceManager.getKubeCmdClient().namespace(OdhConstants.OLM_OPERATOR_NAMESPACE)
.list("configmap").contains(DELETE_CONFIG_MAP_NAME)) {
ConfigMap cm = new ConfigMapBuilder()
.withNewMetadata()
.withName(DELETE_CONFIG_MAP_NAME)
.withNamespace(OdhConstants.OLM_OPERATOR_NAMESPACE)
.withAnnotations(Map.ofEntries(Map.entry(DELETE_ANNOTATION, "true")))
.endMetadata()
.build();
ResourceManager.getInstance().createResourceWithWait(cm);
} else {
Assertions.fail(String.format("The configmap '%s' is present on the cluster before the uninstall test started!", DELETE_CONFIG_MAP_NAME));
}

// Now the product should start to uninstall, let's wait a bit and check the result.
TestUtils.waitFor(String.format("the '%s' namespace to be removed as operator is being uninstalled",
OdhConstants.CONTROLLERS_NAMESPACE), 2000, 20000,
() -> !ResourceManager.getClient().namespaceExists(OdhConstants.CONTROLLERS_NAMESPACE));

// Let's remove the operator namespace now
ResourceManager.getKubeCmdClient().deleteNamespace(OdhConstants.OLM_OPERATOR_NAMESPACE);
NamespaceUtils.waitForNamespaceDeletion(OdhConstants.OLM_OPERATOR_NAMESPACE);

// Check that all other expected resources have been deleted
Assertions.assertTrue(ResourceManager.getKubeCmdClient().namespace(OdhConstants.OLM_OPERATOR_NAMESPACE).list(
"subscriptions").isEmpty(), "The operator subscription is still present!");
Assertions.assertFalse(ResourceManager.getClient().namespaceExists(OdhConstants.MONITORING_NAMESPACE),
String.format("Namespace '%s' hasn't been removed by the operator uninstall operation!",
OdhConstants.MONITORING_NAMESPACE));
Assertions.assertFalse(ResourceManager.getClient().namespaceExists(OdhConstants.NOTEBOOKS_NAMESPACE),
String.format("Namespace '%s' hasn't been removed by the operator uninstall operation!",
OdhConstants.NOTEBOOKS_NAMESPACE));

// Following should be removed and we actually checked above already, so maybe remove from here TODO
Assertions.assertFalse(ResourceManager.getClient().namespaceExists(OdhConstants.CONTROLLERS_NAMESPACE),
String.format("Namespace '%s' hasn't been removed by the operator uninstall operation!",
OdhConstants.CONTROLLERS_NAMESPACE));
Assertions.assertFalse(ResourceManager.getClient().namespaceExists(OdhConstants.OLM_OPERATOR_NAMESPACE),
String.format("Namespace '%s' hasn't been removed!",
OdhConstants.OLM_OPERATOR_NAMESPACE));
}

@BeforeAll
void deployDataScienceCluster() {
// Create DSCI
DSCInitialization dsci = DscUtils.getBasicDSCI();
// Create DSC
DataScienceCluster dsc = DscUtils.getBasicDSC(DS_PROJECT_NAME);

// Deploy DSCI,DSC
ResourceManager.getInstance().createResourceWithWait(dsci);
ResourceManager.getInstance().createResourceWithWait(dsc);
}
}

0 comments on commit 7b67041

Please sign in to comment.