Skip to content

Commit 6b3ed49

Browse files
authored
Merge pull request #631 from mplsgrant/2024-10-use-pod_log-in-grep_log
use `pod_log` in `grep_logs`
2 parents 9825a50 + d4d74e6 commit 6b3ed49

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

src/warnet/bitcoin.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from urllib3.exceptions import MaxRetryError
1111

1212
from .constants import BITCOINCORE_CONTAINER
13-
from .k8s import get_default_namespace, get_mission
13+
from .k8s import get_default_namespace, get_mission, pod_log
1414
from .process import run_command
1515

1616

@@ -79,25 +79,18 @@ def grep_logs(pattern: str, show_k8s_timestamps: bool, no_sort: bool):
7979

8080
for tank in tanks:
8181
pod_name = tank.metadata.name
82-
# Get container names for this pod
83-
containers = tank.spec.containers
84-
if not containers:
85-
continue
86-
87-
# Use the first container name
88-
container_name = containers[0].name
89-
if not container_name:
90-
continue
91-
92-
# Get logs from the specific container
93-
command = f"kubectl logs {pod_name} -c {container_name} --timestamps"
94-
logs = run_command(command)
82+
logs = pod_log(pod_name, BITCOINCORE_CONTAINER)
9583

9684
if logs is not False:
97-
# Process logs
98-
for log_entry in logs.splitlines():
99-
if re.search(pattern, log_entry):
100-
matching_logs.append((log_entry, pod_name))
85+
try:
86+
for line in logs:
87+
log_entry = line.decode("utf-8").rstrip()
88+
if re.search(pattern, log_entry):
89+
matching_logs.append((log_entry, pod_name))
90+
except Exception as e:
91+
print(e)
92+
except KeyboardInterrupt:
93+
print("Interrupted streaming log!")
10194

10295
# Sort logs if needed
10396
if not no_sort:

0 commit comments

Comments
 (0)