Skip to content

Commit 95f72a9

Browse files
committed
return nodes operated on
Signed-off-by: Sylvain Hellegouarch <[email protected]>
1 parent 38370dc commit 95f72a9

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
* Draining multiple nodes only drained a single one
1010

11+
### Changed
12+
13+
* Nodes actions now return the list of node names they operated on
14+
1115
## [0.33.0][] - 2023-10-29
1216

1317
[0.33.0]: https://github.com/chaostoolkit/chaostoolkit-kubernetes/compare/0.32.1...0.33.0

chaosk8s/node/actions.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def delete_nodes(
102102
secrets: Secrets = None,
103103
pod_label_selector: str = None,
104104
pod_namespace: str = None,
105-
):
105+
) -> List[str]:
106106
"""
107107
Delete nodes gracefully. Select the appropriate nodes by label.
108108
@@ -146,6 +146,7 @@ def delete_nodes(
146146
first=first,
147147
)
148148

149+
deleted = []
149150
body = client.V1DeleteOptions()
150151
for n in nodes:
151152
res = v1.delete_node(
@@ -154,6 +155,10 @@ def delete_nodes(
154155

155156
if res.status != "Success":
156157
logger.debug(f"Terminating nodes failed: {res.message}")
158+
else:
159+
deleted.append(n.metadata.name)
160+
161+
return deleted
157162

158163

159164
def create_node(
@@ -186,7 +191,7 @@ def create_node(
186191
return res
187192

188193

189-
def cordon_node(name: str = None, label_selector: str = None, secrets: Secrets = None):
194+
def cordon_node(name: str = None, label_selector: str = None, secrets: Secrets = None) -> List[str]:
190195
"""
191196
Cordon nodes matching the given label or name, so that no pods
192197
are scheduled on them any longer.
@@ -199,19 +204,23 @@ def cordon_node(name: str = None, label_selector: str = None, secrets: Secrets =
199204

200205
body = {"spec": {"unschedulable": True}}
201206

207+
cordoned = []
202208
for n in nodes:
203209
try:
204210
v1.patch_node(n.metadata.name, body)
211+
cordoned.append(n.metadata.name)
205212
except ApiException as x:
206213
logger.debug(f"Unscheduling node '{n.metadata.name}' failed: {x.body}")
207214
raise ActivityFailed(
208215
f"Failed to unschedule node '{n.metadata.name}': {x.body}"
209216
)
217+
218+
return cordoned
210219

211220

212221
def uncordon_node(
213222
name: str = None, label_selector: str = None, secrets: Secrets = None
214-
):
223+
) -> List[str]:
215224
"""
216225
Uncordon nodes matching the given label name, so that pods can be
217226
scheduled on them again.
@@ -224,15 +233,19 @@ def uncordon_node(
224233

225234
body = {"spec": {"unschedulable": False}}
226235

236+
uncordoned = []
227237
for n in nodes:
228238
try:
229239
v1.patch_node(n.metadata.name, body)
240+
uncordoned.append(n.metadata.name)
230241
except ApiException as x:
231242
logger.debug(f"Scheduling node '{n.metadata.name}' failed: {x.body}")
232243
raise ActivityFailed(
233244
f"Failed to schedule node '{n.metadata.name}': {x.body}"
234245
)
235246

247+
return uncordoned
248+
236249

237250
def drain_nodes(
238251
name: str = None,
@@ -243,7 +256,7 @@ def drain_nodes(
243256
count: int = None,
244257
pod_label_selector: str = None,
245258
pod_namespace: str = None,
246-
) -> bool:
259+
) -> List[str]:
247260
"""
248261
Drain nodes matching the given label or name, so that no pods are scheduled
249262
on them any longer and running pods are evicted.
@@ -390,4 +403,4 @@ def drain_nodes(
390403

391404
time.sleep(10)
392405

393-
return True
406+
return [n.metadata.name for n in nodes]

0 commit comments

Comments
 (0)