@@ -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,6 +344,10 @@ 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
347
+ if not local_queue_exists (namespace , lq_name ):
348
+ raise ValueError (
349
+ "local_queue provided does not exist or is not in this namespace. Please provide the correct local_queue name in Cluster Configuration"
350
+ )
327
351
with open (output_file_name , "a" ) as outfile :
328
352
for component in components :
329
353
if "generictemplate" in component :
@@ -355,6 +379,10 @@ def load_components(
355
379
components = user_yaml .get ("spec" , "resources" )["resources" ].get ("GenericItems" )
356
380
lq_name = local_queue or get_default_kueue_name (namespace )
357
381
cluster_labels = labels
382
+ if not local_queue_exists (namespace , lq_name ):
383
+ raise ValueError (
384
+ "local_queue provided does not exist or is not in this namespace. Please provide the correct local_queue name in Cluster Configuration"
385
+ )
358
386
for component in components :
359
387
if "generictemplate" in component :
360
388
if (
0 commit comments