Skip to content

Commit d1e750d

Browse files
[feat][python-client]: add rayjob support to kuberay python-client (#3830)
* [feat][python-client]: add RayJob support to python-client * install kuberay for python-client CI * check in-cluster config if no kube config * fix linting issues * Move python client tests to buildkite * Update .buildkite/test-python-client.yml Signed-off-by: Kai-Hsun Chen <[email protected]> * Add python-client test for RayJob lifecycling a RayCluster * Add python-venv to setup-env.sh --------- Signed-off-by: Kai-Hsun Chen <[email protected]> Co-authored-by: Kai-Hsun Chen <[email protected]>
1 parent b65e4a0 commit d1e750d

17 files changed

+1277
-125
lines changed

.buildkite/setup-env.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ helm repo update
2929

3030
# Install python 3.11 and pip
3131
apt-get update
32-
apt-get install -y python3.11 python3-pip
32+
apt-get install -y python3.11 python3-pip python3-venv python3-dev build-essential
3333

3434
# Install requirements
3535
pip install --break-system-packages ray[default]==2.46.0

.buildkite/test-python-client.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
- label: 'Test Python Client'
2+
instance_size: large
3+
image: golang:1.24
4+
commands:
5+
- source .buildkite/setup-env.sh
6+
- kind create cluster --wait 900s --config ./ci/kind-config-buildkite.yml
7+
- kubectl config set clusters.kind-kind.server https://docker:6443
8+
# Build nightly KubeRay operator image
9+
- pushd ray-operator
10+
- bash ../.buildkite/build-start-operator.sh
11+
- kubectl wait --timeout=90s --for=condition=Available=true deployment kuberay-operator
12+
- popd
13+
# Setup Python environment and install Python client
14+
- echo "--- START:Setting up Python environment"
15+
- pushd clients/python-client
16+
- python3 -m venv venv
17+
- source venv/bin/activate
18+
- pip install -e .
19+
- pip install pytest
20+
# Run Python client tests
21+
- echo "--- START:Running Python client tests"
22+
- set -o pipefail
23+
- pytest python_client_test/ -v || (kubectl logs --tail=50 -l app.kubernetes.io/name=kuberay && exit 1)
24+
- echo "--- END:Python client tests finished"

.github/workflows/test-job.yaml

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -341,32 +341,3 @@ jobs:
341341
- name: Test
342342
run: go test ./pkg/... -race -parallel 4
343343
working-directory: ${{env.working-directory}}
344-
345-
python-client-test:
346-
runs-on: ubuntu-22.04
347-
name: Python Client Test
348-
steps:
349-
- name: Set up Docker
350-
uses: docker/setup-docker-action@v4
351-
352-
- name: Install Kind
353-
run: |
354-
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.22.0/kind-linux-amd64
355-
chmod +x ./kind
356-
sudo mv ./kind /usr/local/bin/kind
357-
kind create cluster
358-
shell: bash
359-
360-
- name: Checkout Python
361-
uses: actions/checkout@v2
362-
363-
- name: Setup Python
364-
uses: actions/setup-python@v2
365-
with:
366-
python-version: '3.x'
367-
368-
- name: Install package and run unittest for Python client
369-
working-directory: ./clients/python-client
370-
run: |
371-
pip install -e .
372-
python3 -m unittest discover 'python_client_test/'

clients/python-client/README.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Overview
22

3-
This python client library provide APIs to handle `raycluster` from your python application.
3+
This python client library provide APIs to handle `raycluster` and `rayjobs` from your python application.
44

55
## Prerequisites
66

@@ -70,39 +70,69 @@ if succeeded:
7070

7171
### cluster_api
7272

73-
Finally, the `cluster_api` is the one you always use to implement your cluster change in k8s. You can
73+
The `cluster_api` is the one you always use to implement your cluster change in k8s. You can
7474
use it with raw `JSON` if you wish. The `director/cluster_builder/cluster_utils` are just tools to
7575
shield the user from using raw `JSON`.
7676

77+
### job_api
78+
79+
Finally, the `job_api` can be used to submit RayJobs to a pre-existing RayCluster.
80+
81+
#### Submitting to Existing Cluster
82+
83+
```python
84+
from python_client import kuberay_job_api, kuberay_cluster_api, constants
85+
86+
job_body = {
87+
"apiVersion": "ray.io/v1",
88+
"kind": "RayJob",
89+
"metadata": {...},
90+
"spec": {
91+
"clusterSelector": {
92+
"ray.io/cluster": "ray-cluster-name",
93+
},
94+
"entrypoint": 'python -c training_script.py',
95+
"submissionMode": "K8sJobMode",
96+
},
97+
}
98+
99+
kuberay_job_api.submit_job(
100+
job=job_body,
101+
k8s_namespace=namespace,
102+
)
103+
```
104+
77105
## Code Organization
78106

79107
```text
80108
clients/
81109
└── python-client
82-
├── LICENSE
83-
├── README.md
84110
├── examples
85111
│ ├── complete-example.py
86112
│ ├── use-builder.py
87113
│ ├── use-director.py
88114
│ ├── use-raw-config_map_with-api.py
89115
│ ├── use-raw-with-api.py
90116
│ └── use-utils.py
117+
├── LICENSE
118+
├── poetry.lock
91119
├── pyproject.toml
92120
├── python_client
93121
│ ├── __init__.py
94122
│ ├── constants.py
95123
│ ├── kuberay_cluster_api.py
124+
│ ├── kuberay_job_api.py
96125
│ └── utils
97126
│ ├── __init__.py
98127
│ ├── kuberay_cluster_builder.py
99128
│ └── kuberay_cluster_utils.py
100129
├── python_client_test
101130
│ ├── README.md
102-
│ ├── test_api.py
131+
│ ├── test_cluster_api.py
103132
│ ├── test_director.py
133+
│ ├── test_job_api.py
104134
│ └── test_utils.py
105-
└── setup.cfg
135+
└── README.md
106136
```
107137

108138
## For developers

clients/python-client/examples/use-raw-config_map_with-api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
}
3838

3939
cluster_body: dict = {
40-
"apiVersion": "ray.io/v1alpha1",
40+
"apiVersion": "ray.io/v1",
4141
"kind": "RayCluster",
4242
"metadata": {
4343
"labels": {

clients/python-client/examples/use-raw-with-api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from python_client import kuberay_cluster_api
2222

2323
cluster_body: dict = {
24-
"apiVersion": "ray.io/v1alpha1",
24+
"apiVersion": "ray.io/v1",
2525
"kind": "RayCluster",
2626
"metadata": {
2727
"labels": {"controller-tools.k8s.io": "1.0", "demo-cluster": "yes"},
@@ -59,7 +59,7 @@
5959

6060

6161
cluster_body2: dict = {
62-
"apiVersion": "ray.io/v1alpha1",
62+
"apiVersion": "ray.io/v1",
6363
"kind": "RayCluster",
6464
"metadata": {
6565
"labels": {"controller-tools.k8s.io": "1.0", "demo-cluster": "yes"},

0 commit comments

Comments
 (0)