@@ -208,11 +208,16 @@ def get_default_kueue_name(namespace: str):
208
208
)
209
209
210
210
211
+ def add_queue_label (item : dict , namespace : str , local_queue : Optional [str ]):
212
+ lq_name = local_queue or get_default_kueue_name (namespace )
213
+ if not "labels" in item ["metadata" ]:
214
+ item ["metadata" ]["labels" ] = {}
215
+ item ["metadata" ]["labels" ].update ({"kueue.x-k8s.io/queue-name" : lq_name })
216
+
217
+
211
218
def write_components (
212
219
user_yaml : dict ,
213
220
output_file_name : str ,
214
- namespace : str ,
215
- local_queue : Optional [str ],
216
221
labels : dict ,
217
222
):
218
223
# Create the directory if it doesn't exist
@@ -222,13 +227,11 @@ def write_components(
222
227
223
228
components = user_yaml .get ("spec" , "resources" ).get ("components" )
224
229
open (output_file_name , "w" ).close ()
225
- lq_name = local_queue or get_default_kueue_name (namespace )
226
230
cluster_labels = labels
227
231
with open (output_file_name , "a" ) as outfile :
228
232
for component in components :
229
233
if "template" in component :
230
234
labels = component ["template" ]["metadata" ]["labels" ]
231
- labels .update ({"kueue.x-k8s.io/queue-name" : lq_name })
232
235
labels .update (cluster_labels )
233
236
outfile .write ("---\n " )
234
237
yaml .dump (component ["template" ], outfile , default_flow_style = False )
@@ -238,18 +241,14 @@ def write_components(
238
241
def load_components (
239
242
user_yaml : dict ,
240
243
name : str ,
241
- namespace : str ,
242
- local_queue : Optional [str ],
243
244
labels : dict ,
244
245
):
245
246
component_list = []
246
247
components = user_yaml .get ("spec" , "resources" ).get ("components" )
247
- lq_name = local_queue or get_default_kueue_name (namespace )
248
248
cluster_labels = labels
249
249
for component in components :
250
250
if "template" in component :
251
251
labels = component ["template" ]["metadata" ]["labels" ]
252
- labels .update ({"kueue.x-k8s.io/queue-name" : lq_name })
253
252
labels .update (cluster_labels )
254
253
component_list .append (component ["template" ])
255
254
@@ -318,18 +317,24 @@ def generate_appwrapper(
318
317
head_gpus ,
319
318
)
320
319
320
+ if appwrapper :
321
+ add_queue_label (user_yaml , namespace , local_queue )
322
+ else :
323
+ if "template" in item :
324
+ add_queue_label (item ["template" ], namespace , local_queue )
325
+
321
326
directory_path = os .path .expanduser ("~/.codeflare/resources/" )
322
327
outfile = os .path .join (directory_path , appwrapper_name + ".yaml" )
323
328
324
329
if write_to_file :
325
330
if appwrapper :
326
331
write_user_appwrapper (user_yaml , outfile )
327
332
else :
328
- write_components (user_yaml , outfile , namespace , local_queue , labels )
333
+ write_components (user_yaml , outfile , labels )
329
334
return outfile
330
335
else :
331
336
if appwrapper :
332
337
user_yaml = load_appwrapper (user_yaml , name )
333
338
else :
334
- user_yaml = load_components (user_yaml , name , namespace , local_queue , labels )
339
+ user_yaml = load_components (user_yaml , name , labels )
335
340
return user_yaml
0 commit comments