Skip to content

Commit

Permalink
Merge pull request #651 from pinheadmz/recent-logs
Browse files Browse the repository at this point in the history
warnet logs: sort by pod age (newest first), and handle namespaces
  • Loading branch information
pinheadmz authored Oct 11, 2024
2 parents 493aeb1 + 1b539f0 commit 577cdbb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/warnet/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ def _logs(pod_name: str, follow: bool, namespace: Optional[str] = None):
namespace = get_default_namespace_or(namespace)

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

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

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

try:
stream = pod_log(pod_name, container_name=container_name, follow=follow)
stream = pod_log(
pod_name, container_name=container_name, namespace=pod_namespace, follow=follow
)
for line in stream:
click.echo(line.decode("utf-8").rstrip())
except Exception as e:
Expand Down

0 comments on commit 577cdbb

Please sign in to comment.