diff --git a/src/warnet/bitcoin.py b/src/warnet/bitcoin.py index 8be750613..382c3e7b5 100644 --- a/src/warnet/bitcoin.py +++ b/src/warnet/bitcoin.py @@ -60,15 +60,16 @@ def debug_log(tank: str): @bitcoin.command() @click.argument("pattern", type=str, required=True) +@click.option("--tank", type=str, required=False, help="Filter by tank name") @click.option("--show-k8s-timestamps", is_flag=True, default=False, show_default=True) @click.option("--no-sort", is_flag=True, default=False, show_default=True) -def grep_logs(pattern: str, show_k8s_timestamps: bool, no_sort: bool): +def grep_logs(pattern: str, tank:str, show_k8s_timestamps: bool, no_sort: bool): """ Grep combined bitcoind logs using regex """ try: - tanks = get_mission("tank") + tanks = get_mission("tank", tank) except MaxRetryError as e: print(f"{e}") sys.exit(1) diff --git a/src/warnet/k8s.py b/src/warnet/k8s.py index 0cb223072..93ff7b41c 100644 --- a/src/warnet/k8s.py +++ b/src/warnet/k8s.py @@ -30,13 +30,15 @@ def get_pods() -> V1PodList: return pod_list -def get_mission(mission: str) -> list[V1PodList]: - pods = get_pods() - crew = [] - for pod in pods.items: - if "mission" in pod.metadata.labels and pod.metadata.labels["mission"] == mission: - crew.append(pod) - return crew +def get_mission(mission: str, tank_name: str = None) -> list: + config.load_kube_config() + v1 = client.CoreV1Api() + pods = v1.list_pod_for_all_namespaces(label_selector=f"mission={mission}") + + if tank_name: + return [pod for pod in pods.items if pod.metadata.name == tank_name] + return pods.items + def get_pod_exit_status(pod_name):