Skip to content

Commit c95c06b

Browse files
committed
user labels should also be added to ray cluster wrapped in appwrapper
1 parent b0551dd commit c95c06b

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
@@ -239,10 +239,16 @@ def add_queue_label(item: dict, namespace: str, local_queue: Optional[str]):
239239
item["metadata"]["labels"].update({"kueue.x-k8s.io/queue-name": lq_name})
240240

241241

242+
def augment_labels(item: dict, labels: dict):
243+
if "template" in item:
244+
if not "labels" in item["template"]["metadata"]:
245+
item["template"]["metadata"]["labels"] = {}
246+
item["template"]["metadata"]["labels"].update(labels)
247+
248+
242249
def write_components(
243250
user_yaml: dict,
244251
output_file_name: str,
245-
labels: dict,
246252
):
247253
# Create the directory if it doesn't exist
248254
directory_path = os.path.dirname(output_file_name)
@@ -251,12 +257,9 @@ def write_components(
251257

252258
components = user_yaml.get("spec", "resources").get("components")
253259
open(output_file_name, "w").close()
254-
cluster_labels = labels
255260
with open(output_file_name, "a") as outfile:
256261
for component in components:
257262
if "template" in component:
258-
labels = component["template"]["metadata"]["labels"]
259-
labels.update(cluster_labels)
260263
outfile.write("---\n")
261264
yaml.dump(component["template"], outfile, default_flow_style=False)
262265
print(f"Written to: {output_file_name}")
@@ -265,15 +268,11 @@ def write_components(
265268
def load_components(
266269
user_yaml: dict,
267270
name: str,
268-
labels: dict,
269271
):
270272
component_list = []
271273
components = user_yaml.get("spec", "resources").get("components")
272-
cluster_labels = labels
273274
for component in components:
274275
if "template" in component:
275-
labels = component["template"]["metadata"]["labels"]
276-
labels.update(cluster_labels)
277276
component_list.append(component["template"])
278277

279278
resources = "---\n" + "---\n".join(
@@ -341,11 +340,12 @@ def generate_appwrapper(
341340
head_gpus,
342341
)
343342

343+
augment_labels(item, labels)
344+
344345
if appwrapper:
345346
add_queue_label(user_yaml, namespace, local_queue)
346347
else:
347-
if "template" in item:
348-
add_queue_label(item["template"], namespace, local_queue)
348+
add_queue_label(item["template"], namespace, local_queue)
349349

350350
directory_path = os.path.expanduser("~/.codeflare/resources/")
351351
outfile = os.path.join(directory_path, appwrapper_name + ".yaml")
@@ -354,11 +354,11 @@ def generate_appwrapper(
354354
if appwrapper:
355355
write_user_appwrapper(user_yaml, outfile)
356356
else:
357-
write_components(user_yaml, outfile, labels)
357+
write_components(user_yaml, outfile)
358358
return outfile
359359
else:
360360
if appwrapper:
361361
user_yaml = load_appwrapper(user_yaml, name)
362362
else:
363-
user_yaml = load_components(user_yaml, name, labels)
363+
user_yaml = load_components(user_yaml, name)
364364
return user_yaml

0 commit comments

Comments
 (0)