@@ -133,16 +133,29 @@ def grep_logs(pattern: str, show_k8s_timestamps: bool, no_sort: bool):
133133@click .argument ("tank_a" , type = str , required = True )
134134@click .argument ("tank_b" , type = str , required = True )
135135@click .option ("--chain" , default = "regtest" , show_default = True )
136- def messages (tank_a : str , tank_b : str , chain : str ):
136+ @click .option ("--namespace_a" , default = None , show_default = True )
137+ @click .option ("--namespace_b" , default = None , show_default = True )
138+ def messages (
139+ tank_a : str , tank_b : str , chain : str , namespace_a : Optional [str ], namespace_b : Optional [str ]
140+ ):
137141 """
138142 Fetch messages sent between <tank_a pod name> and <tank_b pod name> in [chain]
139143 """
140144 try :
145+ if not namespace_a :
146+ namespace_a = get_default_namespace ()
147+ if not namespace_b :
148+ namespace_b = get_default_namespace ()
149+
141150 # Get the messages
142- messages = get_messages (tank_a , tank_b , chain )
151+ messages = get_messages (
152+ tank_a , tank_b , chain , namespace_a = namespace_a , namespace_b = namespace_b
153+ )
143154
144155 if not messages :
145- print (f"No messages found between { tank_a } and { tank_b } " )
156+ print (
157+ f"No messages found between { tank_a } ({ namespace_a } ) and { tank_b } ({ namespace_b } )"
158+ )
146159 return
147160
148161 # Process and print messages
@@ -167,23 +180,25 @@ def messages(tank_a: str, tank_b: str, chain: str):
167180 print (f"Error fetching messages between nodes { tank_a } and { tank_b } : { e } " )
168181
169182
170- def get_messages (tank_a : str , tank_b : str , chain : str ):
183+ def get_messages (tank_a : str , tank_b : str , chain : str , namespace_a : str , namespace_b : str ):
171184 """
172185 Fetch messages from the message capture files
173186 """
174187 subdir = "" if chain == "main" else f"{ chain } /"
175188 base_dir = f"/root/.bitcoin/{ subdir } message_capture"
176189
177190 # Get the IP of node_b
178- cmd = f"kubectl get pod { tank_b } -o jsonpath='{{.status.podIP}}'"
191+ cmd = f"kubectl get pod { tank_b } -o jsonpath='{{.status.podIP}}' --namespace { namespace_b } "
179192 tank_b_ip = run_command (cmd ).strip ()
180193
181194 # Get the service IP of node_b
182- cmd = f"kubectl get service { tank_b } -o jsonpath='{{.spec.clusterIP}}'"
195+ cmd = (
196+ f"kubectl get service { tank_b } -o jsonpath='{{.spec.clusterIP}}' --namespace { namespace_b } "
197+ )
183198 tank_b_service_ip = run_command (cmd ).strip ()
184199
185200 # List directories in the message capture folder
186- cmd = f"kubectl exec { tank_a } -- ls { base_dir } "
201+ cmd = f"kubectl exec { tank_a } --namespace { namespace_a } -- ls { base_dir } "
187202
188203 dirs = run_command (cmd ).splitlines ()
189204
@@ -194,7 +209,8 @@ def get_messages(tank_a: str, tank_b: str, chain: str):
194209 for file , outbound in [["msgs_recv.dat" , False ], ["msgs_sent.dat" , True ]]:
195210 file_path = f"{ base_dir } /{ dir_name } /{ file } "
196211 # Fetch the file contents from the container
197- cmd = f"kubectl exec { tank_a } -- cat { file_path } "
212+ cmd = f"kubectl exec { tank_a } --namespace { namespace_a } -- cat { file_path } "
213+ import subprocess
198214
199215 blob = subprocess .run (
200216 cmd , shell = True , capture_output = True , executable = "bash"
0 commit comments