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