Skip to content

Commit 50d8e7c

Browse files
committed
user labels should also be added to ray cluster wrapped in appwrapper
1 parent 33a1f44 commit 50d8e7c

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/codeflare_sdk/utils/generate_yaml.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,16 @@ def add_queue_label(item: dict, namespace: str, local_queue: Optional[str]):
215215
item["metadata"]["labels"].update({"kueue.x-k8s.io/queue-name": lq_name})
216216

217217

218+
def augment_labels(item: dict, labels: dict):
219+
if "template" in item:
220+
if not "labels" in item["template"]["metadata"]:
221+
item["template"]["metadata"]["labels"] = {}
222+
item["template"]["metadata"]["labels"].update(labels)
223+
224+
218225
def write_components(
219226
user_yaml: dict,
220227
output_file_name: str,
221-
labels: dict,
222228
):
223229
# Create the directory if it doesn't exist
224230
directory_path = os.path.dirname(output_file_name)
@@ -227,12 +233,9 @@ def write_components(
227233

228234
components = user_yaml.get("spec", "resources").get("components")
229235
open(output_file_name, "w").close()
230-
cluster_labels = labels
231236
with open(output_file_name, "a") as outfile:
232237
for component in components:
233238
if "template" in component:
234-
labels = component["template"]["metadata"]["labels"]
235-
labels.update(cluster_labels)
236239
outfile.write("---\n")
237240
yaml.dump(component["template"], outfile, default_flow_style=False)
238241
print(f"Written to: {output_file_name}")
@@ -241,15 +244,11 @@ def write_components(
241244
def load_components(
242245
user_yaml: dict,
243246
name: str,
244-
labels: dict,
245247
):
246248
component_list = []
247249
components = user_yaml.get("spec", "resources").get("components")
248-
cluster_labels = labels
249250
for component in components:
250251
if "template" in component:
251-
labels = component["template"]["metadata"]["labels"]
252-
labels.update(cluster_labels)
253252
component_list.append(component["template"])
254253

255254
resources = "---\n" + "---\n".join(
@@ -317,11 +316,12 @@ def generate_appwrapper(
317316
head_gpus,
318317
)
319318

319+
augment_labels(item, labels)
320+
320321
if appwrapper:
321322
add_queue_label(user_yaml, namespace, local_queue)
322323
else:
323-
if "template" in item:
324-
add_queue_label(item["template"], namespace, local_queue)
324+
add_queue_label(item["template"], namespace, local_queue)
325325

326326
directory_path = os.path.expanduser("~/.codeflare/resources/")
327327
outfile = os.path.join(directory_path, appwrapper_name + ".yaml")
@@ -330,11 +330,11 @@ def generate_appwrapper(
330330
if appwrapper:
331331
write_user_appwrapper(user_yaml, outfile)
332332
else:
333-
write_components(user_yaml, outfile, labels)
333+
write_components(user_yaml, outfile)
334334
return outfile
335335
else:
336336
if appwrapper:
337337
user_yaml = load_appwrapper(user_yaml, name)
338338
else:
339-
user_yaml = load_components(user_yaml, name, labels)
339+
user_yaml = load_components(user_yaml, name)
340340
return user_yaml

0 commit comments

Comments
 (0)