aboutsummaryrefslogtreecommitdiffstats
path: root/arthur/apis/kubernetes/nodes.py
blob: 3221a158dabc5138a4134b24ce9442f407a6b393 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""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_client:
        api = client.CoreV1Api(api_client)
        return await api.list_node()


async def _change_cordon(node: str, *, cordon: bool) -> None:
    async with ApiClient() as api_client:
        api = client.CoreV1Api(api_client)
        await api.patch_node(
            node,
            body={"spec": {"unschedulable": cordon}},
        )


async def cordon_node(node: str) -> None:
    """Cordon a Kubernetes node."""
    await _change_cordon(node, cordon=True)


async def uncordon_node(node: str) -> None:
    """Uncordon a Kubernetes node."""
    await _change_cordon(node, cordon=False)