Skip to content

Commit 8301302

Browse files
committed
use constants in the log function
1 parent 43e3240 commit 8301302

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/warnet/control.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
from rich.prompt import Confirm, Prompt
1717
from rich.table import Table
1818

19-
from .constants import COMMANDER_CHART, LOGGING_NAMESPACE
19+
from .constants import (
20+
BITCOINCORE_CONTAINER,
21+
COMMANDER_CHART,
22+
COMMANDER_CONTAINER,
23+
LOGGING_NAMESPACE,
24+
)
2025
from .k8s import (
2126
delete_pod,
2227
get_default_namespace,
@@ -331,10 +336,21 @@ def _logs(pod_name: str, follow: bool):
331336

332337
try:
333338
pod = get_pod(pod_name)
334-
container_names = [container.name for container in pod.spec.containers]
335-
container_name = container_names[0]
339+
eligible_container_names = [BITCOINCORE_CONTAINER, COMMANDER_CONTAINER]
340+
available_container_names = [container.name for container in pod.spec.containers]
341+
container_name = next(
342+
(
343+
container_name
344+
for container_name in available_container_names
345+
if container_name in eligible_container_names
346+
),
347+
None,
348+
)
349+
if not container_name:
350+
print("Could not determine primary container.")
351+
return
336352
except Exception as e:
337-
print(f"Could not determine primary container: {e}")
353+
print(f"Error getting pods. Could not determine primary container: {e}")
338354
return
339355

340356
try:

0 commit comments

Comments
 (0)