Skip to content

Commit 8f4ddd3

Browse files
committed
cli: enable log cli to filter by regex pattern
1 parent 10fc3ca commit 8f4ddd3

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/warnet/control.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,18 @@ def run(scenario_file: str, additional_args: tuple[str]):
231231

232232

233233
@click.command()
234-
@click.argument("pod_name", type=str, default="")
235-
@click.option("--follow", "-f", is_flag=True, default=False, help="Follow logs")
236-
def logs(pod_name: str, follow: bool):
237-
"""Show the logs of a pod"""
234+
@click.argument("pod_name", type=str, required=False)
235+
@click.option("--follow", "-f", is_flag=True, default=False, help="Follow logs in real-time")
236+
@click.option("--grep", "-g", type=str, required=False, help="Pattern to grep for in logs")
237+
def logs(pod_name: str = "", follow: bool = False, grep: str = ""):
238+
"""Show the logs of a Kubernetes pod, optionally filtering by a grep pattern."""
238239
follow_flag = "--follow" if follow else ""
239240
namespace = get_default_namespace()
240241

241242
if pod_name:
242243
try:
243244
command = f"kubectl logs pod/{pod_name} -n {namespace} {follow_flag}"
244-
stream_command(command)
245+
stream_command(command, grep)
245246
return
246247
except Exception as e:
247248
print(f"Could not find the pod {pod_name}: {e}")
@@ -270,7 +271,7 @@ def logs(pod_name: str, follow: bool):
270271
pod_name = selected["pod"]
271272
try:
272273
command = f"kubectl logs pod/{pod_name} -n {namespace} {follow_flag}"
273-
stream_command(command)
274+
stream_command(command, grep)
274275
except Exception as e:
275276
print(f"Please consider waiting for the pod to become available. Encountered: {e}")
276277
else:

0 commit comments

Comments
 (0)