From 163bd253674d67d1bcc7ec75b78cbb63c341773c Mon Sep 17 00:00:00 2001 From: Roi Glinik Date: Tue, 18 Jul 2023 16:10:53 +0300 Subject: [PATCH] Drain node action - add short summary string (#995) * drain node action, add short summary string --- playbooks/robusta_playbooks/node_actions.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/playbooks/robusta_playbooks/node_actions.py b/playbooks/robusta_playbooks/node_actions.py index 6284e6bb9..15e8ccc0a 100644 --- a/playbooks/robusta_playbooks/node_actions.py +++ b/playbooks/robusta_playbooks/node_actions.py @@ -67,6 +67,7 @@ def drain(event: NodeEvent): ) msg = "" + evicting = skipping = deleting = errors = 0 for pod in pods.items: name = pod.metadata.name namespace = pod.metadata.namespace @@ -74,22 +75,33 @@ def drain(event: NodeEvent): owner_list: List[V1OwnerReference] = pod.metadata.owner_references if pod.metadata.owner_references else [] if any(owner.kind == "DaemonSet" for owner in owner_list): msg += f"Skipping {namespace}/DaemonSet/{name}\n" + skipping += 1 continue try: body = client.V1Eviction(metadata=client.V1ObjectMeta(name=name, namespace=namespace)) api.create_namespaced_pod_eviction(name, namespace, body, pretty="True") - action = "Evicting" if owner_list else "Deleting" + action = "Evicting" + if owner_list: + evicting += 1 + else: + action = "Deleting" + deleting += 1 + msg += f"{action} {namespace}/Pod/{name}\n" except Exception as e: msg += f"Error evicting {namespace}/Pod/{name} {e}\n" + errors += 1 continue event.add_enrichment( [ + MarkdownBlock( + f"Drain node {node.metadata.name} \nEvicting {evicting} pod(s), deleting {deleting} pod(s), skipping {skipping} pod(s) and {errors} Error(s)." + ), FileBlock( filename=f"Drain {node.metadata.name} report.log", contents=f"drain node {node.metadata.name} \n\n{msg}".encode(), - ) + ), ] )