From 57b471fc2bcdc10ce66a8fefcc5c0254cc224d6a Mon Sep 17 00:00:00 2001 From: nikhil1697 Date: Tue, 16 Apr 2024 13:05:11 +0530 Subject: [PATCH 1/2] modify the condition to ensure that it checks for exact match --- kubemarine/kubernetes/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kubemarine/kubernetes/__init__.py b/kubemarine/kubernetes/__init__.py index b038591bd..8cb2dbcb9 100644 --- a/kubemarine/kubernetes/__init__.py +++ b/kubemarine/kubernetes/__init__.py @@ -275,7 +275,11 @@ def drain_nodes(group: NodeGroup, disable_eviction: bool = False, for node in group.get_ordered_members_list(): node_name = node.get_node_name() - if node_name in stdout: + + # Split stdout into lines + stdout_lines = stdout.split('\n') + # Check if node_name exactly matches any line + if node_name in stdout_lines: log.debug("Draining node %s..." % node_name) drain_cmd = prepare_drain_command( cluster, node_name, @@ -299,7 +303,11 @@ def delete_nodes(group: NodeGroup) -> RunnersGroupResult: for node in group.get_ordered_members_list(): node_name = node.get_node_name() - if node_name in stdout: + + # Split stdout into lines + stdout_lines = stdout.split('\n') + # Check if node_name exactly matches any line + if node_name in stdout_lines: log.debug("Deleting node %s from the cluster..." % node_name) control_plane.sudo("kubectl delete node %s" % node_name, hide=False) else: From 78a7662d98b14b99f384b5bc388d1c8b0349a5fd Mon Sep 17 00:00:00 2001 From: nikhil1697 Date: Tue, 16 Apr 2024 17:32:35 +0530 Subject: [PATCH 2/2] ignore first line --- kubemarine/kubernetes/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kubemarine/kubernetes/__init__.py b/kubemarine/kubernetes/__init__.py index 8cb2dbcb9..26c246062 100644 --- a/kubemarine/kubernetes/__init__.py +++ b/kubemarine/kubernetes/__init__.py @@ -277,7 +277,7 @@ def drain_nodes(group: NodeGroup, disable_eviction: bool = False, node_name = node.get_node_name() # Split stdout into lines - stdout_lines = stdout.split('\n') + stdout_lines = stdout.split('\n')[1:] # Check if node_name exactly matches any line if node_name in stdout_lines: log.debug("Draining node %s..." % node_name) @@ -305,7 +305,7 @@ def delete_nodes(group: NodeGroup) -> RunnersGroupResult: node_name = node.get_node_name() # Split stdout into lines - stdout_lines = stdout.split('\n') + stdout_lines = stdout.split('\n')[1:] # Check if node_name exactly matches any line if node_name in stdout_lines: log.debug("Deleting node %s from the cluster..." % node_name)