From fcd0dd92ca301507a7160d5e695bd86b7156395a Mon Sep 17 00:00:00 2001 From: Jan Stourac Date: Mon, 29 Jan 2024 17:29:36 +0100 Subject: [PATCH] Added the Uninstall test --- src/main/java/io/odh/test/OdhConstants.java | 2 + .../io/odh/test/e2e/standard/UninstallST.java | 93 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 src/test/java/io/odh/test/e2e/standard/UninstallST.java diff --git a/src/main/java/io/odh/test/OdhConstants.java b/src/main/java/io/odh/test/OdhConstants.java index 05007d1d..fe7f6bca 100644 --- a/src/main/java/io/odh/test/OdhConstants.java +++ b/src/main/java/io/odh/test/OdhConstants.java @@ -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"; @@ -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); diff --git a/src/test/java/io/odh/test/e2e/standard/UninstallST.java b/src/test/java/io/odh/test/e2e/standard/UninstallST.java new file mode 100644 index 00000000..78e27119 --- /dev/null +++ b/src/test/java/io/odh/test/e2e/standard/UninstallST.java @@ -0,0 +1,93 @@ +/* + * 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.Disabled; +import org.junit.jupiter.api.Test; + +@Disabled("Disabled because of the https://issues.redhat.com/browse/RHOAIENG-499") +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: + *
+     * Uninstalling Red Hat OpenShift AI Self-Managed by using the CLI
+     * 
+ * + * Known issue RHOAIENG-499 + */ + @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.getKubeClient().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.getKubeClient().namespaceExists(OdhConstants.MONITORING_NAMESPACE), + String.format("Namespace '%s' hasn't been removed by the operator uninstall operation!", + OdhConstants.MONITORING_NAMESPACE)); + Assertions.assertFalse(ResourceManager.getKubeClient().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.getKubeClient().namespaceExists(OdhConstants.CONTROLLERS_NAMESPACE), + String.format("Namespace '%s' hasn't been removed by the operator uninstall operation!", + OdhConstants.CONTROLLERS_NAMESPACE)); + Assertions.assertFalse(ResourceManager.getKubeClient().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); + } +}