Skip to content

Commit 4fc22ec

Browse files
committed
control: add namespace to run
1 parent d897bc6 commit 4fc22ec

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
@@ -216,11 +216,21 @@ def get_active_network(namespace):
216216
"--source_dir", type=click.Path(exists=True, file_okay=False, dir_okay=True), required=False
217217
)
218218
@click.argument("additional_args", nargs=-1, type=click.UNPROCESSED)
219-
def run(scenario_file: str, debug: bool, source_dir, additional_args: tuple[str]):
219+
@click.option("--namespace", default=None, show_default=True)
220+
def run(
221+
scenario_file: str,
222+
debug: bool,
223+
source_dir,
224+
additional_args: tuple[str],
225+
namespace: Optional[str],
226+
):
220227
"""
221228
Run a scenario from a file.
222229
Pass `-- --help` to get individual scenario help
223230
"""
231+
if not namespace:
232+
namespace = get_default_namespace()
233+
224234
scenario_path = Path(scenario_file).resolve()
225235
scenario_dir = scenario_path.parent if not source_dir else Path(source_dir).resolve()
226236
scenario_name = scenario_path.stem
@@ -230,7 +240,6 @@ def run(scenario_file: str, debug: bool, source_dir, additional_args: tuple[str]
230240

231241
# Collect tank data for warnet.json
232242
name = f"commander-{scenario_name.replace('_', '')}-{int(time.time())}"
233-
namespace = get_default_namespace()
234243
tankpods = get_mission("tank")
235244
tanks = [
236245
{
@@ -318,18 +327,20 @@ def filter(path):
318327
print(f"Error: {e.stderr}")
319328

320329
# upload scenario files and network data to the init container
321-
wait_for_init(name)
330+
wait_for_init(name, namespace=namespace)
322331
if write_file_to_container(
323-
name, "init", "/shared/warnet.json", warnet_data
324-
) and write_file_to_container(name, "init", "/shared/archive.pyz", archive_data):
332+
name, "init", "/shared/warnet.json", warnet_data, namespace=namespace
333+
) and write_file_to_container(
334+
name, "init", "/shared/archive.pyz", archive_data, namespace=namespace
335+
):
325336
print(f"Successfully uploaded scenario data to commander: {scenario_name}")
326337

327338
if debug:
328339
print("Waiting for commander pod to start...")
329-
wait_for_pod(name)
330-
_logs(pod_name=name, follow=True)
340+
wait_for_pod(name, namespace=namespace)
341+
_logs(pod_name=name, follow=True, namespace=namespace)
331342
print("Deleting pod...")
332-
delete_pod(name)
343+
delete_pod(name, namespace=namespace)
333344

334345

335346
@click.command()

0 commit comments

Comments
 (0)