aquafire / add_remove_labels.py

Last active 6 months ago

Like 0

Добавление/удаление меток на ноду

Revision bd8d132f2d82d0ff4d6cfdd6cc8f99f831858938

add-remove_labels.py Raw
1import asyncio
2
3from lightkube import AsyncClient
4from lightkube.resources.core_v1 import Node
5from lightkube.types import PatchType
6
7
8async def set_feature_label(
9 client: AsyncClient, node_name: str, kind: str, variant: str
10):
11 """Add label with feature to the node"""
12 # create patch
13 patch_metadata = [
14 {
15 "op": "add",
16 "path": f"/metadata/labels/node-feature.k8s.dpc24.ru~1{kind}",
17 "value": variant,
18 }
19 ]
20 # run patch
21 await client.patch(
22 Node, name=node_name, obj=patch_metadata, patch_type=PatchType.JSON
23 )
24
25
26async def unset_feature_label(
27 client: AsyncClient, node_name: str, kind: str, variant: str
28):
29 """Remove label with feature to the node"""
30 # delete patch
31 patch_metadata = [
32 {
33 "op": "remove",
34 "path": f"/metadata/labels/node-feature.k8s.dpc24.ru~1{kind}",
35 }
36 ]
37 # run patch
38 await client.patch(
39 Node, name=node_name, obj=patch_metadata, patch_type=PatchType.JSON
40 )
41
42async def main():
43 lk = AsyncClient()
44 await set_feature_label(lk, "feature-core-k8s2-w9-dpc", "test", "nvidia")
45
46
47if __name__ == "__main__":
48 asyncio.run(main())
49