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
16+ from kubernetes .dynamic .exceptions import ResourceNotFoundError
1517from kubernetes .stream import stream
1618from warnet .status import RunningStatus
1719from warnet .tank import Tank
@@ -122,6 +124,15 @@ def get_pod(self, pod_name: str) -> V1Pod | None:
122124 if e .status == 404 :
123125 return None
124126
127+ def get_service (self , service_name : str ) -> V1Service | None :
128+ try :
129+ return cast (
130+ V1Service , self .client .read_namespaced_service (name = service_name , namespace = self .namespace )
131+ )
132+ except ApiException as e :
133+ if e .status == 404 :
134+ return None
135+
125136 # We could enhance this by checking the pod status as well
126137 # The following pod phases are available: Pending, Running, Succeeded, Failed, Unknown
127138 # For example not able to pull image will be a phase of Pending, but the container status will be ErrImagePull
@@ -239,6 +250,7 @@ def get_messages(
239250 bitcoin_network : str = "regtest" ,
240251 ):
241252 b_pod = self .get_pod (self .get_pod_name (b_index , ServiceType .BITCOIN ))
253+ b_service = self .get_service (self .get_service_name (b_index ))
242254 subdir = "/" if bitcoin_network == "main" else f"{ bitcoin_network } /"
243255 base_dir = f"/root/.bitcoin/{ subdir } message_capture"
244256 cmd = f"ls { base_dir } "
@@ -253,7 +265,7 @@ def get_messages(
253265 messages = []
254266
255267 for dir_name in dirs :
256- if b_pod .status .pod_ip in dir_name :
268+ if b_pod .status .pod_ip in dir_name or b_service . spec . cluster_ip in dir_name :
257269 for file , outbound in [["msgs_recv.dat" , False ], ["msgs_sent.dat" , True ]]:
258270 # Fetch the file contents from the container
259271 file_path = f"{ base_dir } /{ dir_name } /{ file } "
@@ -309,6 +321,9 @@ def default_bitcoind_config_args(self, tank):
309321 defaults += f" -rpcport={ tank .rpc_port } "
310322 defaults += f" -zmqpubrawblock=tcp://0.0.0.0:{ tank .zmqblockport } "
311323 defaults += f" -zmqpubrawtx=tcp://0.0.0.0:{ tank .zmqtxport } "
324+ # connect to initial peers as defined in graph file
325+ for dst_index in tank .init_peers :
326+ defaults += f" -addnode={ self .get_service_name (dst_index )} "
312327 return defaults
313328
314329 def create_bitcoind_container (self , tank : Tank ) -> client .V1Container :
@@ -431,9 +446,8 @@ def remove_prometheus_service_monitors(self, tanks):
431446 name = f"warnet-tank-{ tank .index :06d} " ,
432447 namespace = MAIN_NAMESPACE ,
433448 )
434- except ApiException as e :
435- if e .status != 404 :
436- raise e
449+ except ResourceNotFoundError :
450+ continue
437451
438452 def create_lnd_container (self , tank , bitcoind_service_name , volume_mounts ) -> client .V1Container :
439453 # These args are appended to the Dockerfile `ENTRYPOINT ["lnd"]`
@@ -557,7 +571,7 @@ def create_bitcoind_service(self, tank) -> client.V1Service:
557571 selector = {"app" : self .get_pod_name (tank .index , ServiceType .BITCOIN )},
558572 publish_not_ready_addresses = True ,
559573 ports = [
560- # TODO: do we need to add 18444 here too?
574+ client . V1ServicePort ( port = 18444 , target_port = 18444 , name = "p2p" ),
561575 client .V1ServicePort (port = tank .rpc_port , target_port = tank .rpc_port , name = "rpc" ),
562576 client .V1ServicePort (
563577 port = tank .zmqblockport , target_port = tank .zmqblockport , name = "zmqblock"
0 commit comments