|
18 | 18 | from .constants import COMMANDER_CHART, LOGGING_NAMESPACE
|
19 | 19 | from .deploy import _port_stop_internal
|
20 | 20 | from .k8s import (
|
| 21 | + delete_pod, |
21 | 22 | get_default_namespace,
|
22 | 23 | get_mission,
|
23 | 24 | get_pods,
|
| 25 | + pod_log, |
24 | 26 | snapshot_bitcoin_datadir,
|
25 |
| - pod_log |
| 27 | + wait_for_pod, |
26 | 28 | )
|
27 | 29 | from .process import run_command, stream_command
|
28 | 30 |
|
@@ -164,8 +166,14 @@ def get_active_network(namespace):
|
164 | 166 |
|
165 | 167 | @click.command(context_settings={"ignore_unknown_options": True})
|
166 | 168 | @click.argument("scenario_file", type=click.Path(exists=True, file_okay=True, dir_okay=False))
|
| 169 | +@click.option( |
| 170 | + "--debug", |
| 171 | + is_flag=True, |
| 172 | + default=False, |
| 173 | + help="Stream scenario output and delete container when stopped", |
| 174 | +) |
167 | 175 | @click.argument("additional_args", nargs=-1, type=click.UNPROCESSED)
|
168 |
| -def run(scenario_file: str, additional_args: tuple[str]): |
| 176 | +def run(scenario_file: str, debug: bool, additional_args: tuple[str]): |
169 | 177 | """
|
170 | 178 | Run a scenario from a file.
|
171 | 179 | Pass `-- --help` to get individual scenario help
|
@@ -233,11 +241,22 @@ def run(scenario_file: str, additional_args: tuple[str]):
|
233 | 241 | print(f"Failed to start scenario: {scenario_name}")
|
234 | 242 | print(f"Error: {e.stderr}")
|
235 | 243 |
|
| 244 | + if debug: |
| 245 | + print("Waiting for commander pod to start...") |
| 246 | + wait_for_pod(name) |
| 247 | + _logs(pod_name=name, follow=True) |
| 248 | + print("Deleting pod...") |
| 249 | + delete_pod(name) |
| 250 | + |
236 | 251 |
|
237 | 252 | @click.command()
|
238 | 253 | @click.argument("pod_name", type=str, default="")
|
239 | 254 | @click.option("--follow", "-f", is_flag=True, default=False, help="Follow logs")
|
240 | 255 | def logs(pod_name: str, follow: bool):
|
| 256 | + return _logs(pod_name, follow) |
| 257 | + |
| 258 | + |
| 259 | +def _logs(pod_name: str, follow: bool): |
241 | 260 | """Show the logs of a pod"""
|
242 | 261 | namespace = get_default_namespace()
|
243 | 262 |
|
@@ -269,9 +288,11 @@ def logs(pod_name: str, follow: bool):
|
269 | 288 | try:
|
270 | 289 | stream = pod_log(pod_name, container_name=None, follow=follow)
|
271 | 290 | for line in stream.stream():
|
272 |
| - print(line.decode('utf-8'), end=None) |
| 291 | + print(line.decode("utf-8"), end=None) |
273 | 292 | except Exception as e:
|
274 | 293 | print(e)
|
| 294 | + except KeyboardInterrupt: |
| 295 | + print("Interrupted streaming log!") |
275 | 296 |
|
276 | 297 |
|
277 | 298 | @click.command()
|
|
0 commit comments