Skip to content

Commit 341f9cc

Browse files
committed
control: add namespace to run
1 parent ccc4d5b commit 341f9cc

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/warnet/control.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,21 @@ def get_active_network(namespace):
221221
"--source_dir", type=click.Path(exists=True, file_okay=False, dir_okay=True), required=False
222222
)
223223
@click.argument("additional_args", nargs=-1, type=click.UNPROCESSED)
224-
def run(scenario_file: str, debug: bool, source_dir, additional_args: tuple[str]):
224+
@click.option("--namespace", default=None, show_default=True)
225+
def run(
226+
scenario_file: str,
227+
debug: bool,
228+
source_dir,
229+
additional_args: tuple[str],
230+
namespace: Optional[str],
231+
):
225232
"""
226233
Run a scenario from a file.
227234
Pass `-- --help` to get individual scenario help
228235
"""
236+
if not namespace:
237+
namespace = get_default_namespace()
238+
229239
scenario_path = Path(scenario_file).resolve()
230240
scenario_dir = scenario_path.parent if not source_dir else Path(source_dir).resolve()
231241
scenario_name = scenario_path.stem
@@ -235,7 +245,6 @@ def run(scenario_file: str, debug: bool, source_dir, additional_args: tuple[str]
235245

236246
# Collect tank data for warnet.json
237247
name = f"commander-{scenario_name.replace('_', '')}-{int(time.time())}"
238-
namespace = get_default_namespace()
239248
tankpods = get_mission("tank")
240249
tanks = [
241250
{
@@ -323,18 +332,20 @@ def filter(path):
323332
print(f"Error: {e.stderr}")
324333

325334
# upload scenario files and network data to the init container
326-
wait_for_init(name)
335+
wait_for_init(name, namespace=namespace)
327336
if write_file_to_container(
328-
name, "init", "/shared/warnet.json", warnet_data
329-
) and write_file_to_container(name, "init", "/shared/archive.pyz", archive_data):
337+
name, "init", "/shared/warnet.json", warnet_data, namespace=namespace
338+
) and write_file_to_container(
339+
name, "init", "/shared/archive.pyz", archive_data, namespace=namespace
340+
):
330341
print(f"Successfully uploaded scenario data to commander: {scenario_name}")
331342

332343
if debug:
333344
print("Waiting for commander pod to start...")
334-
wait_for_pod(name)
335-
_logs(pod_name=name, follow=True)
345+
wait_for_pod(name, namespace=namespace)
346+
_logs(pod_name=name, follow=True, namespace=namespace)
336347
print("Deleting pod...")
337-
delete_pod(name)
348+
delete_pod(name, namespace=namespace)
338349

339350

340351
@click.command()

0 commit comments

Comments
 (0)