aquafire / add_remove_labels.py

Last active 6 months ago

Like 0

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

aquafire revised this gist 10 months ago · bd8d132

1 file changed, 16 insertions

add-remove_labels.py
@@ -23,6 +23,22 @@ async def set_feature_label(
23 23 )
24 24
25 25
26 + async 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 +
26 42 async def main():
27 43 lk = AsyncClient()
28 44 await set_feature_label(lk, "feature-core-k8s2-w9-dpc", "test", "nvidia")

aquafire revised this gist 10 months ago · 574f1a1

1 file changed, 32 insertions

add-remove_labels.py (file created)
@@ -0,0 +1,32 @@
1 + import asyncio
2 +
3 + from lightkube import AsyncClient
4 + from lightkube.resources.core_v1 import Node
5 + from lightkube.types import PatchType
6 +
7 +
8 + async 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 +
26 + async def main():
27 + lk = AsyncClient()
28 + await set_feature_label(lk, "feature-core-k8s2-w9-dpc", "test", "nvidia")
29 +
30 +
31 + if __name__ == "__main__":
32 + asyncio.run(main())