Skip to content

Commit 80f467d

Browse files
authored
Merge pull request #743 from pinheadmz/ln-namespaces
Accomdate LN nodes in "wargames" namespaces
2 parents 70df087 + 685456b commit 80f467d

File tree

7 files changed

+30
-17
lines changed

7 files changed

+30
-17
lines changed

resources/charts/bitcoincore/charts/cln/templates/configmap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ data:
1414
bitcoin-rpcconnect={{ include "bitcoincore.fullname" . }}
1515
bitcoin-rpcport={{ index .Values.global .Values.global.chain "RPCPort" }}
1616
bitcoin-rpcpassword={{ .Values.global.rpcpassword }}
17-
alias={{ include "cln.fullname" . }}
17+
alias={{ include "cln.fullname" . }}.{{ .Release.Namespace }}
1818
announce-addr=dns:{{ include "cln.fullname" . }}:{{ .Values.P2PPort }}
1919
database-upgrade=true
2020
bitcoin-retry-timeout=600

resources/charts/bitcoincore/charts/lnd/templates/_helpers.tpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,12 @@ Create the name of the service account to use
7676
{{- default "default" .Values.serviceAccount.name }}
7777
{{- end }}
7878
{{- end }}
79+
80+
{{/*
81+
Create a hex-encoded RGB color derived from the namespace
82+
*/}}
83+
{{- define "namespace.color" -}}
84+
{{- $hash := sha256sum .Release.Namespace -}}
85+
{{- printf "#%s" (substr 0 6 $hash) -}}
86+
{{- end -}}
87+

resources/charts/bitcoincore/charts/lnd/templates/configmap.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ data:
1515
bitcoind.rpchost={{ include "bitcoincore.fullname" . }}:{{ index .Values.global .Values.global.chain "RPCPort" }}
1616
bitcoind.zmqpubrawblock=tcp://{{ include "bitcoincore.fullname" . }}:{{ .Values.global.ZMQBlockPort }}
1717
bitcoind.zmqpubrawtx=tcp://{{ include "bitcoincore.fullname" . }}:{{ .Values.global.ZMQTxPort }}
18-
alias={{ include "lnd.fullname" . }}
18+
alias={{ include "lnd.fullname" . }}.{{ .Release.Namespace }}
19+
color={{ include "namespace.color" . }}
1920
externalhosts={{ include "lnd.fullname" . }}
2021
tlsextradomain={{ include "lnd.fullname" . }}
2122
tls.cert: |

resources/scenarios/commander.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
WARNET["tanks"].append(
9393
{
9494
"tank": pod.metadata.name,
95+
"namespace": pod.metadata.namespace,
9596
"chain": pod.metadata.labels["chain"],
9697
"rpc_host": pod.status.pod_ip,
9798
"rpc_port": int(pod.metadata.labels["RPCPort"]),
@@ -104,10 +105,13 @@
104105
if pod.metadata.labels["mission"] == "lightning":
105106
if "lnd" in pod.metadata.labels["app.kubernetes.io/name"]:
106107
lnnode = LND(
107-
pod.metadata.name, pod.status.pod_ip, pod.metadata.annotations["adminMacaroon"]
108+
pod.metadata.name,
109+
pod.metadata.namespace,
110+
pod.status.pod_ip,
111+
pod.metadata.annotations["adminMacaroon"],
108112
)
109113
if "cln" in pod.metadata.labels["app.kubernetes.io/name"]:
110-
lnnode = CLN(pod.metadata.name, pod.status.pod_ip)
114+
lnnode = CLN(pod.metadata.name, pod.metadata.namespace, pod.status.pod_ip)
111115
assert lnnode
112116
WARNET["lightning"].append(lnnode)
113117

resources/scenarios/ln_framework/ln.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ def to_lnd_chanpolicy(self, capacity):
101101

102102
class LNNode(ABC):
103103
@abstractmethod
104-
def __init__(self, pod_name, ip_address):
104+
def __init__(self, pod_name, pod_namespace, ip_address):
105105
self.name = pod_name
106+
self.namespace = pod_namespace
106107
self.ip_address = ip_address
107108
self.log = logging.getLogger(pod_name)
108109
handler = logging.StreamHandler()
@@ -152,16 +153,16 @@ def update(self, txid_hex: str, policy: dict, capacity: int) -> dict:
152153

153154

154155
class CLN(LNNode):
155-
def __init__(self, pod_name, ip_address):
156-
super().__init__(pod_name, ip_address)
156+
def __init__(self, pod_name, pod_namespace, ip_address):
157+
super().__init__(pod_name, pod_namespace, ip_address)
157158
self.conn = None
158159
self.headers = {}
159160
self.impl = "cln"
160161
self.reset_connection()
161162

162163
def reset_connection(self):
163164
self.conn = http.client.HTTPSConnection(
164-
host=self.name, port=3010, timeout=60, context=INSECURE_CONTEXT
165+
host=f"{self.name}.{self.namespace}", port=3010, timeout=60, context=INSECURE_CONTEXT
165166
)
166167

167168
def setRune(self, rune):
@@ -285,11 +286,9 @@ def update(self, txid_hex: str, policy: dict, capacity: int) -> dict:
285286

286287

287288
class LND(LNNode):
288-
def __init__(self, pod_name, ip_address, admin_macaroon_hex):
289-
super().__init__(pod_name, ip_address)
290-
self.conn = http.client.HTTPSConnection(
291-
host=pod_name, port=8080, timeout=5, context=INSECURE_CONTEXT
292-
)
289+
def __init__(self, pod_name, pod_namespace, ip_address, admin_macaroon_hex):
290+
super().__init__(pod_name, pod_namespace, ip_address)
291+
self.conn = None
293292
self.admin_macaroon_hex = admin_macaroon_hex
294293
self.headers = {
295294
"Grpc-Metadata-macaroon": admin_macaroon_hex,
@@ -299,7 +298,7 @@ def __init__(self, pod_name, ip_address, admin_macaroon_hex):
299298

300299
def reset_connection(self):
301300
self.conn = http.client.HTTPSConnection(
302-
host=self.name, port=8080, timeout=60, context=INSECURE_CONTEXT
301+
host=f"{self.name}.{self.namespace}", port=8080, timeout=60, context=INSECURE_CONTEXT
303302
)
304303

305304
def get(self, uri):

src/warnet/ln.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def rpc(pod: str, method: str, params: str, namespace: Optional[str]):
2828

2929

3030
def _rpc(pod_name: str, method: str, params: str = "", namespace: Optional[str] = None):
31-
pod = get_pod(pod_name)
3231
namespace = get_default_namespace_or(namespace)
32+
pod = get_pod(pod_name, namespace)
3333
chain = pod.metadata.labels["chain"]
3434
ln_client = "lncli"
3535
if "cln" in pod.metadata.labels["app.kubernetes.io/name"]:

test/ln_basic_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ def test_admin_macaroons(self):
6464
info = json.loads(
6565
self.warnet("ln rpc tank-0001-ln --rpcserver=tank-0002-ln.default:10009 getinfo")
6666
)
67-
assert info["alias"] == "tank-0002-ln"
67+
assert info["alias"] == "tank-0002-ln.default"
6868
info = json.loads(
6969
self.warnet("ln rpc tank-0002-ln --rpcserver=tank-0005-ln.default:10009 getinfo")
7070
)
71-
assert info["alias"] == "tank-0005-ln"
71+
assert info["alias"] == "tank-0005-ln.default"
7272

7373
self.log.info("Testing lnd nodes with unique macaroon root key can NOT query each other")
7474
# These tanks are configured with unique macaroon root keys

0 commit comments

Comments
 (0)