Skip to content

Commit ccc4d5b

Browse files
committed
control: add ns to logs
1 parent eb52fab commit ccc4d5b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/warnet/control.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,18 +340,20 @@ def filter(path):
340340
@click.command()
341341
@click.argument("pod_name", type=str, default="")
342342
@click.option("--follow", "-f", is_flag=True, default=False, help="Follow logs")
343-
def logs(pod_name: str, follow: bool):
343+
@click.option("--namespace", type=str, default="default", show_default=True)
344+
def logs(pod_name: str, follow: bool, namespace: str):
344345
"""Show the logs of a pod"""
345-
return _logs(pod_name, follow)
346+
return _logs(pod_name, follow, namespace)
346347

347348

348-
def _logs(pod_name: str, follow: bool):
349-
namespace = get_default_namespace()
349+
def _logs(pod_name: str, follow: bool, namespace: Optional[str] = None):
350+
if not namespace:
351+
namespace = get_default_namespace()
350352

351353
if pod_name == "":
352354
try:
353355
pods = get_pods()
354-
pod_list = [item.metadata.name for item in pods]
356+
pod_list = [f"{item.metadata.name}: {item.metadata.namespace}" for item in pods]
355357
except Exception as e:
356358
print(f"Could not fetch any pods in namespace {namespace}: {e}")
357359
return
@@ -369,7 +371,7 @@ def _logs(pod_name: str, follow: bool):
369371
]
370372
selected = inquirer.prompt(q, theme=GreenPassion())
371373
if selected:
372-
pod_name = selected["pod"]
374+
pod_name, pod_namespace = selected["pod"].split(": ")
373375
else:
374376
return # cancelled by user
375377

0 commit comments

Comments
 (0)