diff --git a/changelog.d/20231205_164453_rra_DM_42029.md b/changelog.d/20231205_164453_rra_DM_42029.md new file mode 100644 index 00000000..3b8a636a --- /dev/null +++ b/changelog.d/20231205_164453_rra_DM_42029.md @@ -0,0 +1,3 @@ +### New features + +- Add support for label selectors in the `list_node` method of the Kubernetes mock. diff --git a/src/safir/testing/kubernetes.py b/src/safir/testing/kubernetes.py index 3dc64f51..e67ac6d4 100644 --- a/src/safir/testing/kubernetes.py +++ b/src/safir/testing/kubernetes.py @@ -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 @@ -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. @@ -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