-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[kubectl-plugin] Add e2e test for kubectl ray job submit #2614
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -38,3 +38,4 @@ jobs: | |
with: | ||
plugin-test: true | ||
dir-to-test: kubectl-plugin | ||
ray-version: 2.40.0 |
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,102 @@ | ||
package e2e | ||
|
||
import ( | ||
"os/exec" | ||
"path" | ||
"regexp" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
// Directory when running test is kuberay/kubectl-plugin/test/e2e/ | ||
const ( | ||
rayJobFilePath = "./testdata/ray-job.interactive-mode.yaml" | ||
rayJobNoEnvFilePath = "./testdata/ray-job.interactive-mode-no-runtime-env.yaml" | ||
kubectlRayJobWorkingDir = "./testdata/rayjob-submit-working-dir/" | ||
entrypointSampleFileName = "entrypoint-python-sample.py" | ||
runtimeEnvSampleFileName = "runtime-env-sample.yaml" | ||
) | ||
|
||
var _ = Describe("Calling ray plugin `job submit` command on Ray Job", Ordered, func() { | ||
It("succeed in submitting RayJob", func() { | ||
cmd := exec.Command("kubectl", "ray", "job", "submit", "-f", rayJobFilePath, "--working-dir", kubectlRayJobWorkingDir, "--", "python", entrypointSampleFileName) | ||
output, err := cmd.CombinedOutput() | ||
|
||
Expect(err).NotTo(HaveOccurred()) | ||
// Retrieve the Job ID from the output | ||
regexExp := regexp.MustCompile(`'([^']*raysubmit[^']*)'`) | ||
matches := regexExp.FindStringSubmatch(string(output)) | ||
|
||
Expect(len(matches)).To(BeNumerically(">=", 2)) | ||
cmdOutputJobID := matches[1] | ||
|
||
// Use kubectl to check status of the rayjob | ||
// Retrieve Job ID | ||
cmd = exec.Command("kubectl", "get", "rayjob", "rayjob-sample", "-o", "jsonpath={.status.jobId}") | ||
output, err = cmd.CombinedOutput() | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Expect(cmdOutputJobID).To(Equal(string(output))) | ||
|
||
// Retrieve Job Status | ||
cmd = exec.Command("kubectl", "get", "rayjob", "rayjob-sample", "-o", "jsonpath={.status.jobStatus}") | ||
output, err = cmd.CombinedOutput() | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Expect(string(output)).To(Equal("SUCCEEDED")) | ||
|
||
// Retrieve Job Deployment Status | ||
cmd = exec.Command("kubectl", "get", "rayjob", "rayjob-sample", "-o", "jsonpath={.status.jobDeploymentStatus}") | ||
output, err = cmd.CombinedOutput() | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Expect(string(output)).To(Equal("Complete")) | ||
|
||
// Cleanup | ||
cmd = exec.Command("kubectl", "delete", "rayjob", "rayjob-sample") | ||
_, err = cmd.CombinedOutput() | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
|
||
It("succeed in submitting RayJob with runtime environment set with working dir", func() { | ||
runtimeEnvFilePath := path.Join(kubectlRayJobWorkingDir, runtimeEnvSampleFileName) | ||
cmd := exec.Command("kubectl", "ray", "job", "submit", "-f", rayJobNoEnvFilePath, "--runtime-env", runtimeEnvFilePath, "--", "python", entrypointSampleFileName) | ||
output, err := cmd.CombinedOutput() | ||
|
||
Expect(err).NotTo(HaveOccurred()) | ||
// Retrieve the Job ID from the output | ||
regexExp := regexp.MustCompile(`'([^']*raysubmit[^']*)'`) | ||
matches := regexExp.FindStringSubmatch(string(output)) | ||
|
||
Expect(len(matches)).To(BeNumerically(">=", 2)) | ||
cmdOutputJobID := matches[1] | ||
|
||
// Use kubectl to check status of the rayjob | ||
// Retrieve Job ID | ||
cmd = exec.Command("kubectl", "get", "rayjob", "rayjob-sample", "-o", "jsonpath={.status.jobId}") | ||
output, err = cmd.CombinedOutput() | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Expect(cmdOutputJobID).To(Equal(string(output))) | ||
|
||
// Retrieve Job Status | ||
cmd = exec.Command("kubectl", "get", "rayjob", "rayjob-sample", "-o", "jsonpath={.status.jobStatus}") | ||
output, err = cmd.CombinedOutput() | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Expect(string(output)).To(Equal("SUCCEEDED")) | ||
|
||
// Retrieve Job Deployment Status | ||
cmd = exec.Command("kubectl", "get", "rayjob", "rayjob-sample", "-o", "jsonpath={.status.jobDeploymentStatus}") | ||
output, err = cmd.CombinedOutput() | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Expect(string(output)).To(Equal("Complete")) | ||
|
||
// Cleanup | ||
cmd = exec.Command("kubectl", "delete", "rayjob", "rayjob-sample") | ||
_, err = cmd.CombinedOutput() | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
}) |
48 changes: 48 additions & 0 deletions
48
kubectl-plugin/test/e2e/testdata/ray-job.interactive-mode-no-runtime-env.yaml
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,48 @@ | ||
apiVersion: ray.io/v1 | ||
kind: RayJob | ||
metadata: | ||
name: rayjob-sample | ||
spec: | ||
submissionMode: 'InteractiveMode' | ||
rayClusterSpec: | ||
rayVersion: '2.39.0' | ||
headGroupSpec: | ||
rayStartParams: | ||
dashboard-host: '0.0.0.0' | ||
template: | ||
spec: | ||
containers: | ||
- name: ray-head | ||
image: rayproject/ray:2.39.0 | ||
ports: | ||
- containerPort: 6379 | ||
name: gcs-server | ||
- containerPort: 8265 | ||
name: dashboard | ||
- containerPort: 10001 | ||
name: client | ||
resources: | ||
limits: | ||
cpu: "1" | ||
requests: | ||
cpu: "200m" | ||
workerGroupSpecs: | ||
- replicas: 1 | ||
minReplicas: 1 | ||
maxReplicas: 5 | ||
groupName: small-group | ||
rayStartParams: {} | ||
template: | ||
spec: | ||
containers: | ||
- name: ray-worker | ||
image: rayproject/ray:2.39.0 | ||
lifecycle: | ||
preStop: | ||
exec: | ||
command: [ "/bin/sh","-c","ray stop" ] | ||
resources: | ||
limits: | ||
cpu: "1" | ||
requests: | ||
cpu: "200m" |
57 changes: 57 additions & 0 deletions
57
kubectl-plugin/test/e2e/testdata/ray-job.interactive-mode.yaml
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,57 @@ | ||
apiVersion: ray.io/v1 | ||
kind: RayJob | ||
metadata: | ||
name: rayjob-sample | ||
spec: | ||
# The current value is "InteractiveMode", meaning that it will wait for user to submit job and provide the job submission ID | ||
submissionMode: 'InteractiveMode' | ||
runtimeEnvYAML: | | ||
pip: | ||
- emoji==2.14.0 | ||
- pyjokes==0.6.0 | ||
env_vars: | ||
test_env_var: "first_env_var" | ||
another_env_var: "second_env_var" | ||
|
||
rayClusterSpec: | ||
rayVersion: '2.39.0' # should match the Ray version in the image of the containers | ||
headGroupSpec: | ||
rayStartParams: | ||
dashboard-host: '0.0.0.0' | ||
template: | ||
spec: | ||
containers: | ||
- name: ray-head | ||
image: rayproject/ray:2.39.0 | ||
ports: | ||
- containerPort: 6379 | ||
name: gcs-server | ||
- containerPort: 8265 | ||
name: dashboard | ||
- containerPort: 10001 | ||
name: client | ||
resources: | ||
limits: | ||
cpu: "1" | ||
requests: | ||
cpu: "200m" | ||
workerGroupSpecs: | ||
- replicas: 1 | ||
minReplicas: 1 | ||
maxReplicas: 5 | ||
groupName: small-group | ||
rayStartParams: {} | ||
template: | ||
spec: | ||
containers: | ||
- name: ray-worker | ||
image: rayproject/ray:2.39.0 | ||
lifecycle: | ||
preStop: | ||
exec: | ||
command: [ "/bin/sh","-c","ray stop" ] | ||
resources: | ||
limits: | ||
cpu: "1" | ||
requests: | ||
cpu: "200m" |
19 changes: 19 additions & 0 deletions
19
kubectl-plugin/test/e2e/testdata/rayjob-submit-working-dir/entrypoint-python-sample.py
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,19 @@ | ||
import ray | ||
import os | ||
import emoji | ||
import pyjokes | ||
|
||
ray.init() | ||
|
||
@ray.remote | ||
def f(): | ||
assert emoji.__version__ == "2.14.0" | ||
assert pyjokes.__version__ == "0.6.0" | ||
|
||
first_env_var = os.getenv("test_env_var") | ||
second_env_var = os.getenv("another_env_var") | ||
|
||
assert first_env_var == "first_env_var" | ||
assert second_env_var == "second_env_var" | ||
|
||
ray.get(f.remote()) |
7 changes: 7 additions & 0 deletions
7
kubectl-plugin/test/e2e/testdata/rayjob-submit-working-dir/runtime-env-sample.yaml
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,7 @@ | ||
pip: | ||
- emoji==2.14.0 | ||
- pyjokes==0.6.0 | ||
env_vars: | ||
test_env_var: "first_env_var" | ||
another_env_var: "second_env_var" | ||
working_dir: ./testdata/rayjob-submit-working-dir/ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevin85421 @MortalHappiness what's the expected behavior with runtime env when using
InteractiveMode
. It should be ignored right?