Skip to content

Commit

Permalink
Merge pull request #225 from lsst-sqre/tickets/DM-42029
Browse files Browse the repository at this point in the history
DM-42029: Add support for label selectors in mock list_node
  • Loading branch information
rra authored Dec 7, 2023
2 parents d35831d + 0d3d5d3 commit 5cf16d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
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

0 comments on commit 5cf16d0

Please sign in to comment.