From df7a556f629f2410f37466c184590eca06df7414 Mon Sep 17 00:00:00 2001 From: Jakub Stejskal Date: Thu, 7 Dec 2023 15:08:20 +0100 Subject: [PATCH 1/3] Add upgrade tests for OLM Signed-off-by: Jakub Stejskal --- src/main/java/io/odh/test/OdhConstants.java | 20 +++ src/main/java/io/odh/test/TestConstants.java | 1 + .../java/io/odh/test/install/OlmInstall.java | 18 ++- .../java/io/odh/test/platform/KubeClient.java | 24 ++++ .../io/odh/test/utils/DeploymentUtils.java | 45 +++++++ src/main/java/io/odh/test/utils/PodUtils.java | 46 +++++++ .../test/e2e/standard/StandardAbstract.java | 2 +- .../io/odh/test/e2e/upgrade/OlmUpgradeST.java | 127 ++++++++++++++++++ .../odh/test/e2e/upgrade/UpgradeAbstract.java | 21 +++ 9 files changed, 302 insertions(+), 2 deletions(-) create mode 100644 src/main/java/io/odh/test/OdhConstants.java create mode 100644 src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java create mode 100644 src/test/java/io/odh/test/e2e/upgrade/UpgradeAbstract.java diff --git a/src/main/java/io/odh/test/OdhConstants.java b/src/main/java/io/odh/test/OdhConstants.java new file mode 100644 index 00000000..ca170ef9 --- /dev/null +++ b/src/main/java/io/odh/test/OdhConstants.java @@ -0,0 +1,20 @@ +/* + * 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; + +public class OdhConstants { + public static final String CODEFLARE_DEPLOYMENT_NAME = "codeflare-operator-manager"; + public static final String DS_PIPELINES_OPERATOR = "data-science-pipelines-operator-controller-manager"; + public static final String ETCD = "etcd"; + public static final String KSERVE_OPERATOR = "kserve-controller-manager"; + public static final String KUBERAY_OPERATOR = "kuberay-operator"; + public static final String MODELMESH_OPERATOR = "modelmesh-controller"; + public static final String NOTEBOOK_OPERATOR = "notebook-controller-deployment"; + public static final String ODH_DASHBOARD = "odh-dashboard"; + public static final String ODH_MODEL_OPERATOR = "odh-model-controller"; + public static final String ODH_NOTEBOOK_OPERATOR = "odh-notebook-controller-manager"; + public static final String TRUSTY_AI_OPERATOR = "trustyai-service-operator-controller-manager"; + +} diff --git a/src/main/java/io/odh/test/TestConstants.java b/src/main/java/io/odh/test/TestConstants.java index 91c1d563..6e916474 100644 --- a/src/main/java/io/odh/test/TestConstants.java +++ b/src/main/java/io/odh/test/TestConstants.java @@ -20,6 +20,7 @@ public class TestConstants { public static final long GLOBAL_POLL_INTERVAL_MEDIUM = Duration.ofSeconds(5).toMillis(); public static final long GLOBAL_POLL_INTERVAL_SHORT = Duration.ofSeconds(1).toMillis(); public static final long GLOBAL_TIMEOUT = Duration.ofMinutes(5).toMillis(); + public static final long GLOBAL_STABILITY_TIME = Duration.ofSeconds(10).toSeconds(); private TestConstants() { } diff --git a/src/main/java/io/odh/test/install/OlmInstall.java b/src/main/java/io/odh/test/install/OlmInstall.java index 51baa53a..a47e3781 100644 --- a/src/main/java/io/odh/test/install/OlmInstall.java +++ b/src/main/java/io/odh/test/install/OlmInstall.java @@ -34,6 +34,8 @@ public class OlmInstall { private String operatorVersion = Environment.OLM_OPERATOR_VERSION; private String csvName = operatorName + ".v" + operatorVersion; + private String approval = "Automatic"; + public void create() { createOperatorGroup(); ResourceManager.getInstance().pushToStack(new ResourceItem(this::deleteCSV)); @@ -43,6 +45,12 @@ public void create() { DeploymentUtils.waitForDeploymentReady(namespace, deploymentName); } + public void createManual() { + createOperatorGroup(); + ResourceManager.getInstance().pushToStack(new ResourceItem(this::deleteCSV)); + createAndModifySubscription(); + } + /** * Creates OperatorGroup in specific namespace */ @@ -89,7 +97,7 @@ public Subscription prepareSubscription() { .withSourceNamespace(sourceNamespace) .withChannel(channel) .withStartingCSV(startingCsv) - .withInstallPlanApproval("Automatic") + .withInstallPlanApproval(approval) .editOrNewConfig() .endConfig() .endSpec() @@ -155,4 +163,12 @@ public String getCsvName() { public void setCsvName(String csvName) { this.csvName = csvName; } + + public String getApproval() { + return approval; + } + + public void setApproval(String approval) { + this.approval = approval; + } } diff --git a/src/main/java/io/odh/test/platform/KubeClient.java b/src/main/java/io/odh/test/platform/KubeClient.java index 97cde87a..80f26cde 100644 --- a/src/main/java/io/odh/test/platform/KubeClient.java +++ b/src/main/java/io/odh/test/platform/KubeClient.java @@ -23,6 +23,8 @@ import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.RollableScalableResource; +import io.fabric8.openshift.api.model.operatorhub.v1alpha1.InstallPlan; +import io.fabric8.openshift.api.model.operatorhub.v1alpha1.InstallPlanBuilder; import io.fabric8.openshift.client.OpenShiftClient; import io.odh.test.Environment; import io.opendatahub.datasciencecluster.v1.DataScienceCluster; @@ -345,6 +347,28 @@ public String getDeploymentNameByPrefix(String namespace, String namePrefix) { } } + public InstallPlan getInstallPlan(String namespaceName, String installPlanName) { + return client.adapt(OpenShiftClient.class).operatorHub().installPlans().inNamespace(namespaceName).withName(installPlanName).get(); + } + + public void approveInstallPlan(String namespaceName, String installPlanName) { + InstallPlan installPlan = new InstallPlanBuilder(this.getInstallPlan(namespaceName, installPlanName)) + .editSpec() + .withApproved() + .endSpec() + .build(); + + LOGGER.debug("Approving {}", installPlanName); + client.adapt(OpenShiftClient.class).operatorHub().installPlans().inNamespace(namespaceName).withName(installPlanName).patch(installPlan); + } + + public InstallPlan getNonApprovedInstallPlan(String namespaceName, String csvPrefix) { + return client.adapt(OpenShiftClient.class).operatorHub().installPlans() + .inNamespace(namespaceName).list().getItems().stream() + .filter(installPlan -> !installPlan.getSpec().getApproved() && installPlan.getSpec().getClusterServiceVersionNames().toString().contains(csvPrefix)) + .findFirst().get(); + } + public MixedOperation, Resource> dataScienceClusterClient() { return client.resources(DataScienceCluster.class); } diff --git a/src/main/java/io/odh/test/utils/DeploymentUtils.java b/src/main/java/io/odh/test/utils/DeploymentUtils.java index 0fb21f7e..e35800cb 100644 --- a/src/main/java/io/odh/test/utils/DeploymentUtils.java +++ b/src/main/java/io/odh/test/utils/DeploymentUtils.java @@ -4,6 +4,7 @@ */ package io.odh.test.utils; +import io.fabric8.kubernetes.api.model.LabelSelector; import io.fabric8.kubernetes.api.model.Pod; import io.fabric8.kubernetes.api.model.PodCondition; import io.fabric8.kubernetes.api.model.apps.Deployment; @@ -16,6 +17,8 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.TreeMap; import static java.util.Arrays.asList; @@ -94,4 +97,46 @@ public static void waitForDeploymentDeletion(String namespaceName, String name) }); LOGGER.debug("Deployment: {}/{} was deleted", namespaceName, name); } + + /** + * Returns a map of pod name to resource version for the Pods currently in the given deployment. + * @param name The Deployment name. + * @return A map of pod name to resource version for Pods in the given Deployment. + */ + public static Map depSnapshot(String namespaceName, String name) { + Deployment deployment = ResourceManager.getClient().getDeployment(namespaceName, name); + LabelSelector selector = deployment.getSpec().getSelector(); + return PodUtils.podSnapshot(namespaceName, selector); + } + + /** + * Method to check that all Pods for expected Deployment were rolled + * @param namespaceName Namespace name + * @param name Deployment name + * @param snapshot Snapshot of Pods for Deployment before the rolling update + * @return true when the Pods for Deployment are recreated + */ + public static boolean depHasRolled(String namespaceName, String name, Map snapshot) { + LOGGER.debug("Existing snapshot: {}/{}", namespaceName, new TreeMap<>(snapshot)); + Map map = PodUtils.podSnapshot(namespaceName, ResourceManager.getClient().getDeployment(namespaceName, name).getSpec().getSelector()); + LOGGER.debug("Current snapshot: {}/{}", namespaceName, new TreeMap<>(map)); + int current = map.size(); + map.keySet().retainAll(snapshot.keySet()); + if (current == snapshot.size() && map.isEmpty()) { + LOGGER.debug("All Pods seem to have rolled"); + return true; + } else { + LOGGER.debug("Some Pods still need to roll: {}/{}", namespaceName, map); + return false; + } + } + + public static Map waitTillDepHasRolled(String namespaceName, String deploymentName, Map snapshot) { + LOGGER.info("Waiting for Deployment: {}/{} rolling update", namespaceName, deploymentName); + TestUtils.waitFor("rolling update of Deployment " + namespaceName + "/" + deploymentName, + TestConstants.GLOBAL_POLL_INTERVAL_MEDIUM, TestConstants.GLOBAL_TIMEOUT, + () -> depHasRolled(namespaceName, deploymentName, snapshot)); + + return depSnapshot(namespaceName, deploymentName); + } } diff --git a/src/main/java/io/odh/test/utils/PodUtils.java b/src/main/java/io/odh/test/utils/PodUtils.java index 57da893f..a31bc353 100644 --- a/src/main/java/io/odh/test/utils/PodUtils.java +++ b/src/main/java/io/odh/test/utils/PodUtils.java @@ -16,6 +16,8 @@ import java.time.Duration; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; public class PodUtils { @@ -61,4 +63,48 @@ public static void waitForPodsReady(String namespaceName, LabelSelector selector return true; }, onTimeout); } + + /** + * Returns a map of resource name to resource version for all the pods in the given {@code namespace} + * matching the given {@code selector}. + */ + public static Map podSnapshot(String namespaceName, LabelSelector selector) { + List pods = ResourceManager.getClient().listPods(namespaceName, selector); + return pods.stream() + .collect( + Collectors.toMap(pod -> pod.getMetadata().getName(), + pod -> pod.getMetadata().getUid())); + } + + public static void verifyThatPodsAreStable(String namespaceName, LabelSelector labelSelector) { + int[] stabilityCounter = {0}; + String phase = "Running"; + + List runningPods = ResourceManager.getClient().listPods(namespaceName, labelSelector); + + TestUtils.waitFor(String.format("Pods in namespace '%s' with LabelSelector %s stability in phase %s", namespaceName, labelSelector, phase), TestConstants.GLOBAL_POLL_INTERVAL_SHORT, TestConstants.GLOBAL_TIMEOUT, + () -> { + List actualPods = runningPods.stream().map(p -> ResourceManager.getClient().getPod(namespaceName, p.getMetadata().getName())).toList(); + + for (Pod pod : actualPods) { + if (pod.getStatus().getPhase().equals(phase)) { + LOGGER.info("Pod: {}/{} is in the {} state. Remaining seconds Pod to be stable {}", + namespaceName, pod.getMetadata().getName(), pod.getStatus().getPhase(), + TestConstants.GLOBAL_STABILITY_TIME - stabilityCounter[0]); + } else { + LOGGER.info("Pod: {}/{} is not stable in phase following phase {} reset the stability counter from {} to {}", + namespaceName, pod.getMetadata().getName(), pod.getStatus().getPhase(), stabilityCounter[0], 0); + stabilityCounter[0] = 0; + return false; + } + } + stabilityCounter[0]++; + + if (stabilityCounter[0] == TestConstants.GLOBAL_STABILITY_TIME) { + LOGGER.info("All Pods are stable {}", actualPods.stream().map(p -> p.getMetadata().getName()).collect(Collectors.joining(" ,"))); + return true; + } + return false; + }); + } } diff --git a/src/test/java/io/odh/test/e2e/standard/StandardAbstract.java b/src/test/java/io/odh/test/e2e/standard/StandardAbstract.java index 3299b186..d125914e 100644 --- a/src/test/java/io/odh/test/e2e/standard/StandardAbstract.java +++ b/src/test/java/io/odh/test/e2e/standard/StandardAbstract.java @@ -26,7 +26,7 @@ @ExtendWith(ResourceManagerDeleteHandler.class) public class StandardAbstract extends Abstract { - private static final Logger LOGGER = LoggerFactory.getLogger(Abstract.class); + private static final Logger LOGGER = LoggerFactory.getLogger(StandardAbstract.class); @BeforeAll void setupEnvironment() throws IOException { diff --git a/src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java b/src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java new file mode 100644 index 00000000..9e56ff36 --- /dev/null +++ b/src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java @@ -0,0 +1,127 @@ +/* + * 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.upgrade; + +import io.fabric8.kubernetes.api.model.LabelSelector; +import io.fabric8.openshift.api.model.operatorhub.v1alpha1.InstallPlan; +import io.odh.test.OdhConstants; +import io.odh.test.TestConstants; +import io.odh.test.TestUtils; +import io.odh.test.framework.manager.ResourceManager; +import io.odh.test.install.OlmInstall; +import io.odh.test.utils.DeploymentUtils; +import io.odh.test.utils.PodUtils; +import io.opendatahub.datasciencecluster.v1.DataScienceCluster; +import io.opendatahub.datasciencecluster.v1.DataScienceClusterBuilder; +import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.ComponentsBuilder; +import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Codeflare; +import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.CodeflareBuilder; +import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Dashboard; +import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.DashboardBuilder; +import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Datasciencepipelines; +import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.DatasciencepipelinesBuilder; +import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Kserve; +import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.KserveBuilder; +import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Modelmeshserving; +import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.ModelmeshservingBuilder; +import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Workbenches; +import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.WorkbenchesBuilder; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.core.IsNot.not; + +import java.util.Map; +import java.util.NoSuchElementException; + +@Tag("upgrade") +public class OlmUpgradeST extends UpgradeAbstract { + + private static final Logger LOGGER = LoggerFactory.getLogger(OlmUpgradeST.class); + private static final String DS_PROJECT_NAME = "upgrade-dsc"; + + private final String startingVersion = "2.3.0"; + + @Test + void testUpgradeOlm() { + OlmInstall olmInstall = new OlmInstall(); + olmInstall.setApproval("Manual"); + olmInstall.setStartingCsv(olmInstall.getOperatorName() + ".v" + startingVersion); + olmInstall.createManual(); + + // Approve install plan created for older version + InstallPlan ip = ResourceManager.getClient().getNonApprovedInstallPlan(olmInstall.getNamespace(), olmInstall.getOperatorName()); + ResourceManager.getClient().approveInstallPlan(olmInstall.getNamespace(), ip.getMetadata().getName()); + // Wait for old version readiness + DeploymentUtils.waitForDeploymentReady(olmInstall.getNamespace(), olmInstall.getDeploymentName()); + + // Make snapshot of current operator + Map operatorSnapshot = DeploymentUtils.depSnapshot(olmInstall.getNamespace(), olmInstall.getDeploymentName()); + + // Deploy DSC + DataScienceCluster dsc = new DataScienceClusterBuilder() + .withNewMetadata() + .withName(DS_PROJECT_NAME) + .endMetadata() + .withNewSpec() + .withComponents( + new ComponentsBuilder() + .withWorkbenches( + new WorkbenchesBuilder().withManagementState(Workbenches.ManagementState.MANAGED).build() + ) + .withDashboard( + new DashboardBuilder().withManagementState(Dashboard.ManagementState.MANAGED).build() + ) + .withKserve( + new KserveBuilder().withManagementState(Kserve.ManagementState.REMOVED).build() + ) + .withCodeflare( + new CodeflareBuilder().withManagementState(Codeflare.ManagementState.MANAGED).build() + ) + .withDatasciencepipelines( + new DatasciencepipelinesBuilder().withManagementState(Datasciencepipelines.ManagementState.MANAGED).build() + ) + .withModelmeshserving( + new ModelmeshservingBuilder().withManagementState(Modelmeshserving.ManagementState.REMOVED).build() + ) + .build()) + .endSpec() + .build(); + // Deploy DSC + ResourceManager.getInstance().createResourceWithWait(dsc); + + // Approve upgrade to newer version + // TODO - add dynamic wait + TestUtils.waitFor("Install paln with new version", TestConstants.GLOBAL_POLL_INTERVAL_SHORT, TestConstants.GLOBAL_TIMEOUT, () -> { + try { + ResourceManager.getClient().getNonApprovedInstallPlan(olmInstall.getNamespace(), olmInstall.getCsvName()); + return true; + } catch (NoSuchElementException ex) { + LOGGER.debug("No new install plan available. Checking again ..."); + return false; + } + }, () -> { }); + + ip = ResourceManager.getClient().getNonApprovedInstallPlan(olmInstall.getNamespace(), olmInstall.getCsvName()); + ResourceManager.getClient().approveInstallPlan(olmInstall.getNamespace(), ip.getMetadata().getName()); + // Wait for operator RU + DeploymentUtils.waitTillDepHasRolled(olmInstall.getNamespace(), olmInstall.getDeploymentName(), operatorSnapshot); + + // Wait for pod stability for Dashboard + LabelSelector labelSelector = ResourceManager.getClient().getDeployment(TestConstants.ODH_NAMESPACE, OdhConstants.ODH_DASHBOARD).getSpec().getSelector(); + PodUtils.verifyThatPodsAreStable(TestConstants.ODH_NAMESPACE, labelSelector); + + // Check that operator doesn't contains errors in logs + String operatorLog = ResourceManager.getClient().getClient().apps().deployments() + .inNamespace(olmInstall.getNamespace()).withName(olmInstall.getDeploymentName()).getLog(); + + assertThat(operatorLog, not(containsString("error"))); + assertThat(operatorLog, not(containsString("Error"))); + assertThat(operatorLog, not(containsString("ERROR"))); + } +} diff --git a/src/test/java/io/odh/test/e2e/upgrade/UpgradeAbstract.java b/src/test/java/io/odh/test/e2e/upgrade/UpgradeAbstract.java new file mode 100644 index 00000000..15789d0c --- /dev/null +++ b/src/test/java/io/odh/test/e2e/upgrade/UpgradeAbstract.java @@ -0,0 +1,21 @@ +/* + * 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.upgrade; + +import io.odh.test.e2e.Abstract; +import io.odh.test.framework.manager.ResourceManager; +import org.junit.jupiter.api.AfterAll; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class UpgradeAbstract extends Abstract { + + private static final Logger LOGGER = LoggerFactory.getLogger(UpgradeAbstract.class); + + @AfterAll + void teardownEnvironment() { + ResourceManager.getInstance().deleteResources(); + } +} From f360e4125cde3ed47aa5050e56b4fbc820fadbdd Mon Sep 17 00:00:00 2001 From: Jakub Stejskal Date: Thu, 7 Dec 2023 15:17:07 +0100 Subject: [PATCH 2/3] Rebase cleaning Signed-off-by: Jakub Stejskal --- .../io/odh/test/e2e/upgrade/OlmUpgradeST.java | 8 ++++++- .../odh/test/e2e/upgrade/UpgradeAbstract.java | 21 ------------------- 2 files changed, 7 insertions(+), 22 deletions(-) delete mode 100644 src/test/java/io/odh/test/e2e/upgrade/UpgradeAbstract.java diff --git a/src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java b/src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java index 9e56ff36..b5099507 100644 --- a/src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java +++ b/src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java @@ -9,6 +9,9 @@ import io.odh.test.OdhConstants; import io.odh.test.TestConstants; import io.odh.test.TestUtils; +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.OlmInstall; import io.odh.test.utils.DeploymentUtils; @@ -30,6 +33,7 @@ import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.WorkbenchesBuilder; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static org.hamcrest.MatcherAssert.assertThat; @@ -40,7 +44,9 @@ import java.util.NoSuchElementException; @Tag("upgrade") -public class OlmUpgradeST extends UpgradeAbstract { +@ExtendWith(OdhResourceCleaner.class) +@ExtendWith(ResourceManagerDeleteHandler.class) +public class OlmUpgradeST extends Abstract { private static final Logger LOGGER = LoggerFactory.getLogger(OlmUpgradeST.class); private static final String DS_PROJECT_NAME = "upgrade-dsc"; diff --git a/src/test/java/io/odh/test/e2e/upgrade/UpgradeAbstract.java b/src/test/java/io/odh/test/e2e/upgrade/UpgradeAbstract.java deleted file mode 100644 index 15789d0c..00000000 --- a/src/test/java/io/odh/test/e2e/upgrade/UpgradeAbstract.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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.upgrade; - -import io.odh.test.e2e.Abstract; -import io.odh.test.framework.manager.ResourceManager; -import org.junit.jupiter.api.AfterAll; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class UpgradeAbstract extends Abstract { - - private static final Logger LOGGER = LoggerFactory.getLogger(UpgradeAbstract.class); - - @AfterAll - void teardownEnvironment() { - ResourceManager.getInstance().deleteResources(); - } -} From a70680915f818e8d7878964525ca919613cc7aa4 Mon Sep 17 00:00:00 2001 From: Jakub Stejskal Date: Thu, 7 Dec 2023 20:28:20 +0100 Subject: [PATCH 3/3] Minor improvement Signed-off-by: Jakub Stejskal --- src/main/java/io/odh/test/platform/KubeUtils.java | 15 +++++++++++++++ .../io/odh/test/e2e/upgrade/OlmUpgradeST.java | 14 ++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/odh/test/platform/KubeUtils.java b/src/main/java/io/odh/test/platform/KubeUtils.java index ad8c9645..4282a664 100644 --- a/src/main/java/io/odh/test/platform/KubeUtils.java +++ b/src/main/java/io/odh/test/platform/KubeUtils.java @@ -4,11 +4,14 @@ */ package io.odh.test.platform; +import io.odh.test.TestConstants; +import io.odh.test.TestUtils; import io.odh.test.framework.manager.ResourceManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.List; +import java.util.NoSuchElementException; public class KubeUtils { @@ -39,6 +42,18 @@ public static void deleteDefaultDSCI() { ResourceManager.getKubeCmdClient().exec(false, "delete", "dsci", "--all"); } + public static void waitForInstallPlan(String namespace, String csvName) { + TestUtils.waitFor("Install paln with new version", TestConstants.GLOBAL_POLL_INTERVAL_SHORT, TestConstants.GLOBAL_TIMEOUT, () -> { + try { + ResourceManager.getClient().getNonApprovedInstallPlan(namespace, csvName); + return true; + } catch (NoSuchElementException ex) { + LOGGER.debug("No new install plan available. Checking again ..."); + return false; + } + }, () -> { }); + } + private KubeUtils() { } } diff --git a/src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java b/src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java index b5099507..0c3327de 100644 --- a/src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java +++ b/src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java @@ -8,12 +8,12 @@ import io.fabric8.openshift.api.model.operatorhub.v1alpha1.InstallPlan; import io.odh.test.OdhConstants; import io.odh.test.TestConstants; -import io.odh.test.TestUtils; 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.OlmInstall; +import io.odh.test.platform.KubeUtils; import io.odh.test.utils.DeploymentUtils; import io.odh.test.utils.PodUtils; import io.opendatahub.datasciencecluster.v1.DataScienceCluster; @@ -41,7 +41,6 @@ import static org.hamcrest.core.IsNot.not; import java.util.Map; -import java.util.NoSuchElementException; @Tag("upgrade") @ExtendWith(OdhResourceCleaner.class) @@ -102,16 +101,7 @@ void testUpgradeOlm() { ResourceManager.getInstance().createResourceWithWait(dsc); // Approve upgrade to newer version - // TODO - add dynamic wait - TestUtils.waitFor("Install paln with new version", TestConstants.GLOBAL_POLL_INTERVAL_SHORT, TestConstants.GLOBAL_TIMEOUT, () -> { - try { - ResourceManager.getClient().getNonApprovedInstallPlan(olmInstall.getNamespace(), olmInstall.getCsvName()); - return true; - } catch (NoSuchElementException ex) { - LOGGER.debug("No new install plan available. Checking again ..."); - return false; - } - }, () -> { }); + KubeUtils.waitForInstallPlan(olmInstall.getNamespace(), olmInstall.getCsvName()); ip = ResourceManager.getClient().getNonApprovedInstallPlan(olmInstall.getNamespace(), olmInstall.getCsvName()); ResourceManager.getClient().approveInstallPlan(olmInstall.getNamespace(), ip.getMetadata().getName());