Skip to content

Commit 5188108

Browse files
committed
constants: use labels to select pods for log
1 parent 30af65a commit 5188108

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/warnet/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
KUBE_INTERNAL_NAMESPACES = ["kube-node-lease", "kube-public", "kube-system", "kubernetes-dashboard"]
1919
HELM_COMMAND = "helm upgrade --install --create-namespace"
2020

21+
TANK_MISSION = "tank"
22+
COMMANDER_MISSION = "commander"
23+
2124
BITCOINCORE_CONTAINER = "bitcoincore"
2225
COMMANDER_CONTAINER = "commander"
2326

src/warnet/control.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import click
1313
import inquirer
1414
from inquirer.themes import GreenPassion
15+
from kubernetes.client.models import V1Pod
1516
from rich import print
1617
from rich.console import Console
1718
from rich.prompt import Confirm, Prompt
@@ -21,8 +22,8 @@
2122
BITCOINCORE_CONTAINER,
2223
COMMANDER_CHART,
2324
COMMANDER_CONTAINER,
24-
INGRESS_NAMESPACE,
25-
LOGGING_NAMESPACE,
25+
COMMANDER_MISSION,
26+
TANK_MISSION,
2627
)
2728
from .k8s import (
2829
delete_pod,
@@ -363,20 +364,23 @@ def logs(pod_name: str, follow: bool, namespace: str):
363364
def _logs(pod_name: str, follow: bool, namespace: Optional[str] = None):
364365
namespace = get_default_namespace_or(namespace)
365366

367+
def format_pods(pods: list[V1Pod]) -> list[str]:
368+
return [f"{pod.metadata.name}: {pod.metadata.namespace}" for pod in pods]
369+
366370
if pod_name == "":
367371
try:
368-
pods = get_pods()
369-
pod_list = [
370-
f"{item.metadata.name}: {item.metadata.namespace}"
371-
for item in pods
372-
if item.metadata.namespace not in [LOGGING_NAMESPACE, INGRESS_NAMESPACE]
373-
]
372+
pod_list = []
373+
formatted_commanders = format_pods(get_mission(COMMANDER_MISSION))
374+
formatted_tanks = format_pods(get_mission(TANK_MISSION))
375+
pod_list.extend(formatted_commanders)
376+
pod_list.extend(formatted_tanks)
377+
374378
except Exception as e:
375-
print(f"Could not fetch any pods in namespace {namespace}: {e}")
379+
print(f"Could not fetch any pods in namespace ({namespace}): {e}")
376380
return
377381

378382
if not pod_list:
379-
print(f"Could not fetch any pods in namespace {namespace}")
383+
print(f"Could not fetch any pods in namespace ({namespace})")
380384
return
381385

382386
q = [

0 commit comments

Comments
 (0)