Skip to content

Commit

Permalink
BREAKING REFACTOR: move some values to global, add lnd as subchart
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Nov 7, 2024
1 parent b637bd3 commit d9aad8f
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 113 deletions.
5 changes: 5 additions & 0 deletions resources/charts/bitcoincore/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ apiVersion: v2
name: bitcoincore
description: A Helm chart for Bitcoin Core

dependencies:
- name: lnd
version: 0.1.0
condition: ln.lnd

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apiVersion: v2
name: lnd

description: A Helm chart for LND

# A chart can be either an 'application' or a 'library' chart.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
{{/*
Expand the name of the PARENT chart.
*/}}
{{- define "bitcoincore.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified PARENT app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "bitcoincore.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s" .Release.Name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}


{{/*
Expand the name of the chart.
*/}}
{{- define "lnd.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}-ln
{{- end }}

{{/*
Expand All @@ -14,7 +35,7 @@ If release name contains chart name it will be used as a full name.
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s" .Release.Name | trunc 63 | trimSuffix "-" }}
{{- printf "%s" .Release.Name | trunc 63 | trimSuffix "-" }}-ln
{{- end }}
{{- end }}

Expand Down
19 changes: 19 additions & 0 deletions resources/charts/bitcoincore/charts/lnd/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "lnd.fullname" . }}
labels:
{{- include "lnd.labels" . | nindent 4 }}
data:
lnd.conf: |
{{- .Values.baseConfig | nindent 4 }}
{{- .Values.defaultConfig | nindent 4 }}
{{- .Values.config | nindent 4 }}
bitcoin.{{ .Values.global.chain }}=1
bitcoind.rpcpass={{ .Values.global.rpcpassword }}
bitcoind.rpchost={{ include "bitcoincore.fullname" . }}:{{ index .Values.global .Values.global.chain "RPCPort" }}
bitcoind.zmqpubrawblock=tcp://{{ include "bitcoincore.fullname" . }}:{{ .Values.global.ZMQBlockPort }}
bitcoind.zmqpubrawtx=tcp://{{ include "bitcoincore.fullname" . }}:{{ .Values.global.ZMQTxPort }}
alias={{ include "lnd.fullname" . }}
externalhosts={{ include "lnd.fullname" . }}
tlsextradomain={{ include "lnd.fullname" . }}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ metadata:
{{- if .Values.collectLogs }}
collect_logs: "true"
{{- end }}
chain: {{ .Values.global.chain }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ baseConfig: |
maxpendingchannels=64
trickledelay=1
rpclisten=0.0.0.0:10009
# zmq* and bitcoind.{rpcuser, rpcpass} are set in warnet code
bitcoind.rpcuser=user
# zmq* and bitcoind.rpcpass are set in configmap.yaml
config: ""

Expand Down
2 changes: 1 addition & 1 deletion resources/charts/bitcoincore/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ Always add for custom semver, check version for valid semver
{{- $custom := contains "-" .Values.image.tag -}}
{{- $newer := semverCompare ">=0.17.0" .Values.image.tag -}}
{{- if or $newer $custom -}}
[{{ .Values.chain }}]
[{{ .Values.global.chain }}]
{{- end -}}
{{- end -}}
10 changes: 5 additions & 5 deletions resources/charts/bitcoincore/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ metadata:
{{- include "bitcoincore.labels" . | nindent 4 }}
data:
bitcoin.conf: |
{{ .Values.chain }}=1
{{ .Values.global.chain }}=1
{{ template "bitcoincore.check_semver" . }}
{{- .Values.baseConfig | nindent 4 }}
rpcport={{ index .Values .Values.chain "RPCPort" }}
rpcpassword={{ .Values.rpcpassword }}
zmqpubrawblock=tcp://0.0.0.0:{{ .Values.ZMQBlockPort }}
zmqpubrawtx=tcp://0.0.0.0:{{ .Values.ZMQTxPort }}
rpcport={{ index .Values.global .Values.global.chain "RPCPort" }}
rpcpassword={{ .Values.global.rpcpassword }}
zmqpubrawblock=tcp://0.0.0.0:{{ .Values.global.ZMQBlockPort }}
zmqpubrawtx=tcp://0.0.0.0:{{ .Values.global.ZMQTxPort }}
{{- .Values.defaultConfig | nindent 4 }}
{{- .Values.config | nindent 4 }}
{{- range .Values.addnode }}
Expand Down
22 changes: 11 additions & 11 deletions resources/charts/bitcoincore/templates/pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ metadata:
{{- with .Values.podLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
chain: {{ .Values.chain }}
RPCPort: "{{ index .Values .Values.chain "RPCPort" }}"
ZMQTxPort: "{{ .Values.ZMQTxPort }}"
ZMQBlockPort: "{{ .Values.ZMQBlockPort }}"
rpcpassword: {{ .Values.rpcpassword }}
chain: {{ .Values.global.chain }}
RPCPort: "{{ index .Values.global .Values.global.chain "RPCPort" }}"
ZMQTxPort: "{{ .Values.global.ZMQTxPort }}"
ZMQBlockPort: "{{ .Values.global.ZMQBlockPort }}"
rpcpassword: {{ .Values.global.rpcpassword }}
app: {{ include "bitcoincore.fullname" . }}
{{- if .Values.collectLogs }}
collect_logs: "true"
Expand Down Expand Up @@ -48,23 +48,23 @@ spec:
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: rpc
containerPort: {{ index .Values .Values.chain "RPCPort" }}
containerPort: {{ index .Values.global .Values.global.chain "RPCPort" }}
protocol: TCP
- name: p2p
containerPort: {{ index .Values .Values.chain "P2PPort" }}
containerPort: {{ index .Values.global .Values.global.chain "P2PPort" }}
protocol: TCP
- name: zmq-tx
containerPort: {{ .Values.ZMQTxPort }}
containerPort: {{ .Values.global.ZMQTxPort }}
protocol: TCP
- name: zmq-block
containerPort: {{ .Values.ZMQBlockPort }}
containerPort: {{ .Values.global.ZMQBlockPort }}
protocol: TCP
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 8 }}
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 8 }}
tcpSocket:
port: {{ index .Values .Values.chain "RPCPort" }}
port: {{ index .Values.global .Values.global.chain "RPCPort" }}
resources:
{{- toYaml .Values.resources | nindent 8 }}
volumeMounts:
Expand All @@ -88,7 +88,7 @@ spec:
- name: BITCOIN_RPC_HOST
value: "127.0.0.1"
- name: BITCOIN_RPC_PORT
value: "{{ index .Values .Values.chain "RPCPort" }}"
value: "{{ index .Values.global .Values.global.chain "RPCPort" }}"
- name: BITCOIN_RPC_USER
value: user
- name: BITCOIN_RPC_PASSWORD
Expand Down
8 changes: 4 additions & 4 deletions resources/charts/bitcoincore/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ metadata:
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ index .Values .Values.chain "RPCPort" }}
- port: {{ index .Values.global .Values.global.chain "RPCPort" }}
targetPort: rpc
protocol: TCP
name: rpc
- port: {{ index .Values .Values.chain "P2PPort" }}
- port: {{ index .Values.global .Values.global.chain "P2PPort" }}
targetPort: p2p
protocol: TCP
name: p2p
- port: {{ .Values.ZMQTxPort }}
- port: {{ .Values.global.ZMQTxPort }}
targetPort: zmq-tx
protocol: TCP
name: zmq-tx
- port: {{ .Values.ZMQBlockPort }}
- port: {{ .Values.global.ZMQBlockPort }}
targetPort: zmq-block
protocol: TCP
name: zmq-block
Expand Down
31 changes: 16 additions & 15 deletions resources/charts/bitcoincore/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ securityContext: {}
service:
type: ClusterIP

regtest:
RPCPort: 18443
P2PPort: 18444

signet:
RPCPort: 38332
P2PPort: 38333

ZMQTxPort: 28333
ZMQBlockPort: 28332

ingress:
enabled: false
className: ""
Expand Down Expand Up @@ -109,12 +98,23 @@ tolerations: []

affinity: {}

chain: regtest

collectLogs: false
metricsExport: false
prometheusMetricsPort: 9332

# These are values that are propogated to the sub-charts (i.e. lightning nodes)
global:
chain: regtest
regtest:
RPCPort: 18443
P2PPort: 18444
signet:
RPCPort: 38332
P2PPort: 38333
ZMQTxPort: 28333
ZMQBlockPort: 28332
rpcpassword: gn0cchi

baseConfig: |
checkmempool=0
debuglogfile=debug.log
Expand All @@ -130,8 +130,6 @@ baseConfig: |
rest=1
# rpcport and zmq endpoints are configured by chain in configmap.yaml
rpcpassword: gn0cchi

config: ""

defaultConfig: ""
Expand All @@ -141,3 +139,6 @@ addnode: []
loadSnapshot:
enabled: false
url: ""

ln:
lnd: false
11 changes: 0 additions & 11 deletions resources/charts/lnd/templates/configmap.yaml

This file was deleted.

43 changes: 0 additions & 43 deletions src/warnet/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
FORK_OBSERVER_CHART,
HELM_COMMAND,
INGRESS_HELM_COMMANDS,
LND_CHART_LOCATION,
LOGGING_HELM_COMMANDS,
LOGGING_NAMESPACE,
NAMESPACES_CHART_LOCATION,
Expand All @@ -28,7 +27,6 @@
get_default_namespace_or,
get_mission,
get_namespaces_by_type,
get_pod,
wait_for_ingress_controller,
wait_for_pod_ready,
)
Expand Down Expand Up @@ -263,10 +261,6 @@ def deploy_network(directory: Path, debug: bool = False, namespace: Optional[str
click.echo(f"Failed to run Helm command: {cmd}")
return

lnd = node.get("lnd")
if lnd:
deploy_lnd(node, namespace)

except Exception as e:
click.echo(f"Error: {e}")
return
Expand All @@ -275,43 +269,6 @@ def deploy_network(directory: Path, debug: bool = False, namespace: Optional[str
Path(temp_override_file_path).unlink()


def deploy_lnd(node: object, namespace: str):
node_name = node.get("name")
lnd_name = f"{node_name}-lnd"

tank = get_pod(node_name, namespace)

# A little harsh but for now let's make sure this always works
assert tank

extra_conf = {
"extraLabels": {"chain": tank.metadata.labels["chain"]},
"config": ("\n").join(
[
f"bitcoin.{tank.metadata.labels['chain']}=1",
"bitcoind.rpcuser=user",
f"bitcoind.rpcpass={tank.metadata.labels['rpcpassword']}",
f"bitcoind.rpchost={node_name}:{int(tank.metadata.labels['RPCPort'])}",
f"bitcoind.zmqpubrawblock=tcp://{node_name}:{int(tank.metadata.labels['ZMQBlockPort'])}",
f"bitcoind.zmqpubrawtx=tcp://{node_name}:{int(tank.metadata.labels['ZMQTxPort'])}",
f"alias={lnd_name}",
f"externalhosts={lnd_name}",
f"tlsextradomain={lnd_name}",
]
),
}

with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as temp_file:
yaml.dump(extra_conf, temp_file)
extra_conf_file_path = Path(temp_file.name)

cmd = f"{HELM_COMMAND} {lnd_name} {LND_CHART_LOCATION} --namespace {namespace} -f {extra_conf_file_path}"
if not stream_command(cmd):
print(f"Failed to run Helm command: {cmd}")
return
Path(extra_conf_file_path).unlink()


def deploy_namespaces(directory: Path):
namespaces_file_path = directory / NAMESPACES_FILE
defaults_file_path = directory / DEFAULTS_NAMESPACE_FILE
Expand Down
11 changes: 8 additions & 3 deletions test/data/ln/network.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ nodes:
- name: tank-0000
addnode:
- tank-0001
lnd: true
ln:
lnd: true

- name: tank-0001
addnode:
- tank-0002
lnd: true
ln:
lnd: true

- name: tank-0002
addnode:
- tank-0000
lnd: true
ln:
lnd: true
3 changes: 2 additions & 1 deletion test/data/signet/node-defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ image:
pullPolicy: Always
tag: "27.0"

chain: signet
global:
chain: signet

spec:
restartPolicy: Never
Expand Down
Loading

0 comments on commit d9aad8f

Please sign in to comment.