Skip to content

Commit 577cdbb

Browse files
authored
Merge pull request #651 from pinheadmz/recent-logs
warnet logs: sort by pod age (newest first), and handle namespaces
2 parents 493aeb1 + 1b539f0 commit 577cdbb

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/warnet/control.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ def _logs(pod_name: str, follow: bool, namespace: Optional[str] = None):
370370
namespace = get_default_namespace_or(namespace)
371371

372372
def format_pods(pods: list[V1Pod]) -> list[str]:
373-
return [f"{pod.metadata.name}: {pod.metadata.namespace}" for pod in pods]
373+
sorted_pods = sorted(pods, key=lambda pod: pod.metadata.creation_timestamp, reverse=True)
374+
return [f"{pod.metadata.name}: {pod.metadata.namespace}" for pod in sorted_pods]
374375

375376
if pod_name == "":
376377
try:
@@ -402,7 +403,7 @@ def format_pods(pods: list[V1Pod]) -> list[str]:
402403
return # cancelled by user
403404

404405
try:
405-
pod = get_pod(pod_name)
406+
pod = get_pod(pod_name, namespace=pod_namespace)
406407
eligible_container_names = [BITCOINCORE_CONTAINER, COMMANDER_CONTAINER]
407408
available_container_names = [container.name for container in pod.spec.containers]
408409
container_name = next(
@@ -421,7 +422,9 @@ def format_pods(pods: list[V1Pod]) -> list[str]:
421422
return
422423

423424
try:
424-
stream = pod_log(pod_name, container_name=container_name, follow=follow)
425+
stream = pod_log(
426+
pod_name, container_name=container_name, namespace=pod_namespace, follow=follow
427+
)
425428
for line in stream:
426429
click.echo(line.decode("utf-8").rstrip())
427430
except Exception as e:

0 commit comments

Comments
 (0)