Skip to content

Fix get_cluster for cases without default local_queue #538

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 2 commits into from
May 21, 2024
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
3 changes: 3 additions & 0 deletions src/codeflare_sdk/cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,9 @@ def from_k8_cluster_object(
mcad=mcad,
write_to_file=write_to_file,
verify_tls=verify_tls,
local_queue=rc["metadata"]
.get("labels", dict())
.get("kueue.x-k8s.io/queue-name", None),
)
return Cluster(cluster_config)

Expand Down
31 changes: 31 additions & 0 deletions tests/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,7 @@ def get_ray_obj(group, version, namespace, plural, cls=None):
"resourceName": "quicktest",
"workload.codeflare.dev/appwrapper": "quicktest",
"orderedinstance": "m4.xlarge_g4dn.xlarge",
"kueue.x-k8s.io/queue-name": "team-a-queue",
},
"managedFields": [
{
Expand Down Expand Up @@ -2483,6 +2484,36 @@ def test_get_cluster(mocker):
assert cluster_config.num_workers == 1


def test_get_cluster_no_mcad(mocker):
mocker.patch("kubernetes.client.ApisApi.get_api_versions")
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
mocker.patch(
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
side_effect=get_ray_obj,
)
mocker.patch(
"kubernetes.client.NetworkingV1Api.list_namespaced_ingress",
return_value=ingress_retrieval(cluster_name="quicktest", client_ing=True),
)
cluster = get_cluster("quicktest")
cluster_config = cluster.config
assert cluster_config.name == "quicktest" and cluster_config.namespace == "ns"
assert (
"m4.xlarge" in cluster_config.machine_types
and "g4dn.xlarge" in cluster_config.machine_types
)
assert cluster_config.min_cpus == 1 and cluster_config.max_cpus == 1
assert cluster_config.min_memory == "2G" and cluster_config.max_memory == "2G"
assert cluster_config.num_gpus == 0
assert cluster_config.instascale
assert (
cluster_config.image
== "ghcr.io/foundation-model-stack/base:ray2.1.0-py38-gpu-pytorch1.12.0cu116-20221213-193103"
)
assert cluster_config.num_workers == 1
assert cluster_config.local_queue == "team-a-queue"


def route_retrieval(group, version, namespace, plural, name):
assert group == "route.openshift.io"
assert version == "v1"
Expand Down