Skip to content

Commit

Permalink
Add mock Kubernetes read methods for more kinds
Browse files Browse the repository at this point in the history
Add read methods for the Kubernetes object types for which the mock
provided create methods. This is required by the new generic
Kubernetes storage layer in the Nublado lab controller.
  • Loading branch information
rra committed Sep 7, 2023
1 parent aede45c commit d0540c5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelog.d/20230907_135241_rra_DM_40638b.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### New features

- Add `read_` methods for the Kubernetes object types for which the mock provided `create_` methods (`NetworkPolicy` and `PersistentVolumeClaim`).
53 changes: 53 additions & 0 deletions src/safir/testing/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,31 @@ async def create_namespaced_network_policy(
name = body.metadata.name
self._store_object(namespace, "NetworkPolicy", name, body)

async def read_namespaced_network_policy(
self, name: str, namespace: str
) -> V1Pod:
"""Read a network policy object.
Parameters
----------
name
Name of the network policy.
namespace
Namespace of the network policy.
Returns
-------
kubernetes_asyncio.client.V1NetworkPolicy
Network policy object.
Raises
------
kubernetes_asyncio.client.ApiException
Raised with 404 status if the network policy was not found.
"""
self._maybe_error("read_namespaced_network_policy", name, namespace)
return self._get_object(namespace, "NetworkPolicy", name)

# NODE API

async def list_node(self) -> V1NodeList:
Expand Down Expand Up @@ -1469,6 +1494,34 @@ async def create_namespaced_persistent_volume_claim(
namespace, "PersistentVolumeClaim", body.metadata.name, body
)

async def read_namespaced_persistent_volume_claim(
self, name: str, namespace: str
) -> V1PersistentVolumeClaim:
"""Read a persistent volume claim.
Parameters
----------
name
Name of the persistent volume claim.
namespace
Namespace of the persistent volume claim.
Returns
-------
kubernetes_asyncio.client.V1PersistentVolumeClaim
Persistent volume claim object.
Raises
------
kubernetes_asyncio.client.ApiException
Raised with 404 status if the persistent volume claim was not
found.
"""
self._maybe_error(
"read_namespaced_persistent_volume_claim", name, namespace
)
return self._get_object(namespace, "PersistentVolumeClaim", name)

# POD API

async def create_namespaced_pod(self, namespace: str, body: V1Pod) -> None:
Expand Down

0 comments on commit d0540c5

Please sign in to comment.