Skip to content

Commit 96ceac8

Browse files
committed
remove kubectl from stop_scenarios
1 parent d90c47a commit 96ceac8

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
@@ -26,7 +26,7 @@
2626
snapshot_bitcoin_datadir,
2727
wait_for_pod,
2828
)
29-
from .process import run_command, stream_command
29+
from .process import run_command
3030

3131
console = Console()
3232

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

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

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

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

0 commit comments

Comments
 (0)