@@ -138,16 +138,29 @@ def grep_logs(pattern: str, show_k8s_timestamps: bool, no_sort: bool):
138
138
@click .argument ("tank_a" , type = str , required = True )
139
139
@click .argument ("tank_b" , type = str , required = True )
140
140
@click .option ("--chain" , default = "regtest" , show_default = True )
141
- def messages (tank_a : str , tank_b : str , chain : str ):
141
+ @click .option ("--namespace_a" , default = None , show_default = True )
142
+ @click .option ("--namespace_b" , default = None , show_default = True )
143
+ def messages (
144
+ tank_a : str , tank_b : str , chain : str , namespace_a : Optional [str ], namespace_b : Optional [str ]
145
+ ):
142
146
"""
143
147
Fetch messages sent between <tank_a pod name> and <tank_b pod name> in [chain]
144
148
"""
145
149
try :
150
+ if not namespace_a :
151
+ namespace_a = get_default_namespace ()
152
+ if not namespace_b :
153
+ namespace_b = get_default_namespace ()
154
+
146
155
# Get the messages
147
- messages = get_messages (tank_a , tank_b , chain )
156
+ messages = get_messages (
157
+ tank_a , tank_b , chain , namespace_a = namespace_a , namespace_b = namespace_b
158
+ )
148
159
149
160
if not messages :
150
- print (f"No messages found between { tank_a } and { tank_b } " )
161
+ print (
162
+ f"No messages found between { tank_a } ({ namespace_a } ) and { tank_b } ({ namespace_b } )"
163
+ )
151
164
return
152
165
153
166
# Process and print messages
@@ -172,23 +185,25 @@ def messages(tank_a: str, tank_b: str, chain: str):
172
185
print (f"Error fetching messages between nodes { tank_a } and { tank_b } : { e } " )
173
186
174
187
175
- def get_messages (tank_a : str , tank_b : str , chain : str ):
188
+ def get_messages (tank_a : str , tank_b : str , chain : str , namespace_a : str , namespace_b : str ):
176
189
"""
177
190
Fetch messages from the message capture files
178
191
"""
179
192
subdir = "" if chain == "main" else f"{ chain } /"
180
193
base_dir = f"/root/.bitcoin/{ subdir } message_capture"
181
194
182
195
# Get the IP of node_b
183
- cmd = f"kubectl get pod { tank_b } -o jsonpath='{{.status.podIP}}'"
196
+ cmd = f"kubectl get pod { tank_b } -o jsonpath='{{.status.podIP}}' --namespace { namespace_b } "
184
197
tank_b_ip = run_command (cmd ).strip ()
185
198
186
199
# Get the service IP of node_b
187
- cmd = f"kubectl get service { tank_b } -o jsonpath='{{.spec.clusterIP}}'"
200
+ cmd = (
201
+ f"kubectl get service { tank_b } -o jsonpath='{{.spec.clusterIP}}' --namespace { namespace_b } "
202
+ )
188
203
tank_b_service_ip = run_command (cmd ).strip ()
189
204
190
205
# List directories in the message capture folder
191
- cmd = f"kubectl exec { tank_a } -- ls { base_dir } "
206
+ cmd = f"kubectl exec { tank_a } --namespace { namespace_a } -- ls { base_dir } "
192
207
193
208
dirs = run_command (cmd ).splitlines ()
194
209
@@ -199,7 +214,7 @@ def get_messages(tank_a: str, tank_b: str, chain: str):
199
214
for file , outbound in [["msgs_recv.dat" , False ], ["msgs_sent.dat" , True ]]:
200
215
file_path = f"{ base_dir } /{ dir_name } /{ file } "
201
216
# Fetch the file contents from the container
202
- cmd = f"kubectl exec { tank_a } -- cat { file_path } "
217
+ cmd = f"kubectl exec { tank_a } --namespace { namespace_a } -- cat { file_path } "
203
218
import subprocess
204
219
205
220
blob = subprocess .run (
0 commit comments