@@ -308,6 +308,26 @@ def get_default_kueue_name(namespace: str):
308308 )
309309
310310
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+
311331def write_components (
312332 user_yaml : dict ,
313333 output_file_name : str ,
@@ -324,6 +344,10 @@ def write_components(
324344 open (output_file_name , "w" ).close ()
325345 lq_name = local_queue or get_default_kueue_name (namespace )
326346 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+ )
327351 with open (output_file_name , "a" ) as outfile :
328352 for component in components :
329353 if "generictemplate" in component :
@@ -355,6 +379,10 @@ def load_components(
355379 components = user_yaml .get ("spec" , "resources" )["resources" ].get ("GenericItems" )
356380 lq_name = local_queue or get_default_kueue_name (namespace )
357381 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+ )
358386 for component in components :
359387 if "generictemplate" in component :
360388 if (
0 commit comments