aquafire / add_remove_labels.py

Last active 6 months ago

Like 0

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

Revision 574f1a16e6286366e50d4a89259009d50f85b808

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 main():
27 lk = AsyncClient()
28 await set_feature_label(lk, "feature-core-k8s2-w9-dpc", "test", "nvidia")
29
30
31if __name__ == "__main__":
32 asyncio.run(main())
33