Files
Bryan KeaneandGitHub b2fd91b58c [feat][python-client]: Add suspend, resubmit, & delete logic, and improve status reporting in python client (#4026)
* [feat][python-client]: add functionality to stop and delete a job

* [feat][python-client]: improve status watching to watch job deployment status

* [feat][python-client]: add get_job and list_jobs to python client. test improvements
2025-09-04 18:50:14 -07:00

136 lines
4.8 KiB
Python

import time
from python_client import constants
def create_job_with_cluster_selector(
job_name,
namespace,
cluster_name,
entrypoint="python -c \"import ray; ray.init(); @ray.remote\ndef hello(): return 'Hello from Ray!'; print(ray.get(hello.remote()))\"",
labels=None,
):
job_body = {
"apiVersion": constants.GROUP + "/" + constants.JOB_VERSION,
"kind": constants.JOB_KIND,
"metadata": {
"name": job_name,
"namespace": namespace,
"labels": {
"app.kubernetes.io/name": job_name,
"app.kubernetes.io/managed-by": "kuberay",
},
},
"spec": {
"clusterSelector": {
"ray.io/cluster": cluster_name,
},
"entrypoint": entrypoint,
"submissionMode": "K8sJobMode",
},
}
# Add any additional labels if provided
if labels:
job_body["metadata"]["labels"].update(labels)
return job_body
def create_job_with_ray_cluster_spec(
job_name,
namespace,
entrypoint="python -c \"import ray; ray.init(); @ray.remote\ndef hello(): return 'Hello from Ray!'; print(ray.get(hello.remote()))\"",
labels=None,
):
job_body = {
"apiVersion": constants.GROUP + "/" + constants.JOB_VERSION,
"kind": constants.JOB_KIND,
"metadata": {
"name": job_name,
"namespace": namespace,
"labels": {
"app.kubernetes.io/name": job_name,
"app.kubernetes.io/managed-by": "kuberay",
},
},
"spec": {
"rayClusterSpec": {
"headGroupSpec": {
"serviceType": "ClusterIP",
"replicas": 1,
"rayStartParams": {
"dashboard-host": "0.0.0.0",
},
"template": {
"spec": {
"containers": [
{
"name": "ray-head",
"image": "rayproject/ray:2.48.0",
"ports": [
{"containerPort": 6379, "name": "gcs"},
{
"containerPort": 8265,
"name": "dashboard",
},
{
"containerPort": 10001,
"name": "client",
},
],
"resources": {
"limits": {
"cpu": "1",
"memory": "2Gi",
},
"requests": {
"cpu": "500m",
"memory": "1Gi",
},
},
}
]
}
},
},
"workerGroupSpecs": [
{
"groupName": "small-worker",
"replicas": 1,
"rayStartParams": {
"num-cpus": "1",
},
"template": {
"spec": {
"containers": [
{
"name": "ray-worker",
"image": "rayproject/ray:2.48.0",
"resources": {
"limits": {
"cpu": "1",
"memory": "1Gi",
},
"requests": {
"cpu": "500m",
"memory": "512Mi",
},
},
}
]
}
},
}
],
},
"entrypoint": entrypoint,
"submissionMode": "K8sJobMode",
"shutdownAfterJobFinishes": True,
},
}
if labels:
job_body["metadata"]["labels"].update(labels)
return job_body