Skip to content

Commit f7d4bd9

Browse files
authored
Merge pull request #1 from Camillarhi/circuitbreaker3
Circuit breaker plugin integration
2 parents f0ff2a3 + 4f4bde8 commit f7d4bd9

File tree

5 files changed

+71
-22
lines changed

5 files changed

+71
-22
lines changed

resources/networks/hello/network.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ plugins: # Each plugin section has a number of hooks available (preDeploy, post
5959
entrypoint: "../../plugins/hello" # This entrypoint path is relative to the network.yaml file
6060
podName: "hello-pre-deploy"
6161
helloTo: "preDeploy!"
62+
circuitbreaker:
63+
entrypoint: "../../plugins/circuitbreaker"
64+
url: "http://127.0.0.1:9235"
65+
apiUrl: "/api"
66+
mode: "fail" # Operating mode: fail, queue, or queue_peer_initiated
67+
maxPendingHtlcs: 10 # Default maximum pending HTLCs per peer
68+
rateLimit: 1 # Minimum seconds between HTLCs (token bucket rate limit)
6269
postDeploy:
6370
hello:
6471
entrypoint: "../../plugins/hello"
@@ -67,21 +74,56 @@ plugins: # Each plugin section has a number of hooks available (preDeploy, post
6774
simln: # You can have multiple plugins per hook
6875
entrypoint: "../../plugins/simln"
6976
activity: '[{"source": "tank-0003-ln", "destination": "tank-0005-ln", "interval_secs": 1, "amount_msat": 2000}]'
77+
circuitbreaker:
78+
entrypoint: "../../plugins/circuitbreaker"
79+
url: "http://127.0.0.1:9235"
80+
apiUrl: "/api"
81+
mode: "fail" # Operating mode: fail, queue, or queue_peer_initiated
82+
maxPendingHtlcs: 10 # Default maximum pending HTLCs per peer
83+
rateLimit: 1 # Minimum seconds between HTLCs (token bucket rate limit)
7084
preNode: # preNode plugins run before each node is deployed
7185
hello:
7286
entrypoint: "../../plugins/hello"
7387
helloTo: "preNode!"
88+
circuitbreaker:
89+
entrypoint: "../../plugins/circuitbreaker"
90+
url: "http://127.0.0.1:9235"
91+
apiUrl: "/api"
92+
mode: "fail" # Operating mode: fail, queue, or queue_peer_initiated
93+
maxPendingHtlcs: 10 # Default maximum pending HTLCs per peer
94+
rateLimit: 1 # Minimum seconds between HTLCs (token bucket rate limit)
7495
postNode:
7596
hello:
7697
entrypoint: "../../plugins/hello"
7798
helloTo: "postNode!"
99+
circuitbreaker:
100+
entrypoint: "../../plugins/circuitbreaker"
101+
url: "http://127.0.0.1:9235"
102+
apiUrl: "/api"
103+
mode: "fail" # Operating mode: fail, queue, or queue_peer_initiated
104+
maxPendingHtlcs: 10 # Default maximum pending HTLCs per peer
105+
rateLimit: 1 # Minimum seconds between HTLCs (token bucket rate limit)
78106
preNetwork:
79107
hello:
80108
entrypoint: "../../plugins/hello"
81109
helloTo: "preNetwork!"
82110
podName: "hello-pre-network"
111+
circuitbreaker:
112+
entrypoint: "../../plugins/circuitbreaker"
113+
url: "http://127.0.0.1:9235"
114+
apiUrl: "/api"
115+
mode: "fail" # Operating mode: fail, queue, or queue_peer_initiated
116+
maxPendingHtlcs: 10 # Default maximum pending HTLCs per peer
117+
rateLimit: 1 # Minimum seconds between HTLCs (token bucket rate limit)
83118
postNetwork:
84119
hello:
85120
entrypoint: "../../plugins/hello"
86121
helloTo: "postNetwork!"
87122
podName: "hello-post-network"
123+
circuitbreaker:
124+
entrypoint: "../../plugins/circuitbreaker"
125+
url: "http://127.0.0.1:9235"
126+
apiUrl: "/api"
127+
mode: "fail" # Operating mode: fail, queue, or queue_peer_initiated
128+
maxPendingHtlcs: 10 # Default maximum pending HTLCs per peer
129+
rateLimit: 1 # Minimum seconds between HTLCs (token bucket rate limit)

