|
| 1 | +/* |
| 2 | +Copyright 2023. |
| 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 integration |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + . "github.com/onsi/gomega" |
| 23 | + cfosupport "github.com/project-codeflare/codeflare-operator/test/support" |
| 24 | + mcadv1beta1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1" |
| 25 | + rayv1alpha1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1alpha1" |
| 26 | + |
| 27 | + corev1 "k8s.io/api/core/v1" |
| 28 | + rbacv1 "k8s.io/api/rbac/v1" |
| 29 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 30 | + |
| 31 | + support "github.com/opendatahub-io/distributed-workloads/tests/integration/support" |
| 32 | +) |
| 33 | + |
| 34 | +func TestMCADRay(t *testing.T) { |
| 35 | + test := cfosupport.With(t) |
| 36 | + |
| 37 | + test.T().Skip("Requires https://github.com/project-codeflare/codeflare-sdk/issues/190") |
| 38 | + |
| 39 | + // Create a namespace |
| 40 | + namespace := test.NewTestNamespace() |
| 41 | + |
| 42 | + // Test configuration |
| 43 | + jupyterNotebookConfigMapFileName := "mnist_ray_mini.ipynb" |
| 44 | + config := &corev1.ConfigMap{ |
| 45 | + TypeMeta: metav1.TypeMeta{ |
| 46 | + APIVersion: corev1.SchemeGroupVersion.String(), |
| 47 | + Kind: "ConfigMap", |
| 48 | + }, |
| 49 | + ObjectMeta: metav1.ObjectMeta{ |
| 50 | + Name: "notebooks-ray", |
| 51 | + }, |
| 52 | + BinaryData: map[string][]byte{ |
| 53 | + // MNIST MCAD Notebook |
| 54 | + jupyterNotebookConfigMapFileName: ReadFile(test, "resources/mnist_ray_mini.ipynb"), |
| 55 | + "mnist.py": ReadFile(test, "resources/mnist.py"), |
| 56 | + "requirements.txt": ReadFile(test, "resources/requirements.txt"), |
| 57 | + }, |
| 58 | + Immutable: cfosupport.Ptr(true), |
| 59 | + } |
| 60 | + config, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Create(test.Ctx(), config, metav1.CreateOptions{}) |
| 61 | + test.Expect(err).NotTo(HaveOccurred()) |
| 62 | + test.T().Logf("Created ConfigMap %s/%s successfully", config.Namespace, config.Name) |
| 63 | + |
| 64 | + // Create RBAC, retrieve token for user with limited rights |
| 65 | + policyRules := []rbacv1.PolicyRule{ |
| 66 | + { |
| 67 | + Verbs: []string{"get", "create", "delete", "list", "patch", "update"}, |
| 68 | + APIGroups: []string{mcadv1beta1.GroupName}, |
| 69 | + Resources: []string{"appwrappers"}, |
| 70 | + }, |
| 71 | + { |
| 72 | + Verbs: []string{"get", "list"}, |
| 73 | + APIGroups: []string{rayv1alpha1.GroupVersion.Group}, |
| 74 | + Resources: []string{"rayclusters", "rayclusters/status"}, |
| 75 | + }, |
| 76 | + { |
| 77 | + Verbs: []string{"get", "list"}, |
| 78 | + APIGroups: []string{"route.openshift.io"}, |
| 79 | + Resources: []string{"routes"}, |
| 80 | + }, |
| 81 | + } |
| 82 | + token := support.CreateTestRBAC(test, namespace, policyRules) |
| 83 | + |
| 84 | + // Create Notebook CR |
| 85 | + support.CreateNotebook(test, namespace, token, config.Name, jupyterNotebookConfigMapFileName) |
| 86 | + |
| 87 | + // Make sure the AppWrapper is created and running |
| 88 | + test.Eventually(cfosupport.AppWrappers(test, namespace), cfosupport.TestTimeoutLong). |
| 89 | + Should( |
| 90 | + And( |
| 91 | + HaveLen(1), |
| 92 | + ContainElement(WithTransform(cfosupport.AppWrapperName, HavePrefix("mnistjob"))), |
| 93 | + ContainElement(WithTransform(cfosupport.AppWrapperState, Equal(mcadv1beta1.AppWrapperStateActive))), |
| 94 | + ), |
| 95 | + ) |
| 96 | + |
| 97 | + // Make sure the AppWrapper finishes and is deleted |
| 98 | + test.Eventually(cfosupport.AppWrappers(test, namespace), cfosupport.TestTimeoutLong). |
| 99 | + Should(HaveLen(0)) |
| 100 | +} |
0 commit comments