Skip to content

Commit ceb9093

Browse files
committed
remove kubectl from stop_scenarios
1 parent e6895e0 commit ceb9093

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/warnet/control.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
snapshot_bitcoin_datadir,
2626
wait_for_pod,
2727
)
28-
from .process import run_command, stream_command
28+
from .process import run_command
2929

3030
console = Console()
3131

@@ -80,8 +80,8 @@ def stop_scenario(scenario_name):
8080
"""Stop a single scenario using Helm"""
8181
# Stop the pod immediately (faster than uninstalling)
8282
namespace = get_default_namespace()
83-
cmd = f"kubectl --namespace {namespace} delete pod {scenario_name} --grace-period=0 --force"
84-
if stream_command(cmd):
83+
resp = delete_pod(scenario_name, namespace, grace_period=0, force=True)
84+
if resp.status == "Success":
8585
console.print(f"[bold green]Successfully stopped scenario: {scenario_name}[/bold green]")
8686
else:
8787
console.print(f"[bold red]Failed to stop scenario: {scenario_name}[/bold red]")
@@ -116,11 +116,6 @@ def uninstall_release(namespace, release_name):
116116
subprocess.Popen(cmd, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
117117
return f"Initiated uninstall for: {release_name} in namespace {namespace}"
118118

119-
def delete_pod(pod_name, namespace):
120-
cmd = f"kubectl delete pod --ignore-not-found=true {pod_name} -n {namespace} --grace-period=0 --force"
121-
subprocess.Popen(cmd, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
122-
return f"Initiated deletion of pod: {pod_name} in namespace {namespace}"
123-
124119
with ThreadPoolExecutor(max_workers=10) as executor:
125120
futures = []
126121

@@ -136,7 +131,16 @@ def delete_pod(pod_name, namespace):
136131
# Delete remaining pods
137132
pods = get_pods()
138133
for pod in pods.items:
139-
futures.append(executor.submit(delete_pod, pod.metadata.name, pod.metadata.namespace))
134+
futures.append(
135+
executor.submit(
136+
delete_pod,
137+
pod.metadata.name,
138+
pod.metadata.namespace,
139+
grace_period=0,
140+
force=True,
141+
ignore_not_found=True,
142+
)
143+
)
140144

141145
# Wait for all tasks to complete and print results
142146
for future in as_completed(futures):

0 commit comments

Comments
 (0)