Skip to content
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

DM-42029: Add support for label selectors in mock list_node #225

Merged
merged 1 commit into from
Dec 7, 2023
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 changelog.d/20231205_164453_rra_DM_42029.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### New features

- Add support for label selectors in the `list_node` method of the Kubernetes mock.
16 changes: 13 additions & 3 deletions src/safir/testing/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def set_nodes_for_test(self, nodes: list[V1Node]) -> None:
nodes
New node list to return.
"""
self._nodes = V1NodeList(items=nodes)
self._nodes = nodes

# CUSTOM OBJECT API

Expand Down Expand Up @@ -1805,12 +1805,17 @@ async def read_namespaced_network_policy(
# NODE API

async def list_node(
self, *, _request_timeout: float | None = None
self,
*,
label_selector: str | None = None,
_request_timeout: float | None = None,
) -> V1NodeList:
"""List node information.

Parameters
----------
label_selector
Which objects to retrieve. All labels must match.
_request_timeout
Ignored, accepted for compatibility with the Kubernetes API.

Expand All @@ -1821,7 +1826,12 @@ async def list_node(
if any.
"""
self._maybe_error("list_node")
return self._nodes
nodes = [
n
for n in self._nodes
if _check_labels(n.metadata.labels, label_selector)
]
return V1NodeList(items=nodes)

# PERSISTENTVOLUMECLAIM API

Expand Down