@@ -113,10 +113,15 @@ def stop_all_scenarios(scenarios):
113
113
console .print ("[bold green]All scenarios have been stopped.[/bold green]" )
114
114
115
115
116
+ @click .option (
117
+ "--force" ,
118
+ is_flag = True ,
119
+ default = False ,
120
+ help = "Skip confirmations" ,
121
+ )
116
122
@click .command ()
117
- def down ():
123
+ def down (force ):
118
124
"""Bring down a running warnet quickly"""
119
- console .print ("[bold yellow]Bringing down the warnet...[/bold yellow]" )
120
125
121
126
def uninstall_release (namespace , release_name ):
122
127
cmd = f"helm uninstall { release_name } --namespace { namespace } --wait=false"
@@ -128,19 +133,53 @@ def delete_pod(pod_name, namespace):
128
133
subprocess .Popen (cmd , shell = True , stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL )
129
134
return f"Initiated deletion of pod: { pod_name } in namespace { namespace } "
130
135
136
+ namespaces = get_namespaces ()
137
+ print (namespaces )
138
+ release_list : list [dict [str , str ]] = []
139
+ for namespace in namespaces :
140
+ command = f"helm list --namespace { namespace .metadata .name } -o json"
141
+ result = run_command (command )
142
+ if result :
143
+ releases = json .loads (result )
144
+ for release in releases :
145
+ release_list .append ({"namespace" : namespace .metadata .name , "name" : release ["name" ]})
146
+
147
+ if not force :
148
+ affected_namespaces = set ([entry ["namespace" ] for entry in release_list ])
149
+ namespace_listing = "\n " .join (affected_namespaces )
150
+ confirmed = "confirmed"
151
+ click .secho ("Preparing to bring down the running Warnet..." , fg = "yellow" )
152
+ click .secho ("The listed namespaces will be affected:" , fg = "yellow" )
153
+ click .secho (f" { namespace_listing } " , fg = "blue" )
154
+
155
+ proj_answers = inquirer .prompt (
156
+ [
157
+ inquirer .Confirm (
158
+ confirmed ,
159
+ message = click .style (
160
+ "Do you want to bring down the running Warnet?" , fg = "yellow" , bold = False
161
+ ),
162
+ default = False ,
163
+ ),
164
+ ]
165
+ )
166
+ if not proj_answers :
167
+ click .secho ("Operation cancelled by user." , fg = "yellow" )
168
+ sys .exit (0 )
169
+ if proj_answers [confirmed ]:
170
+ click .secho ("Bringing down the warnet..." , fg = "yellow" )
171
+ else :
172
+ click .secho ("Operation cancelled by user" , fg = "yellow" )
173
+ sys .exit (0 )
174
+
131
175
with ThreadPoolExecutor (max_workers = 10 ) as executor :
132
176
futures = []
133
177
134
178
# Uninstall Helm releases
135
- for namespace in get_namespaces ():
136
- command = f"helm list --namespace { namespace .metadata .name } -o json"
137
- result = run_command (command )
138
- if result :
139
- releases = json .loads (result )
140
- for release in releases :
141
- futures .append (
142
- executor .submit (uninstall_release , namespace .metadata .name , release ["name" ])
143
- )
179
+ for release in release_list :
180
+ futures .append (
181
+ executor .submit (uninstall_release , release ["namespace" ], release ["name" ])
182
+ )
144
183
145
184
# Delete remaining pods
146
185
pods = get_pods ()
0 commit comments