Skip to content
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
8 changes: 6 additions & 2 deletions src/codeflare_sdk/common/kueue/kueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def list_local_queues(

Note:
Depending on the version of the local queue API, the available flavors may not be present in the response.
A ``LocalQueue`` may also appear without a ``status`` (or with empty status) until the Kueue controller
reconciles; such queues are still returned, usually without a ``flavors`` key on the dict.

Args:
namespace (str, optional):
Expand All @@ -127,8 +129,10 @@ def list_local_queues(
to_return = []
for lq in local_queues["items"]:
item = {"name": lq["metadata"]["name"]}
if "flavors" in lq["status"]:
item["flavors"] = [f["name"] for f in lq["status"]["flavors"]]
# LocalQueue may exist before Kueue populates .status (RHOAIENG-54719).
lq_status = lq.get("status") or {}
if "flavors" in lq_status:
item["flavors"] = [f["name"] for f in lq_status["flavors"]]
if flavors is not None and not set(flavors).issubset(set(item["flavors"])):
continue
elif flavors is not None:
Expand Down
25 changes: 25 additions & 0 deletions src/codeflare_sdk/common/kueue/test_kueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,31 @@ def test_list_local_queues(mocker):
assert lqs == []


def test_list_local_queues_no_status(mocker):
mocker.patch("kubernetes.client.ApisApi.get_api_versions")
mocker.patch(
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
return_value={
"items": [
{"metadata": {"name": "a"}},
{"metadata": {"name": "b"}, "status": None},
{
"metadata": {"name": "c"},
"status": {"flavors": [{"name": "default"}]},
},
]
},
)
assert list_local_queues("ns") == [
{"name": "a"},
{"name": "b"},
{"name": "c", "flavors": ["default"]},
]
assert list_local_queues("ns", flavors=["default"]) == [
{"name": "c", "flavors": ["default"]},
]


def test_get_default_kueue_name_found(mocker):
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
mock_api_instance = mocker.Mock()
Expand Down
Loading