2323POD_PREFIX = "tank"
2424BITCOIN_CONTAINER_NAME = "bitcoin"
2525LN_CONTAINER_NAME = "ln"
26+ LN_CB_CONTAINER_NAME = "ln-cb"
2627MAIN_NAMESPACE = "warnet"
2728PROMETHEUS_METRICS_PORT = 9332
29+ LND_MOUNT_PATH = '/root/.lnd'
2830
2931
3032logger = logging .getLogger ("KubernetesBackend" )
@@ -107,7 +109,7 @@ def get_file(self, tank_index: int, service: ServiceType, file_path: str):
107109 return decoded_bytes
108110
109111 def get_pod_name (self , tank_index : int , type : ServiceType ) -> str :
110- if type == ServiceType .LIGHTNING :
112+ if type == ServiceType .LIGHTNING or type == ServiceType . CIRCUITBREAKER :
111113 return f"{ self .network_name } -{ POD_PREFIX } -ln-{ tank_index :06d} "
112114 return f"{ self .network_name } -{ POD_PREFIX } -{ tank_index :06d} "
113115
@@ -173,18 +175,19 @@ def get_status(self, tank_index: int, service: ServiceType) -> RunningStatus:
173175
174176 def exec_run (self , tank_index : int , service : ServiceType , cmd : str ):
175177 pod_name = self .get_pod_name (tank_index , service )
176- if service == ServiceType .BITCOIN :
177- exec_cmd = ["/bin/bash" , "-c" , f"{ cmd } " ]
178- elif service == ServiceType .LIGHTNING :
179- exec_cmd = ["/bin/sh" , "-c" , f"{ cmd } " ]
178+ exec_cmd = ["/bin/sh" , "-c" , f"{ cmd } " ]
180179 self .log .debug (f"Running { exec_cmd = :} on { tank_index = :} " )
180+ if service == ServiceType .BITCOIN :
181+ container = BITCOIN_CONTAINER_NAME
182+ if service == ServiceType .LIGHTNING :
183+ container = LN_CONTAINER_NAME
184+ if service == ServiceType .CIRCUITBREAKER :
185+ container = LN_CB_CONTAINER_NAME
181186 result = stream (
182187 self .client .connect_get_namespaced_pod_exec ,
183188 pod_name ,
184189 self .namespace ,
185- container = BITCOIN_CONTAINER_NAME
186- if service == ServiceType .BITCOIN
187- else LN_CONTAINER_NAME ,
190+ container = container ,
188191 command = exec_cmd ,
189192 stderr = True ,
190193 stdin = False ,
@@ -432,7 +435,7 @@ def remove_prometheus_service_monitors(self, tanks):
432435 if e .status != 404 :
433436 raise e
434437
435- def create_lnd_container (self , tank , bitcoind_service_name ) -> client .V1Container :
438+ def create_lnd_container (self , tank , bitcoind_service_name , volume_mounts ) -> client .V1Container :
436439 # These args are appended to the Dockerfile `ENTRYPOINT ["lnd"]`
437440 bitcoind_rpc_host = f"{ bitcoind_service_name } .{ self .namespace } "
438441 lightning_dns = f"lightning-{ tank .index } .{ self .namespace } "
@@ -475,12 +478,33 @@ def create_lnd_container(self, tank, bitcoind_service_name) -> client.V1Containe
475478 privileged = True ,
476479 capabilities = client .V1Capabilities (add = ["NET_ADMIN" , "NET_RAW" ]),
477480 ),
481+ volume_mounts = volume_mounts ,
478482 )
479483 self .log .debug (f"Created lightning container for tank { tank .index } " )
480484 return lightning_container
481485
486+ def create_circuitbreaker_container (self , tank , volume_mounts ) -> client .V1Container :
487+ self .log .debug (f"Creating circuitbreaker container for tank { tank .index } " )
488+ cb_container = client .V1Container (
489+ name = LN_CB_CONTAINER_NAME ,
490+ image = tank .lnnode .cb ,
491+ args = [
492+ "--network=regtest" ,
493+ f"--rpcserver=localhost:{ tank .lnnode .rpc_port } " ,
494+ f"--tlscertpath={ LND_MOUNT_PATH } /tls.cert" ,
495+ f"--macaroonpath={ LND_MOUNT_PATH } /data/chain/bitcoin/regtest/admin.macaroon"
496+ ],
497+ security_context = client .V1SecurityContext (
498+ privileged = True ,
499+ capabilities = client .V1Capabilities (add = ["NET_ADMIN" , "NET_RAW" ]),
500+ ),
501+ volume_mounts = volume_mounts ,
502+ )
503+ self .log .debug (f"Created circuitbreaker container for tank { tank .index } " )
504+ return cb_container
505+
482506 def create_pod_object (
483- self , tank : Tank , container : client .V1Container , name : str
507+ self , tank : Tank , containers : list [ client .V1Container ], volumes : list [ client . V1Volume ] , name : str
484508 ) -> client .V1Pod :
485509 # Create and return a Pod object
486510 # TODO: pass a custom namespace , e.g. different warnet sims can be deployed into diff namespaces
@@ -500,7 +524,8 @@ def create_pod_object(
500524 # Might need some more thinking on the pod restart policy, setting to Never for now
501525 # This means if a node has a problem it dies
502526 restart_policy = "OnFailure" ,
503- containers = [container ],
527+ containers = containers ,
528+ volumes = volumes ,
504529 ),
505530 )
506531
@@ -588,7 +613,7 @@ def deploy_pods(self, warnet):
588613 # Create and deploy bitcoind pod and service
589614 bitcoind_container = self .create_bitcoind_container (tank )
590615 bitcoind_pod = self .create_pod_object (
591- tank , bitcoind_container , self .get_pod_name (tank .index , ServiceType .BITCOIN )
616+ tank , [ bitcoind_container ], [] , self .get_pod_name (tank .index , ServiceType .BITCOIN )
592617 )
593618
594619 if tank .exporter and self .check_logging_crds_installed ():
@@ -609,11 +634,30 @@ def deploy_pods(self, warnet):
609634
610635 # Create and deploy LND pod
611636 if tank .lnnode :
612- lnd_container = self .create_lnd_container (tank , bitcoind_service .metadata .name )
637+ conts = []
638+ vols = []
639+ volume_mounts = []
640+ if tank .lnnode .cb :
641+ # Create a shared volume between containers in the pod
642+ volume_name = f"ln-cb-data-{ tank .index } "
643+ vols .append (client .V1Volume (
644+ name = volume_name ,
645+ empty_dir = client .V1EmptyDirVolumeSource ()
646+ ))
647+ volume_mounts .append (client .V1VolumeMount (
648+ name = volume_name ,
649+ mount_path = LND_MOUNT_PATH ,
650+ ))
651+ # Add circuit breaker container
652+ conts .append (self .create_circuitbreaker_container (tank , volume_mounts ))
653+ # Add lnd container
654+ conts .append (self .create_lnd_container (tank , bitcoind_service .metadata .name , volume_mounts ))
655+ # Put it all together in a pod
613656 lnd_pod = self .create_pod_object (
614- tank , lnd_container , self .get_pod_name (tank .index , ServiceType .LIGHTNING )
657+ tank , conts , vols , self .get_pod_name (tank .index , ServiceType .LIGHTNING )
615658 )
616659 self .client .create_namespaced_pod (namespace = self .namespace , body = lnd_pod )
660+ # Create service for the pod
617661 lightning_service = self .create_lightning_service (tank )
618662 try :
619663 self .client .delete_namespaced_service (
0 commit comments