diff options
author | 2021-07-18 12:39:03 +0100 | |
---|---|---|
committer | 2021-07-18 12:39:03 +0100 | |
commit | 5a65fe059e5b123e8b3eea11c1b72b46068143c9 (patch) | |
tree | b6cef8dd2461beaaf901876c047bcd5d963e0057 /arthur/apis/kubernetes/nodes.py | |
parent | fix: add missing await on certificates list (diff) |
feat: add APIs for fetching & patching nodes
Diffstat (limited to 'arthur/apis/kubernetes/nodes.py')
-rw-r--r-- | arthur/apis/kubernetes/nodes.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/arthur/apis/kubernetes/nodes.py b/arthur/apis/kubernetes/nodes.py new file mode 100644 index 0000000..ff8a7d6 --- /dev/null +++ b/arthur/apis/kubernetes/nodes.py @@ -0,0 +1,30 @@ +"""APIs for interacting with Kubernetes nodes.""" +from kubernetes_asyncio import client +from kubernetes_asyncio.client.api_client import ApiClient +from kubernetes_asyncio.client.models import V1NodeList + + +async def list_nodes() -> V1NodeList: + """List Kubernetes nodes.""" + async with ApiClient() as api: + api = client.CoreV1Api(api) + return await api.list_node() + + +async def _change_cordon(node: str, cordon: bool) -> None: + async with ApiClient() as api: + api = client.CoreV1Api(api) + await api.patch_node( + node, + body={"spec": {"unschedulable": cordon}}, + ) + + +async def cordon_node(node: str) -> None: + """Cordon a Kubernetes node.""" + await _change_cordon(node, True) + + +async def uncordon_node(node: str) -> None: + """Cordon a Kubernetes node.""" + await _change_cordon(node, False) |