@@ -308,6 +308,26 @@ def get_default_kueue_name(namespace: str):
308
308
)
309
309
310
310
311
+ def local_queue_exists (namespace : str , local_queue_name : str ):
312
+ # get all local queues in the namespace
313
+ try :
314
+ config_check ()
315
+ api_instance = client .CustomObjectsApi (api_config_handler ())
316
+ local_queues = api_instance .list_namespaced_custom_object (
317
+ group = "kueue.x-k8s.io" ,
318
+ version = "v1beta1" ,
319
+ namespace = namespace ,
320
+ plural = "localqueues" ,
321
+ )
322
+ except Exception as e : # pragma: no cover
323
+ return _kube_api_error_handling (e )
324
+ # check if local queue with the name provided in cluster config exists
325
+ for lq in local_queues ["items" ]:
326
+ if lq ["metadata" ]["name" ] == local_queue_name :
327
+ return True
328
+ return False
329
+
330
+
311
331
def write_components (
312
332
user_yaml : dict ,
313
333
output_file_name : str ,
@@ -324,24 +344,29 @@ def write_components(
324
344
open (output_file_name , "w" ).close ()
325
345
lq_name = local_queue or get_default_kueue_name (namespace )
326
346
cluster_labels = labels
327
- with open (output_file_name , "a" ) as outfile :
328
- for component in components :
329
- if "generictemplate" in component :
330
- if (
331
- "workload.codeflare.dev/appwrapper"
332
- in component ["generictemplate" ]["metadata" ]["labels" ]
333
- ):
334
- del component ["generictemplate" ]["metadata" ]["labels" ][
347
+ if local_queue_exists (namespace , lq_name ):
348
+ with open (output_file_name , "a" ) as outfile :
349
+ for component in components :
350
+ if "generictemplate" in component :
351
+ if (
335
352
"workload.codeflare.dev/appwrapper"
336
- ]
337
- labels = component ["generictemplate" ]["metadata" ]["labels" ]
338
- labels .update ({"kueue.x-k8s.io/queue-name" : lq_name })
339
- labels .update (cluster_labels )
340
- outfile .write ("---\n " )
341
- yaml .dump (
342
- component ["generictemplate" ], outfile , default_flow_style = False
343
- )
344
- print (f"Written to: { output_file_name } " )
353
+ in component ["generictemplate" ]["metadata" ]["labels" ]
354
+ ):
355
+ del component ["generictemplate" ]["metadata" ]["labels" ][
356
+ "workload.codeflare.dev/appwrapper"
357
+ ]
358
+ labels = component ["generictemplate" ]["metadata" ]["labels" ]
359
+ labels .update ({"kueue.x-k8s.io/queue-name" : lq_name })
360
+ labels .update (cluster_labels )
361
+ outfile .write ("---\n " )
362
+ yaml .dump (
363
+ component ["generictemplate" ], outfile , default_flow_style = False
364
+ )
365
+ print (f"Written to: { output_file_name } " )
366
+ else :
367
+ raise ValueError (
368
+ "local_queue provided does not exist. Please provide the correct local_queue name in Cluster Configuration"
369
+ )
345
370
346
371
347
372
def load_components (
@@ -355,6 +380,10 @@ def load_components(
355
380
components = user_yaml .get ("spec" , "resources" )["resources" ].get ("GenericItems" )
356
381
lq_name = local_queue or get_default_kueue_name (namespace )
357
382
cluster_labels = labels
383
+ if not local_queue_exists (namespace , lq_name ):
384
+ raise ValueError (
385
+ "local_queue provided does not exist or is not in this namespace. Please provide the correct local_queue name in Cluster Configuration"
386
+ )
358
387
for component in components :
359
388
if "generictemplate" in component :
360
389
if (
0 commit comments