-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RayJob]: Add RayJob with RayCluster spec e2e test (#1636)
This PR adds e2e test following up #1539 and leverages #1575. It also factorises configuration across the RayJob e2e tests.
- Loading branch information
1 parent
7c82efe
commit 1c5f3e8
Showing
6 changed files
with
387 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package e2e | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
. "github.com/onsi/gomega" | ||
|
||
k8serrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1" | ||
. "github.com/ray-project/kuberay/ray-operator/test/support" | ||
) | ||
|
||
func TestRayJob(t *testing.T) { | ||
test := With(t) | ||
|
||
// Create a namespace | ||
namespace := test.NewTestNamespace() | ||
|
||
// Job scripts | ||
jobs := newConfigMap(namespace.Name, "jobs", files(test, "counter.py", "fail.py")) | ||
jobs, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Create(test.Ctx(), jobs, metav1.CreateOptions{}) | ||
test.Expect(err).NotTo(HaveOccurred()) | ||
test.T().Logf("Created ConfigMap %s/%s successfully", jobs.Namespace, jobs.Name) | ||
|
||
test.T().Run("Successful RayJob", func(t *testing.T) { | ||
// RayJob | ||
rayJob := &rayv1.RayJob{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: rayv1.GroupVersion.String(), | ||
Kind: "RayJob", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "counter", | ||
Namespace: namespace.Name, | ||
}, | ||
Spec: rayv1.RayJobSpec{ | ||
RayClusterSpec: newRayClusterSpec(mountConfigMap(jobs, "/home/ray/jobs")), | ||
Entrypoint: "python /home/ray/jobs/counter.py", | ||
RuntimeEnvYAML: ` | ||
env_vars: | ||
counter_name: test_counter | ||
`, | ||
ShutdownAfterJobFinishes: true, | ||
SubmitterPodTemplate: jobSubmitterPodTemplate(), | ||
}, | ||
} | ||
rayJob, err = test.Client().Ray().RayV1().RayJobs(namespace.Name).Create(test.Ctx(), rayJob, metav1.CreateOptions{}) | ||
test.Expect(err).NotTo(HaveOccurred()) | ||
test.T().Logf("Created RayJob %s/%s successfully", rayJob.Namespace, rayJob.Name) | ||
|
||
test.T().Logf("Waiting for RayJob %s/%s to complete", rayJob.Namespace, rayJob.Name) | ||
test.Eventually(RayJob(test, rayJob.Namespace, rayJob.Name), TestTimeoutMedium). | ||
Should(WithTransform(RayJobStatus, Satisfy(rayv1.IsJobTerminal))) | ||
|
||
// Assert the RayJob has completed successfully | ||
test.Expect(GetRayJob(test, rayJob.Namespace, rayJob.Name)). | ||
To(WithTransform(RayJobStatus, Equal(rayv1.JobStatusSucceeded))) | ||
|
||
// And the RayJob deployment status is updated accordingly | ||
test.Eventually(RayJob(test, rayJob.Namespace, rayJob.Name)). | ||
Should(WithTransform(RayJobDeploymentStatus, Equal(rayv1.JobDeploymentStatusComplete))) | ||
|
||
// Refresh the RayJob status | ||
rayJob = GetRayJob(test, rayJob.Namespace, rayJob.Name) | ||
|
||
// Assert the RayCluster has been torn down | ||
_, err = test.Client().Ray().RayV1().RayClusters(namespace.Name).Get(test.Ctx(), rayJob.Status.RayClusterName, metav1.GetOptions{}) | ||
test.Expect(err).To(MatchError(k8serrors.NewNotFound(rayv1.Resource("rayclusters"), rayJob.Status.RayClusterName))) | ||
|
||
// Delete the RayJob | ||
err = test.Client().Ray().RayV1().RayJobs(namespace.Name).Delete(test.Ctx(), rayJob.Name, metav1.DeleteOptions{}) | ||
test.Expect(err).NotTo(HaveOccurred()) | ||
test.T().Logf("Deleted RayJob %s/%s successfully", rayJob.Namespace, rayJob.Name) | ||
|
||
// Assert the submitter Job has been cascade deleted | ||
test.Eventually(Jobs(test, namespace.Name)).Should(BeEmpty()) | ||
}) | ||
|
||
test.T().Run("Failing RayJob without cluster shutdown after finished", func(t *testing.T) { | ||
// RayJob | ||
rayJob := &rayv1.RayJob{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: rayv1.GroupVersion.String(), | ||
Kind: "RayJob", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "fail", | ||
Namespace: namespace.Name, | ||
}, | ||
Spec: rayv1.RayJobSpec{ | ||
RayClusterSpec: newRayClusterSpec(mountConfigMap(jobs, "/home/ray/jobs")), | ||
Entrypoint: "python /home/ray/jobs/fail.py", | ||
ShutdownAfterJobFinishes: false, | ||
SubmitterPodTemplate: jobSubmitterPodTemplate(), | ||
}, | ||
} | ||
rayJob, err = test.Client().Ray().RayV1().RayJobs(namespace.Name).Create(test.Ctx(), rayJob, metav1.CreateOptions{}) | ||
test.Expect(err).NotTo(HaveOccurred()) | ||
test.T().Logf("Created RayJob %s/%s successfully", rayJob.Namespace, rayJob.Name) | ||
|
||
test.T().Logf("Waiting for RayJob %s/%s to complete", rayJob.Namespace, rayJob.Name) | ||
test.Eventually(RayJob(test, rayJob.Namespace, rayJob.Name), TestTimeoutMedium). | ||
Should(WithTransform(RayJobStatus, Satisfy(rayv1.IsJobTerminal))) | ||
|
||
// Assert the Ray job has failed | ||
test.Expect(GetRayJob(test, rayJob.Namespace, rayJob.Name)). | ||
To(WithTransform(RayJobStatus, Equal(rayv1.JobStatusFailed))) | ||
|
||
// And the RayJob deployment status is updated accordingly | ||
test.Consistently(RayJob(test, rayJob.Namespace, rayJob.Name), 10*time.Second). | ||
Should(WithTransform(RayJobDeploymentStatus, Equal(rayv1.JobDeploymentStatusRunning))) | ||
|
||
// Refresh the RayJob status | ||
rayJob = GetRayJob(test, rayJob.Namespace, rayJob.Name) | ||
|
||
// Delete the RayJob | ||
err = test.Client().Ray().RayV1().RayJobs(namespace.Name).Delete(test.Ctx(), rayJob.Name, metav1.DeleteOptions{}) | ||
test.Expect(err).NotTo(HaveOccurred()) | ||
test.T().Logf("Deleted RayJob %s/%s successfully", rayJob.Namespace, rayJob.Name) | ||
|
||
// Assert the RayCluster has been cascade deleted | ||
test.Eventually(NotFound(RayClusterOrError(test, namespace.Name, rayJob.Status.RayClusterName))). | ||
Should(BeTrue()) | ||
|
||
// Assert the submitter Job has been cascade deleted | ||
test.Eventually(Jobs(test, namespace.Name)).Should(BeEmpty()) | ||
}) | ||
} |
Oops, something went wrong.