Skip to content

Commit 329340e

Browse files
add priorities and schedulingSpec to SDK
1 parent 4593dd5 commit 329340e

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

src/codeflare_sdk/cluster/cluster.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ def create_app_wrapper(self):
8989
instascale = self.config.instascale
9090
instance_types = self.config.machine_types
9191
env = self.config.envs
92+
<<<<<<< HEAD
9293
local_interactive = self.config.local_interactive
9394
image_pull_secrets = self.config.image_pull_secrets
95+
=======
96+
priority = self.config.priority
97+
>>>>>>> 7e7a311 ( add priorities and schedulingSpec to SDK)
9498
return generate_appwrapper(
9599
name=name,
96100
namespace=namespace,
@@ -105,8 +109,12 @@ def create_app_wrapper(self):
105109
instascale=instascale,
106110
instance_types=instance_types,
107111
env=env,
112+
<<<<<<< HEAD
108113
local_interactive=local_interactive,
109114
image_pull_secrets=image_pull_secrets,
115+
=======
116+
priority=priority,
117+
>>>>>>> 7e7a311 ( add priorities and schedulingSpec to SDK)
110118
)
111119

112120
# creates a new cluster with the provided or default spec

src/codeflare_sdk/cluster/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ class ClusterConfiguration:
4747
image: str = "quay.io/project-codeflare/ray:2.5.0-py38-cu116"
4848
local_interactive: bool = False
4949
image_pull_secrets: list = field(default_factory=list)
50+

src/codeflare_sdk/utils/generate_yaml.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,27 @@ def update_labels(yaml, instascale, instance_types):
8989
metadata.pop("labels")
9090

9191

92+
def update_priority(yaml, item, priority):
93+
if priority not in ["low", "default", "high"]:
94+
sys.exit("Priority must be 'low', 'default', or 'high'")
95+
96+
priority_levels = {
97+
"low": (1, "low-priority"),
98+
"default": (5, "default-priority"),
99+
"high": (10, "high-priority"),
100+
}
101+
102+
priority_level = priority_levels[priority]
103+
spec = yaml.get("spec")
104+
spec["priority"] = priority_level[0]
105+
# spec["SchedulingSpec"]["priorityClassName"] = priority_level
106+
if "generictemplate" in item.keys():
107+
head = item.get("generictemplate").get("spec").get("headGroupSpec")
108+
worker = item.get("generictemplate").get("spec").get("workerGroupSpecs")[0]
109+
head["template"]["spec"]["priorityClassName"] = priority_level[1]
110+
worker["template"]["spec"]["priorityClassName"] = priority_level[1]
111+
112+
92113
def update_custompodresources(
93114
item, min_cpu, max_cpu, min_memory, max_memory, gpu, workers
94115
):
@@ -175,6 +196,11 @@ def update_resources(spec, min_cpu, max_cpu, min_memory, max_memory, gpu):
175196
limits["nvidia.com/gpu"] = gpu
176197

177198

199+
def update_scheduling_spec(yaml, workers):
200+
spec = yaml.get("spec")
201+
spec["schedulingSpec"]["minAvailable"] = workers + 1
202+
203+
178204
def update_nodes(
179205
item,
180206
appwrapper_name,
@@ -346,6 +372,7 @@ def generate_appwrapper(
346372
env,
347373
local_interactive: bool,
348374
image_pull_secrets: list,
375+
priority: str,
349376
):
350377
user_yaml = read_template(template)
351378
appwrapper_name, cluster_name = gen_names(name)
@@ -354,6 +381,8 @@ def generate_appwrapper(
354381
route_item = resources["resources"].get("GenericItems")[1]
355382
update_names(user_yaml, item, appwrapper_name, cluster_name, namespace)
356383
update_labels(user_yaml, instascale, instance_types)
384+
update_priority(user_yaml, item, priority)
385+
update_scheduling_spec(user_yaml, workers)
357386
update_custompodresources(
358387
item, min_cpu, max_cpu, min_memory, max_memory, gpu, workers
359388
)

tests/test-case.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
name: unit-test-cluster
77
namespace: ns
88
spec:
9-
priority: 9
9+
priority: 1
1010
resources:
1111
GenericItems:
1212
- custompodresources:
@@ -176,6 +176,7 @@ spec:
176176
do echo waiting for myservice; sleep 2; done
177177
image: busybox:1.28
178178
name: init-myservice
179+
priorityClassName: low-priority
179180
replicas: 1
180181
- generictemplate:
181182
apiVersion: route.openshift.io/v1
@@ -193,3 +194,5 @@ spec:
193194
name: unit-test-cluster-head-svc
194195
replicas: 1
195196
Items: []
197+
schedulingSpec:
198+
minAvailable: 3

tests/unit_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ def test_config_creation():
228228
instascale=True,
229229
machine_types=["cpu.small", "gpu.large"],
230230
image_pull_secrets=["unit-test-pull-secret"],
231+
priority="low",
231232
)
232233

233234
assert config.name == "unit-test-cluster" and config.namespace == "ns"
@@ -240,11 +241,13 @@ def test_config_creation():
240241
assert config.instascale
241242
assert config.machine_types == ["cpu.small", "gpu.large"]
242243
assert config.image_pull_secrets == ["unit-test-pull-secret"]
244+
assert config.priority == "low"
243245
return config
244246

245247

246248
def test_cluster_creation():
247249
cluster = Cluster(test_config_creation())
250+
print(cluster.app_wrapper_yaml)
248251
assert cluster.app_wrapper_yaml == "unit-test-cluster.yaml"
249252
assert cluster.app_wrapper_name == "unit-test-cluster"
250253
assert filecmp.cmp(

0 commit comments

Comments
 (0)