Skip to content

Commit 8f3b335

Browse files
committed
user labels should also be added to ray cluster wrapped in appwrapper
1 parent aeef651 commit 8f3b335

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/codeflare_sdk/utils/generate_yaml.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,15 @@ 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 not "labels" in item["metadata"]:
220+
item["metadata"]["labels"] = {}
221+
item["metadata"]["labels"].update(labels)
222+
223+
218224
def write_components(
219225
user_yaml: dict,
220226
output_file_name: str,
221-
labels: dict,
222227
):
223228
# Create the directory if it doesn't exist
224229
directory_path = os.path.dirname(output_file_name)
@@ -227,12 +232,9 @@ def write_components(
227232

228233
components = user_yaml.get("spec", "resources").get("components")
229234
open(output_file_name, "w").close()
230-
cluster_labels = labels
231235
with open(output_file_name, "a") as outfile:
232236
for component in components:
233237
if "template" in component:
234-
labels = component["template"]["metadata"]["labels"]
235-
labels.update(cluster_labels)
236238
outfile.write("---\n")
237239
yaml.dump(component["template"], outfile, default_flow_style=False)
238240
print(f"Written to: {output_file_name}")
@@ -241,15 +243,11 @@ def write_components(
241243
def load_components(
242244
user_yaml: dict,
243245
name: str,
244-
labels: dict,
245246
):
246247
component_list = []
247248
components = user_yaml.get("spec", "resources").get("components")
248-
cluster_labels = labels
249249
for component in components:
250250
if "template" in component:
251-
labels = component["template"]["metadata"]["labels"]
252-
labels.update(cluster_labels)
253251
component_list.append(component["template"])
254252

255253
resources = "---\n" + "---\n".join(
@@ -319,9 +317,10 @@ def generate_appwrapper(
319317

320318
if appwrapper:
321319
add_queue_label(user_yaml, namespace, local_queue)
320+
augment_labels(item["template"], labels)
322321
else:
323-
if "template" in item:
324-
add_queue_label(item["template"], namespace, local_queue)
322+
add_queue_label(item["template"], namespace, local_queue)
323+
augment_labels(item["template"], labels)
325324

326325
directory_path = os.path.expanduser("~/.codeflare/resources/")
327326
outfile = os.path.join(directory_path, appwrapper_name + ".yaml")
@@ -330,11 +329,11 @@ def generate_appwrapper(
330329
if appwrapper:
331330
write_user_appwrapper(user_yaml, outfile)
332331
else:
333-
write_components(user_yaml, outfile, labels)
332+
write_components(user_yaml, outfile)
334333
return outfile
335334
else:
336335
if appwrapper:
337336
user_yaml = load_appwrapper(user_yaml, name)
338337
else:
339-
user_yaml = load_components(user_yaml, name, labels)
338+
user_yaml = load_components(user_yaml, name)
340339
return user_yaml

0 commit comments

Comments
 (0)