Skip to content

Commit f01f383

Browse files
committed
circuit breaker setup
1 parent a114d89 commit f01f383

File tree

7 files changed

+101
-88
lines changed

7 files changed

+101
-88
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{{- define "mychart.name" -}}
2+
{{- .Chart.Name | trunc 63 | trimSuffix "-" -}}
3+
{{- end -}}
4+
5+
{{- define "mychart.fullname" -}}
6+
{{- printf "%s-%s" (include "mychart.name" .) .Release.Name | trunc 63 | trimSuffix "-" -}}
7+
{{- end -}}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ include "mychart.fullname" . }}-data
5+
data:
6+
tls.cert: |
7+
-----BEGIN CERTIFICATE-----
8+
MIIB8TCCAZagAwIBAgIUJDsR6mmY+TaO9pCfjtotlbOkzJMwCgYIKoZIzj0EAwIw
9+
MjEfMB0GA1UECgwWbG5kIGF1dG9nZW5lcmF0ZWQgY2VydDEPMA0GA1UEAwwGd2Fy
10+
bmV0MB4XDTI0MTExMTE2NTM1MFoXDTM0MTEwOTE2NTM1MFowMjEfMB0GA1UECgwW
11+
bG5kIGF1dG9nZW5lcmF0ZWQgY2VydDEPMA0GA1UEAwwGd2FybmV0MFkwEwYHKoZI
12+
zj0CAQYIKoZIzj0DAQcDQgAEBVltIvaTlAQI/3FFatTqVflZuZdRJ0SmRMSJrFLP
13+
tp0fxE7hmteSt6gjQriy90fP8j9OJXBNAjt915kLY4zVvqOBiTCBhjAOBgNVHQ8B
14+
Af8EBAMCAqQwEwYDVR0lBAwwCgYIKwYBBQUHAwEwDwYDVR0TAQH/BAUwAwEB/zAd
15+
BgNVHQ4EFgQU5d8QMrwhLgTkDjWA+eXZGz+dybUwLwYDVR0RBCgwJoIJbG9jYWxo
16+
b3N0ggEqhwR/AAABhxAAAAAAAAAAAAAAAAAAAAABMAoGCCqGSM49BAMCA0kAMEYC
17+
IQDPofN0fEl5gTwCYhk3nZbjMqJhZ8BsSJ6K8XRhxr7zbwIhAPsgQCFOqUWg632O
18+
NEO53OQ6CIqnpxSskjsFNH4ZBQOE
19+
-----END CERTIFICATE-----
20+
admin.macaroon.hex: |
21+
0201036c6e6402f801030a1062beabbf2a614b112128afa0c0b4fdd61201301a160a0761646472657373120472656164120577726974651a130a04696e666f120472656164120577726974651a170a08696e766f69636573120472656164120577726974651a210a086d616361726f6f6e120867656e6572617465120472656164120577726974651a160a076d657373616765120472656164120577726974651a170a086f6666636861696e120472656164120577726974651a160a076f6e636861696e120472656164120577726974651a140a057065657273120472656164120577726974651a180a067369676e6572120867656e657261746512047265616400000620b17be53e367290871681055d0de15587f6d1cd47d1248fe2662ae27f62cfbdc6

resources/plugins/circuitbreaker/charts/circuitbreaker/templates/deployment.yaml

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: {{ include "mychart.fullname" . }}
5+
labels:
6+
app: {{ include "mychart.name" . }}
7+
mission: {{ .Values.name }}
8+
spec:
9+
initContainers:
10+
- name: "init"
11+
image: "busybox"
12+
command:
13+
- "sh"
14+
- "-c"
15+
args:
16+
- >
17+
mkdir -p /shared/.lnd/data/chain/bitcoin/mainnet &&
18+
cp /configmap/tls.cert /shared/.lnd/tls.cert &&
19+
cat /configmap/admin.macaroon.hex | xxd -r -p > /shared/.lnd/data/chain/bitcoin/mainnet/admin.macaroon
20+
volumeMounts:
21+
- name: shared-volume
22+
mountPath: /shared
23+
- name: configmap-volume
24+
mountPath: /configmap
25+
containers:
26+
- name: {{ .Values.name }}
27+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
28+
imagePullPolicy: {{ .Values.image.pullPolicy }}
29+
command:
30+
- "sh"
31+
- "-c"
32+
args:
33+
- >
34+
mkdir -p /root/.lnd/data/chain/bitcoin/mainnet &&
35+
ln -s /shared/.lnd/tls.cert /root/.lnd/tls.cert &&
36+
ln -s /shared/.lnd/data/chain/bitcoin/mainnet/admin.macaroon /root/.lnd/data/chain/bitcoin/mainnet/admin.macaroon &&
37+
circuitbreaker --rpcserver={{ .Values.lnd.rpcserver }} --httplisten={{ .Values.lnd.httplisten }}
38+
volumeMounts:
39+
- name: shared-volume
40+
mountPath: /shared
41+
volumes:
42+
- name: configmap-volume
43+
configMap:
44+
name: {{ include "mychart.fullname" . }}-data
45+
- name: shared-volume
46+
emptyDir: {}

