1010from cli .image import build_image
1111from kubernetes import client , config
1212from kubernetes .client .models .v1_pod import V1Pod
13+ from kubernetes .client .models .v1_service import V1Service
1314from kubernetes .client .rest import ApiException
1415from kubernetes .dynamic import DynamicClient
1516from kubernetes .dynamic .exceptions import ResourceNotFoundError
@@ -121,6 +122,15 @@ def get_pod(self, pod_name: str) -> V1Pod | None:
121122 if e .status == 404 :
122123 return None
123124
125+ def get_service (self , service_name : str ) -> V1Service | None :
126+ try :
127+ return cast (
128+ V1Service , self .client .read_namespaced_service (name = service_name , namespace = self .namespace )
129+ )
130+ except ApiException as e :
131+ if e .status == 404 :
132+ return None
133+
124134 # We could enhance this by checking the pod status as well
125135 # The following pod phases are available: Pending, Running, Succeeded, Failed, Unknown
126136 # For example not able to pull image will be a phase of Pending, but the container status will be ErrImagePull
@@ -237,6 +247,7 @@ def get_messages(
237247 bitcoin_network : str = "regtest" ,
238248 ):
239249 b_pod = self .get_pod (self .get_pod_name (b_index , ServiceType .BITCOIN ))
250+ b_service = self .get_service (self .get_service_name (b_index ))
240251 subdir = "/" if bitcoin_network == "main" else f"{ bitcoin_network } /"
241252 base_dir = f"/root/.bitcoin/{ subdir } message_capture"
242253 cmd = f"ls { base_dir } "
@@ -251,7 +262,7 @@ def get_messages(
251262 messages = []
252263
253264 for dir_name in dirs :
254- if b_pod .status .pod_ip in dir_name :
265+ if b_pod .status .pod_ip in dir_name or b_service . spec . cluster_ip in dir_name :
255266 for file , outbound in [["msgs_recv.dat" , False ], ["msgs_sent.dat" , True ]]:
256267 # Fetch the file contents from the container
257268 file_path = f"{ base_dir } /{ dir_name } /{ file } "
0 commit comments