resources/plugins/circuitbreaker/charts/circuitbreaker/templates/_helpers.tpl

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
apiVersion: v1
22
kind: Pod
33
metadata:
4-
name: {{ include "mychart.fullname" . }}
4+
name: {{ .Values.name }}
55
labels:
6-
app: {{ include "mychart.name" . }}
7-
mission: {{ .Values.name }}
6+
app: {{ .Chart.Name }}
87
spec:
98
containers:
10-
- name: {{ .Values.name }}
9+
- name: {{ .Values.name }}-container
1110
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
1211
imagePullPolicy: {{ .Values.image.pullPolicy }}
1312
command: ["sh", "-c"]
1413
args:
15-
- echo "Hello {{ .Values.mode }}";
14+
- echo "Hello {{ .Values.name }}";
1615
resources: {}
1716

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "circuitbreaker"
22
image:
33
repository: "camillarhi/circuitbreaker"
4-
tag: "0.2.3"
4+
tag: "latest"
55
pullPolicy: IfNotPresent

resources/plugins/circuitbreaker/plugin.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
from warnet.constants import PLUGIN_ANNEX, AnnexMember, HookValue, WarnetContent
1212
from warnet.process import run_command
1313

14+
from warnet.k8s import (
15+
download,
16+
get_default_namespace,
17+
get_mission,
18+
get_static_client,
19+
wait_for_init,
20+
write_file_to_container,
21+
)
22+
1423
MISSION = "circuitbreaker"
1524
PRIMARY_CONTAINER = MISSION
1625

@@ -84,15 +93,15 @@ def _entrypoint(ctx, plugin_content: dict, warnet_content: dict):
8493
):
8594
data = get_data(plugin_content)
8695
if data:
87-
_launch_circuit_breaker(ctx, node_name=hook_value.value.lower())
96+
_launch_circuit_breaker(ctx, node_name=hook_value.value.lower()+"breaker",hook_value=hook_value.value)
8897
else:
89-
_launch_circuit_breaker(ctx, node_name=hook_value.value.lower())
98+
_launch_circuit_breaker(ctx, node_name=hook_value.value.lower()+"breaker",hook_value=hook_value.value)
9099
case HookValue.PRE_NODE:
91100
name = warnet_content[PLUGIN_ANNEX][AnnexMember.NODE_NAME.value] + "-pre-pod"
92-
_launch_circuit_breaker(ctx, node_name=hook_value.value.lower() + "-" + name)
101+
_launch_circuit_breaker(ctx, node_name=hook_value.value.lower() + "-" + name, hook_value=hook_value.value)
93102
case HookValue.POST_NODE:
94103
name = warnet_content[PLUGIN_ANNEX][AnnexMember.NODE_NAME.value] + "-post-pod"
95-
_launch_circuit_breaker(ctx, node_name=hook_value.value.lower() + "-" + name)
104+
_launch_circuit_breaker(ctx, node_name=hook_value.value.lower() + "-" + name, hook_value=hook_value.value)
96105

97106
def get_data(plugin_content: dict) -> Optional[dict]:
98107
data = {
@@ -103,14 +112,20 @@ def get_data(plugin_content: dict) -> Optional[dict]:
103112
return data or None
104113

105114

106-
def _launch_circuit_breaker(ctx, node_name: str):
115+
def _launch_circuit_breaker(ctx, node_name: str, hook_value: str):
107116
timestamp = int(time.time())
108-
release_name = f"cb-{node_name}-{timestamp}"
109-
110-
command = f"helm upgrade --install {node_name} {ctx.obj[PLUGIN_DIR_TAG]}/charts/circuitbreaker --set node={node_name}"
117+
release_name = f"cb-{node_name}"
111118

119+
# command = f"helm upgrade --install {release_name} {ctx.obj[PLUGIN_DIR_TAG]}/charts/circuitbreaker"
120+
command = (
121+
f"helm upgrade --install {release_name} {ctx.obj[PLUGIN_DIR_TAG]}/charts/circuitbreaker "
122+
f"--set name={release_name}"
123+
)
112124
log.info(command)
113-
log.info(run_command(command))
125+
run_command(command)
126+
127+
if(hook_value==HookValue.POST_DEPLOY):
128+
wait_for_init(release_name, namespace=get_default_namespace(), quiet=True)
114129

115130

116131
if __name__ == "__main__":

0 commit comments

Comments
 (0)