Skip to content

Commit 32cb751

Browse files
adding validation for local_queue provided in cluster config
1 parent 7d758eb commit 32cb751

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Diff for: src/codeflare_sdk/utils/generate_yaml.py

+28
Original file line numberDiff line numberDiff line change
@@ -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+
311331
def 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 (

Diff for: tests/unit_test.py

+8
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ def test_cluster_creation_no_mcad_local_queue(mocker):
344344
"kubernetes.client.CustomObjectsApi.get_cluster_custom_object",
345345
return_value={"spec": {"domain": "apps.cluster.awsroute.org"}},
346346
)
347+
mocker.patch(
348+
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
349+
return_value=get_local_queue("kueue.x-k8s.io", "v1beta1", "ns", "localqueues"),
350+
)
347351
config = createClusterConfig()
348352
config.name = "unit-test-cluster-ray"
349353
config.mcad = False
@@ -3046,6 +3050,10 @@ def test_cluster_throw_for_no_raycluster(mocker: MockerFixture):
30463050
"codeflare_sdk.utils.generate_yaml.get_default_kueue_name",
30473051
return_value="default",
30483052
)
3053+
mocker.patch(
3054+
"codeflare_sdk.utils.generate_yaml.local_queue_exists",
3055+
return_value="true",
3056+
)
30493057

30503058
def throw_if_getting_raycluster(group, version, namespace, plural):
30513059
if plural == "rayclusters":

0 commit comments

Comments
 (0)