|
| 1 | +/* |
| 2 | +Copyright 2025 Feast Community. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +// Package e2erhoai provides end-to-end (E2E) test coverage for Feast integration with |
| 18 | +// Red Hat OpenShift AI (RHOAI) environments. This specific test validates the functionality |
| 19 | +// of executing a Feast Jupyter notebook within a fully configured OpenShift namespace |
| 20 | +package e2erhoai |
| 21 | + |
| 22 | +import ( |
| 23 | + "fmt" |
| 24 | + "os" |
| 25 | + "os/exec" |
| 26 | + "strings" |
| 27 | + |
| 28 | + utils "github.com/feast-dev/feast/infra/feast-operator/test/utils" |
| 29 | + . "github.com/onsi/ginkgo/v2" |
| 30 | + . "github.com/onsi/gomega" |
| 31 | +) |
| 32 | + |
| 33 | +var _ = Describe("Feast Jupyter Notebook Testing", Ordered, func() { |
| 34 | + const ( |
| 35 | + namespace = "test-ns-feast-wb" |
| 36 | + configMapName = "feast-wb-cm" |
| 37 | + rolebindingName = "rb-feast-test" |
| 38 | + notebookFile = "test/e2e_rhoai/resources/feast-test.ipynb" |
| 39 | + pvcFile = "test/e2e_rhoai/resources/pvc.yaml" |
| 40 | + notebookPVC = "jupyterhub-nb-kube-3aadmin-pvc" |
| 41 | + testDir = "/test/e2e_rhoai" |
| 42 | + notebookName = "feast-test.ipynb" |
| 43 | + feastMilvusTest = "TestFeastMilvusNotebook" |
| 44 | + ) |
| 45 | + |
| 46 | + BeforeAll(func() { |
| 47 | + By(fmt.Sprintf("Creating test namespace: %s", namespace)) |
| 48 | + Expect(utils.CreateNamespace(namespace, testDir)).To(Succeed()) |
| 49 | + fmt.Printf("Namespace %s created successfully\n", namespace) |
| 50 | + }) |
| 51 | + |
| 52 | + AfterAll(func() { |
| 53 | + By(fmt.Sprintf("Deleting test namespace: %s", namespace)) |
| 54 | + Expect(utils.DeleteNamespace(namespace, testDir)).To(Succeed()) |
| 55 | + fmt.Printf("Namespace %s deleted successfully\n", namespace) |
| 56 | + }) |
| 57 | + |
| 58 | + runNotebookTest := func() { |
| 59 | + env := func(key string) string { |
| 60 | + val, _ := os.LookupEnv(key) |
| 61 | + return val |
| 62 | + } |
| 63 | + |
| 64 | + username := utils.GetOCUser(testDir) |
| 65 | + |
| 66 | + // set namespace context |
| 67 | + By(fmt.Sprintf("Setting namespace context to : %s", namespace)) |
| 68 | + cmd := exec.Command("kubectl", "config", "set-context", "--current", "--namespace", namespace) |
| 69 | + output, err := utils.Run(cmd, "/test/e2e_rhoai") |
| 70 | + Expect(err).ToNot(HaveOccurred(), fmt.Sprintf( |
| 71 | + "Failed to set namespace context to %s.\nError: %v\nOutput: %s\n", |
| 72 | + namespace, err, output, |
| 73 | + )) |
| 74 | + fmt.Printf("Successfully set namespace context to: %s\n", namespace) |
| 75 | + |
| 76 | + // create config map |
| 77 | + By(fmt.Sprintf("Creating Config map: %s", configMapName)) |
| 78 | + cmd = exec.Command("kubectl", "create", "configmap", configMapName, "--from-file="+notebookFile, "--from-file=test/e2e_rhoai/resources/feature_repo") |
| 79 | + output, err = utils.Run(cmd, "/test/e2e_rhoai") |
| 80 | + Expect(err).ToNot(HaveOccurred(), fmt.Sprintf( |
| 81 | + "Failed to create ConfigMap %s.\nError: %v\nOutput: %s\n", |
| 82 | + configMapName, err, output, |
| 83 | + )) |
| 84 | + fmt.Printf("ConfigMap %s created successfully\n", configMapName) |
| 85 | + |
| 86 | + // create pvc |
| 87 | + By(fmt.Sprintf("Creating Persistent volume claim: %s", notebookPVC)) |
| 88 | + cmd = exec.Command("kubectl", "apply", "-f", "test/e2e_rhoai/resources/pvc.yaml") |
| 89 | + _, err = utils.Run(cmd, "/test/e2e_rhoai") |
| 90 | + ExpectWithOffset(1, err).NotTo(HaveOccurred()) |
| 91 | + fmt.Printf("Persistent Volume Claim %s created successfully", notebookPVC) |
| 92 | + |
| 93 | + // create rolebinding |
| 94 | + By(fmt.Sprintf("Creating rolebinding %s for the user", rolebindingName)) |
| 95 | + cmd = exec.Command("kubectl", "create", "rolebinding", rolebindingName, "-n", namespace, "--role=admin", "--user="+username) |
| 96 | + _, err = utils.Run(cmd, "/test/e2e_rhoai") |
| 97 | + ExpectWithOffset(1, err).NotTo(HaveOccurred()) |
| 98 | + fmt.Printf("Created rolebinding %s successfully\n", rolebindingName) |
| 99 | + |
| 100 | + // configure papermill notebook command execution |
| 101 | + command := []string{ |
| 102 | + "/bin/sh", |
| 103 | + "-c", |
| 104 | + fmt.Sprintf( |
| 105 | + "pip install papermill && "+ |
| 106 | + "mkdir -p /opt/app-root/src/feature_repo && "+ |
| 107 | + "cp -rL /opt/app-root/notebooks/* /opt/app-root/src/feature_repo/ && "+ |
| 108 | + "oc login --token=%s --server=%s --insecure-skip-tls-verify=true && "+ |
| 109 | + "(papermill /opt/app-root/notebooks/%s /opt/app-root/src/output.ipynb --kernel python3 && "+ |
| 110 | + "echo '✅ Notebook executed successfully' || "+ |
| 111 | + "(echo '❌ Notebook execution failed' && "+ |
| 112 | + "cp /opt/app-root/src/output.ipynb /opt/app-root/src/failed_output.ipynb && "+ |
| 113 | + "echo '📄 Copied failed notebook to failed_output.ipynb')) && "+ |
| 114 | + "jupyter nbconvert --to notebook --stdout /opt/app-root/src/output.ipynb || echo '⚠️ nbconvert failed' && "+ |
| 115 | + "sleep 100; exit 0", |
| 116 | + utils.GetOCToken("test/e2e_rhoai"), |
| 117 | + utils.GetOCServer("test/e2e_rhoai"), |
| 118 | + "feast-test.ipynb", |
| 119 | + ), |
| 120 | + } |
| 121 | + |
| 122 | + // Defining notebook parameters |
| 123 | + nbParams := utils.NotebookTemplateParams{ |
| 124 | + Namespace: namespace, |
| 125 | + IngressDomain: utils.GetIngressDomain(testDir), |
| 126 | + OpenDataHubNamespace: env("APPLICATIONS_NAMESPACE"), |
| 127 | + NotebookImage: env("NOTEBOOK_IMAGE"), |
| 128 | + NotebookConfigMapName: configMapName, |
| 129 | + NotebookPVC: notebookPVC, |
| 130 | + Username: username, |
| 131 | + OC_TOKEN: utils.GetOCToken(testDir), |
| 132 | + OC_SERVER: utils.GetOCServer(testDir), |
| 133 | + NotebookFile: notebookName, |
| 134 | + Command: "[\"" + strings.Join(command, "\",\"") + "\"]", |
| 135 | + PipIndexUrl: env("PIP_INDEX_URL"), |
| 136 | + PipTrustedHost: env("PIP_TRUSTED_HOST"), |
| 137 | + FeastVerison: env("FEAST_VERSION"), |
| 138 | + OpenAIAPIKey: env("OPENAI_API_KEY"), |
| 139 | + } |
| 140 | + |
| 141 | + By("Creating Jupyter Notebook") |
| 142 | + Expect(utils.CreateNotebook(nbParams)).To(Succeed(), "Failed to create notebook") |
| 143 | + |
| 144 | + By("Monitoring notebook logs") |
| 145 | + Expect(utils.MonitorNotebookPod(namespace, "jupyter-nb-", notebookName)).To(Succeed(), "Notebook execution failed") |
| 146 | + } |
| 147 | + |
| 148 | + Context("Feast Jupyter Notebook Test", func() { |
| 149 | + It("Should create and run a "+feastMilvusTest+" successfully", runNotebookTest) |
| 150 | + }) |
| 151 | +}) |
0 commit comments