|
| 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 e2e |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + . "github.com/onsi/gomega" |
| 23 | + |
| 24 | + batchv1 "k8s.io/api/batch/v1" |
| 25 | + corev1 "k8s.io/api/core/v1" |
| 26 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 27 | + |
| 28 | + . "github.com/project-codeflare/codeflare-operator/test/support" |
| 29 | +) |
| 30 | + |
| 31 | +func TestMNISTRayClusterSDK(t *testing.T) { |
| 32 | + test := With(t) |
| 33 | + test.T().Parallel() |
| 34 | + |
| 35 | + test.T().Skip("Requires https://github.com/project-codeflare/codeflare-sdk/pull/146") |
| 36 | + |
| 37 | + // Create a namespace |
| 38 | + namespace := test.NewTestNamespace() |
| 39 | + |
| 40 | + // SDK script |
| 41 | + sdk := &corev1.ConfigMap{ |
| 42 | + TypeMeta: metav1.TypeMeta{ |
| 43 | + APIVersion: corev1.SchemeGroupVersion.String(), |
| 44 | + Kind: "ConfigMap", |
| 45 | + }, |
| 46 | + ObjectMeta: metav1.ObjectMeta{ |
| 47 | + Name: "sdk", |
| 48 | + Namespace: namespace.Name, |
| 49 | + }, |
| 50 | + BinaryData: map[string][]byte{ |
| 51 | + "sdk.py": ReadFile(test, "sdk.py"), |
| 52 | + }, |
| 53 | + Immutable: Ptr(true), |
| 54 | + } |
| 55 | + sdk, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Create(test.Ctx(), sdk, metav1.CreateOptions{}) |
| 56 | + test.Expect(err).NotTo(HaveOccurred()) |
| 57 | + test.T().Logf("Created ConfigMap %s/%s successfully", sdk.Namespace, sdk.Name) |
| 58 | + |
| 59 | + // pip requirements |
| 60 | + requirements := &corev1.ConfigMap{ |
| 61 | + TypeMeta: metav1.TypeMeta{ |
| 62 | + APIVersion: corev1.SchemeGroupVersion.String(), |
| 63 | + Kind: "ConfigMap", |
| 64 | + }, |
| 65 | + ObjectMeta: metav1.ObjectMeta{ |
| 66 | + Name: "requirements", |
| 67 | + Namespace: namespace.Name, |
| 68 | + }, |
| 69 | + BinaryData: map[string][]byte{ |
| 70 | + "requirements.txt": ReadFile(test, "requirements.txt"), |
| 71 | + }, |
| 72 | + Immutable: Ptr(true), |
| 73 | + } |
| 74 | + requirements, err = test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Create(test.Ctx(), requirements, metav1.CreateOptions{}) |
| 75 | + test.Expect(err).NotTo(HaveOccurred()) |
| 76 | + test.T().Logf("Created ConfigMap %s/%s successfully", requirements.Namespace, requirements.Name) |
| 77 | + |
| 78 | + job := &batchv1.Job{ |
| 79 | + TypeMeta: metav1.TypeMeta{ |
| 80 | + APIVersion: batchv1.SchemeGroupVersion.String(), |
| 81 | + Kind: "Job", |
| 82 | + }, |
| 83 | + ObjectMeta: metav1.ObjectMeta{ |
| 84 | + Name: "sdk", |
| 85 | + Namespace: namespace.Name, |
| 86 | + }, |
| 87 | + Spec: batchv1.JobSpec{ |
| 88 | + Completions: Ptr(int32(1)), |
| 89 | + Parallelism: Ptr(int32(1)), |
| 90 | + BackoffLimit: Ptr(int32(0)), |
| 91 | + Template: corev1.PodTemplateSpec{ |
| 92 | + Spec: corev1.PodSpec{ |
| 93 | + Containers: []corev1.Container{ |
| 94 | + { |
| 95 | + Name: "sdk", |
| 96 | + Image: "quay.io/opendatahub/notebooks:jupyter-minimal-ubi8-python-3.8-4c8f26e", |
| 97 | + Command: []string{"/bin/sh", "-c", "pip install -r /test/runtime/requirements.txt && python /test/job/sdk.py"}, |
| 98 | + VolumeMounts: []corev1.VolumeMount{ |
| 99 | + { |
| 100 | + Name: "sdk", |
| 101 | + MountPath: "/test/job", |
| 102 | + }, |
| 103 | + { |
| 104 | + Name: "requirements", |
| 105 | + MountPath: "/test/runtime", |
| 106 | + }, |
| 107 | + }, |
| 108 | + }, |
| 109 | + }, |
| 110 | + Volumes: []corev1.Volume{ |
| 111 | + { |
| 112 | + Name: "sdk", |
| 113 | + VolumeSource: corev1.VolumeSource{ |
| 114 | + ConfigMap: &corev1.ConfigMapVolumeSource{ |
| 115 | + LocalObjectReference: corev1.LocalObjectReference{ |
| 116 | + Name: sdk.Name, |
| 117 | + }, |
| 118 | + }, |
| 119 | + }, |
| 120 | + }, |
| 121 | + { |
| 122 | + Name: "requirements", |
| 123 | + VolumeSource: corev1.VolumeSource{ |
| 124 | + ConfigMap: &corev1.ConfigMapVolumeSource{ |
| 125 | + LocalObjectReference: corev1.LocalObjectReference{ |
| 126 | + Name: requirements.Name, |
| 127 | + }, |
| 128 | + }, |
| 129 | + }, |
| 130 | + }, |
| 131 | + }, |
| 132 | + RestartPolicy: corev1.RestartPolicyNever, |
| 133 | + }, |
| 134 | + }, |
| 135 | + }, |
| 136 | + } |
| 137 | + job, err = test.Client().Core().BatchV1().Jobs(namespace.Name).Create(test.Ctx(), job, metav1.CreateOptions{}) |
| 138 | + test.Expect(err).NotTo(HaveOccurred()) |
| 139 | + |
| 140 | + defer JobTroubleshooting(test, job) |
| 141 | + |
| 142 | + test.T().Logf("Waiting for Job %s/%s to complete successfully", job.Namespace, job.Name) |
| 143 | + test.Eventually(Job(test, job.Namespace, job.Name), TestTimeoutMedium). |
| 144 | + Should(WithTransform(ConditionStatus(batchv1.JobComplete), Equal(corev1.ConditionTrue))) |
| 145 | +} |
0 commit comments