resources/plugins/circuitbreaker/charts/circuitbreaker/templates/service.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
podName: "circuitbreaker-pod"
2-
rpcserver: "localhost:10009"
3-
httplisten: "0.0.0.0:9235"
1+
name: "circuitbreaker"
42
image:
53
repository: "camillarhi/circuitbreaker"
64
tag: "latest"
7-
pullPolicy: IfNotPresent
5+
pullPolicy: IfNotPresent
6+
workingVolume:
7+
name: working-volume
8+
mountPath: /working
9+
configmapVolume:
10+
name: configmap-volume
11+
mountPath: /configmap
12+
lnd:
13+
rpcserver: "host.docker.internal:10009" # Default LND RPC server address
14+
httplisten: "0.0.0.0:9235" # Default HTTP listen address

resources/plugins/circuitbreaker/plugin.py

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,11 @@ def _entrypoint(ctx, plugin_content: dict, warnet_content: dict):
8585

8686
match hook_value:
8787
case HookValue.POST_DEPLOY:
88-
# data = get_data(plugin_content)
89-
# if data:
90-
# log.info(f"Launching circuit breaker with data: {data}")
91-
# _create_secrets()
92-
_launch_circuit_breaker(ctx, plugin_content)
93-
# else:
94-
# _launch_circuit_breaker(ctx, install_name="circuitbreaker")
88+
data = get_data(plugin_content)
89+
if data:
90+
_launch_pod(ctx, install_name="circuitbreaker", **data)
91+
else:
92+
_launch_pod(ctx, install_name="circuitbreaker")
9593
case _:
9694
log.info(f"No action required for hook {hook_value}")
9795

@@ -186,40 +184,21 @@ def _create_secrets():
186184
log.error(f"Failed to create secrets for {node_name}: {e}")
187185
raise PluginError(f"Failed to create secrets for {node_name}.")
188186

189-
def _launch_circuit_breaker(ctx,
190-
plugin_content: dict,
191-
install_name: str="circuitbreaker",
192-
podName: str ="circuitbreaker-pod",
193-
rpcserver: str = "localhost:10009",
194-
httplisten: str = "0.0.0.0:9235"):
187+
def _launch_pod(ctx,
188+
install_name: str = "circuitbreaker",
189+
podName: str = "circuitbreaker-pod",
190+
rpcserver: str = "localhost:10009",
191+
httplisten: str = "0.0.0.0:9235"):
195192
timestamp = int(time.time())
196193
# release_name = f"cb-{install_name}"
197194

198-
lnd_pods = subprocess.check_output(["kubectl", "get", "pods", "-l", "app=warnet", "-l", "mission=lightning", "-o", "name"]).decode().splitlines()
199-
for node in lnd_pods:
200-
node_name = node.split('/')[-1]
201-
log.info(f"Launching Circuit Breaker for {node_name}")
202-
release_name = f"circuitbreaker-{node_name}"
203-
204-
command = (
205-
f"helm upgrade --install {release_name} {ctx.obj[PLUGIN_DIR_TAG]}/charts/circuitbreaker "
206-
f"--set podName={release_name} --set rpcserver=localhost:10009 --set httplisten=0.0.0.0:9235"
207-
)
208-
209-
# command = f"helm upgrade --install {release_name} {ctx.obj[PLUGIN_DIR_TAG]}/charts/circuitbreaker"
210-
# command = (
211-
# f"helm upgrade --install {install_name} {ctx.obj[PLUGIN_DIR_TAG]}/charts/circuitbreaker "
212-
# f"--set podName={podName} --set rpcserver={rpcserver} --set httplisten={httplisten}"
213-
# )
214-
log.info(command)
215-
try:
216-
run_command(command)
195+
command = (
196+
f"helm upgrade --install {install_name} {ctx.obj[PLUGIN_DIR_TAG]}/charts/circuitbreaker "
197+
f"--set podName={podName} --set rpcserver={rpcserver} --set httplisten={httplisten}"
198+
)
217199

218-
# if(hook_value==HookValue.POST_DEPLOY):
219-
wait_for_init(release_name, namespace=get_default_namespace(), quiet=True)
220-
except Exception as e:
221-
log.error(f"Failed to launch Circuit Breaker for {node_name}: {e}")
222-
200+
log.info(command)
201+
log.info(run_command(command))
223202

224203
if __name__ == "__main__":
225204
circuitbreaker()

0 commit comments

Comments
 (0)