Skip to content

Commit

Permalink
adding validation for local_queue provided in cluster config
Browse files Browse the repository at this point in the history
  • Loading branch information
Fiona-Waters authored and openshift-merge-bot[bot] committed May 23, 2024
1 parent 7d758eb commit 32cb751
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
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 @@ -3046,6 +3050,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

0 comments on commit 32cb751

Please sign in to comment.