From db27aee410f3d8d8b9f48c77e712f5d625991e81 Mon Sep 17 00:00:00 2001 From: Jakub Stejskal Date: Mon, 11 Dec 2023 12:45:57 +0100 Subject: [PATCH] Fixes v2 Signed-off-by: Jakub Stejskal --- src/main/java/io/odh/test/TestConstants.java | 3 ++- .../manager/resources/NotebookResource.java | 9 +++++++++ src/main/java/io/odh/test/platform/KubeClient.java | 12 ++++++------ .../test/platform/cmdClient/BaseCmdKubeClient.java | 1 - .../odh/test/platform/cmdClient/KubeCmdClient.java | 2 ++ .../io/odh/test/platform/cmdClient/Kubectl.java | 6 ++++++ .../java/io/odh/test/platform/cmdClient/Oc.java | 5 +++++ src/main/java/io/odh/test/utils/PodUtils.java | 13 ++++++++----- src/main/resources/notebook.yaml | 2 +- .../java/io/odh/test/e2e/upgrade/OlmUpgradeST.java | 4 +++- 10 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/odh/test/TestConstants.java b/src/main/java/io/odh/test/TestConstants.java index 4c3dd887..885be68c 100644 --- a/src/main/java/io/odh/test/TestConstants.java +++ b/src/main/java/io/odh/test/TestConstants.java @@ -8,6 +8,7 @@ public class TestConstants { public static final String ODH_NAMESPACE = "opendatahub"; + public static final String ODH_DASHBOARD_ROUTE_NAME = "odh-dashboard"; public static final String DEFAULT_NAMESPACE = "default"; public static final String SUBSCRIPTION = "Subscription"; @@ -20,7 +21,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.ofMinutes(2).toSeconds(); + public static final long GLOBAL_STABILITY_TIME = Duration.ofMinutes(1).toSeconds(); private TestConstants() { } diff --git a/src/main/java/io/odh/test/framework/manager/resources/NotebookResource.java b/src/main/java/io/odh/test/framework/manager/resources/NotebookResource.java index f2afd1ba..bcebb7ec 100644 --- a/src/main/java/io/odh/test/framework/manager/resources/NotebookResource.java +++ b/src/main/java/io/odh/test/framework/manager/resources/NotebookResource.java @@ -7,6 +7,8 @@ import io.fabric8.kubernetes.api.model.KubernetesResourceList; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.openshift.client.OpenShiftClient; +import io.odh.test.TestConstants; import io.odh.test.TestUtils; import io.odh.test.framework.manager.ResourceManager; import io.odh.test.framework.manager.ResourceType; @@ -58,6 +60,13 @@ public static Notebook loadDefaultNotebook(String namespace, String name) throws InputStream is = TestUtils.getFileFromResourceAsStream(NOTEBOOK_TEMPLATE_PATH); String notebookString = IOUtils.toString(is, "UTF-8"); notebookString = notebookString.replace("my-project", namespace).replace("my-workbench", name); + // Set new Route url + String routeHost = ResourceManager.getClient().getClient().adapt(OpenShiftClient.class).routes().inNamespace(TestConstants.ODH_NAMESPACE).withName(TestConstants.ODH_DASHBOARD_ROUTE_NAME).get().getSpec().getHost(); + notebookString = notebookString.replace("odh_dashboard_route", "https://" + routeHost); + // Set correct username + String username = ResourceManager.getKubeCmdClient().getUsername().strip(); + notebookString = notebookString.replace("odh_user", username); + return TestUtils.configFromYaml(notebookString, Notebook.class); } } diff --git a/src/main/java/io/odh/test/platform/KubeClient.java b/src/main/java/io/odh/test/platform/KubeClient.java index 42516a22..a37ff8c7 100644 --- a/src/main/java/io/odh/test/platform/KubeClient.java +++ b/src/main/java/io/odh/test/platform/KubeClient.java @@ -370,15 +370,15 @@ public InstallPlan getInstallPlan(String namespaceName, String installPlanName) } public void approveInstallPlan(String namespaceName, String installPlanName) throws InterruptedException { - InstallPlan installPlan = new InstallPlanBuilder(this.getInstallPlan(namespaceName, installPlanName)) - .editSpec() - .withApproved() - .endSpec() - .build(); - LOGGER.debug("Approving InstallPlan {}", installPlanName); TestUtils.waitFor("InstallPlan approval", TestConstants.GLOBAL_POLL_INTERVAL_SHORT, 15_000, () -> { try { + InstallPlan installPlan = new InstallPlanBuilder(this.getInstallPlan(namespaceName, installPlanName)) + .editSpec() + .withApproved() + .endSpec() + .build(); + client.adapt(OpenShiftClient.class).operatorHub().installPlans().inNamespace(namespaceName).withName(installPlanName).patch(installPlan); return true; } catch (Exception ex) { diff --git a/src/main/java/io/odh/test/platform/cmdClient/BaseCmdKubeClient.java b/src/main/java/io/odh/test/platform/cmdClient/BaseCmdKubeClient.java index ab27754b..e9e4ede8 100644 --- a/src/main/java/io/odh/test/platform/cmdClient/BaseCmdKubeClient.java +++ b/src/main/java/io/odh/test/platform/cmdClient/BaseCmdKubeClient.java @@ -397,5 +397,4 @@ public K process(Map parameters, String file, Consumer c c.accept(exec.out()); return (K) this; } - } diff --git a/src/main/java/io/odh/test/platform/cmdClient/KubeCmdClient.java b/src/main/java/io/odh/test/platform/cmdClient/KubeCmdClient.java index 96f01e9d..ec21cbcc 100644 --- a/src/main/java/io/odh/test/platform/cmdClient/KubeCmdClient.java +++ b/src/main/java/io/odh/test/platform/cmdClient/KubeCmdClient.java @@ -202,4 +202,6 @@ default String logs(String pod) { String cmd(); K process(Map domain, String file, Consumer c); + + String getUsername(); } diff --git a/src/main/java/io/odh/test/platform/cmdClient/Kubectl.java b/src/main/java/io/odh/test/platform/cmdClient/Kubectl.java index 36f81ed3..2f75e480 100644 --- a/src/main/java/io/odh/test/platform/cmdClient/Kubectl.java +++ b/src/main/java/io/odh/test/platform/cmdClient/Kubectl.java @@ -48,4 +48,10 @@ public String defaultOlmNamespace() { public String cmd() { return KUBECTL; } + + @Override + public String getUsername() { + // TODO - implement this! + return null; + } } diff --git a/src/main/java/io/odh/test/platform/cmdClient/Oc.java b/src/main/java/io/odh/test/platform/cmdClient/Oc.java index 376226b0..593edad1 100644 --- a/src/main/java/io/odh/test/platform/cmdClient/Oc.java +++ b/src/main/java/io/odh/test/platform/cmdClient/Oc.java @@ -72,4 +72,9 @@ public Oc newApp(String template, Map params) { public String cmd() { return OC; } + + @Override + public String getUsername() { + return Exec.exec(cmd(), "whoami").out(); + } } diff --git a/src/main/java/io/odh/test/utils/PodUtils.java b/src/main/java/io/odh/test/utils/PodUtils.java index a31bc353..a04ad107 100644 --- a/src/main/java/io/odh/test/utils/PodUtils.java +++ b/src/main/java/io/odh/test/utils/PodUtils.java @@ -80,20 +80,23 @@ public static void verifyThatPodsAreStable(String namespaceName, LabelSelector l 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 runningPods = ResourceManager.getClient().listPods(namespaceName, labelSelector); List actualPods = runningPods.stream().map(p -> ResourceManager.getClient().getPod(namespaceName, p.getMetadata().getName())).toList(); + LOGGER.debug("Working with the following pods: {}", actualPods.stream().map(p -> p.getMetadata().getName()).toList()); for (Pod pod : actualPods) { + if (pod == null) { + continue; + } if (pod.getStatus().getPhase().equals(phase)) { - LOGGER.info("Pod: {}/{} is in the {} state. Remaining seconds Pod to be stable {}", + LOGGER.debug("Pod: {}/{} is in the {} state. Remaining seconds for 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); + LOGGER.warn("Pod: {}/{} is not stable in phase following phase {} ({}) reset the stability counter from {}s to {}s", + namespaceName, pod.getMetadata().getName(), pod.getStatus().getPhase(), phase, stabilityCounter[0], 0); stabilityCounter[0] = 0; return false; } diff --git a/src/main/resources/notebook.yaml b/src/main/resources/notebook.yaml index 15d91261..99df5519 100644 --- a/src/main/resources/notebook.yaml +++ b/src/main/resources/notebook.yaml @@ -25,7 +25,7 @@ spec: --ServerApp.password='' --ServerApp.base_url=/notebook/my-project/my-workbench --ServerApp.quit_button=False - --ServerApp.tornado_settings={"user":"","hub_host":"odh_dashboard_route","hub_prefix":"/projects/my-project"} + --ServerApp.tornado_settings={"user":"odh_user","hub_host":"odh_dashboard_route","hub_prefix":"/projects/my-project"} - name: JUPYTER_IMAGE value: image-registry.openshift-image-registry.svc:5000/opendatahub/jupyter-pytorch-notebook:2023.2 image: image-registry.openshift-image-registry.svc:5000/opendatahub/jupyter-pytorch-notebook:2023.2 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 4153673a..e5797dd5 100644 --- a/src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java +++ b/src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java @@ -15,6 +15,7 @@ import io.odh.test.utils.DeploymentUtils; import io.odh.test.utils.PodUtils; import io.odh.test.utils.UpgradeUtils; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.slf4j.Logger; @@ -29,9 +30,10 @@ 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"; + private final String startingVersion = "2.4.0"; @Test + @Disabled("Tested only for upgrades from 2.4+ so we are waiting for 2.5 release") void testUpgradeOlm() throws IOException, InterruptedException { String ntbName = "test-odh-notebook"; String ntbNamespace = "test-odh-notebook-upgrade";