Skip to content

Adding validation for local_queue provided in cluster config #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/codeflare_sdk/utils/generate_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,26 @@ def get_default_kueue_name(namespace: str):
)


def local_queue_exists(namespace: str, local_queue_name: str):
# get all local queues in the namespace
try:
config_check()
api_instance = client.CustomObjectsApi(api_config_handler())
local_queues = api_instance.list_namespaced_custom_object(
group="kueue.x-k8s.io",
version="v1beta1",
namespace=namespace,
plural="localqueues",
)
except Exception as e: # pragma: no cover
return _kube_api_error_handling(e)
# check if local queue with the name provided in cluster config exists
for lq in local_queues["items"]:
if lq["metadata"]["name"] == local_queue_name:
return True
return False


def write_components(
user_yaml: dict,
output_file_name: str,
Expand All @@ -324,6 +344,10 @@ def write_components(
open(output_file_name, "w").close()
lq_name = local_queue or get_default_kueue_name(namespace)
cluster_labels = labels
if not local_queue_exists(namespace, lq_name):
raise ValueError(
"local_queue provided does not exist or is not in this namespace. Please provide the correct local_queue name in Cluster Configuration"
)
with open(output_file_name, "a") as outfile:
for component in components:
if "generictemplate" in component:
Expand Down Expand Up @@ -355,6 +379,10 @@ def load_components(
components = user_yaml.get("spec", "resources")["resources"].get("GenericItems")
lq_name = local_queue or get_default_kueue_name(namespace)
cluster_labels = labels
if not local_queue_exists(namespace, lq_name):
raise ValueError(
"local_queue provided does not exist or is not in this namespace. Please provide the correct local_queue name in Cluster Configuration"
)
for component in components:
if "generictemplate" in component:
if (
Expand Down
8 changes: 8 additions & 0 deletions tests/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ def test_cluster_creation_no_mcad_local_queue(mocker):
"kubernetes.client.CustomObjectsApi.get_cluster_custom_object",
return_value={"spec": {"domain": "apps.cluster.awsroute.org"}},
)
mocker.patch(
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
return_value=get_local_queue("kueue.x-k8s.io", "v1beta1", "ns", "localqueues"),
)
config = createClusterConfig()
config.name = "unit-test-cluster-ray"
config.mcad = False
Expand Down Expand Up @@ -3015,6 +3019,10 @@ def test_cluster_throw_for_no_raycluster(mocker: MockerFixture):
"codeflare_sdk.utils.generate_yaml.get_default_kueue_name",
return_value="default",
)
mocker.patch(
"codeflare_sdk.utils.generate_yaml.local_queue_exists",
return_value="true",
)

def throw_if_getting_raycluster(group, version, namespace, plural):
if plural == "rayclusters":
Expand Down