Skip to content

Commit 90ebfd6

Browse files
committed
add resources key to schema file
1 parent a7a92cb commit 90ebfd6

File tree

7 files changed

+93
-49
lines changed

7 files changed

+93
-49
lines changed

src/warnet/backend/kubernetes_backend.py

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -384,33 +384,62 @@ def create_bitcoind_container(self, tank: Tank) -> client.V1Container:
384384
bitcoind_options = tank.get_bitcoin_conf(peers)
385385
container_env = [client.V1EnvVar(name="BITCOIN_ARGS", value=bitcoind_options)]
386386

387-
bitcoind_container = client.V1Container(
388-
name=container_name,
389-
image=container_image,
390-
env=container_env,
391-
liveness_probe=client.V1Probe(
387+
if tank.resources:
388+
resources = client.V1ResourceRequirements(
389+
requests=tank.resources["requests"],
390+
limits=tank.resources["limits"],
391+
)
392+
else:
393+
resources = client.V1ResourceRequirements()
394+
395+
liveness_probe = client.V1Probe(
392396
failure_threshold=3,
393397
initial_delay_seconds=5,
394398
period_seconds=5,
395399
timeout_seconds=1,
396400
_exec=client.V1ExecAction(command=["pidof", "bitcoind"]),
397-
),
398-
readiness_probe=client.V1Probe(
401+
)
402+
readiness_probe = client.V1Probe(
399403
failure_threshold=1,
400404
initial_delay_seconds=0,
401405
period_seconds=1,
402406
timeout_seconds=1,
403407
tcp_socket=client.V1TCPSocketAction(port=tank.rpc_port),
404-
),
405-
security_context=client.V1SecurityContext(
408+
)
409+
security_context = client.V1SecurityContext(
406410
privileged=True,
407411
capabilities=client.V1Capabilities(add=["NET_ADMIN", "NET_RAW"]),
408-
),
409412
)
410-
self.log.debug(
411-
f"Created bitcoind container for tank {tank.index} using {bitcoind_options=:}"
412-
)
413-
return bitcoind_container
413+
if tank.resources:
414+
bitcoind_container = client.V1Container(
415+
name=container_name,
416+
image=container_image,
417+
env=container_env,
418+
liveness_probe=liveness_probe,
419+
readiness_probe=readiness_probe,
420+
security_context=security_context,
421+
resources=client.V1ResourceRequirements(
422+
requests=tank.resources["requests"],
423+
limits=tank.resources["limits"],
424+
),
425+
)
426+
self.log.debug(
427+
f"Created bitcoind container for tank {tank.index} using {bitcoind_options=:}"
428+
)
429+
return bitcoind_container
430+
else:
431+
bitcoind_container = client.V1Container(
432+
name=container_name,
433+
image=container_image,
434+
env=container_env,
435+
liveness_probe=liveness_probe,
436+
readiness_probe=readiness_probe,
437+
security_context=security_context,
438+
)
439+
self.log.debug(
440+
f"Created bitcoind container for tank {tank.index} using {bitcoind_options=:}"
441+
)
442+
return bitcoind_container
414443

415444
def create_prometheus_container(self, tank) -> client.V1Container:
416445
env = [

src/warnet/cli/graph.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def create(number: int, outfile: Path, version: str, bitcoin_conf: Path, random:
4040
@click.option("--outfile", type=click.Path())
4141
@click.option("--cb", type=str)
4242
@click.option("--ln_image", type=str)
43-
def import_json(infile: Path, outfile: Path, cb: str, ln_image: str):
43+
@click.option("--ci", is_flag=True)
44+
def import_json(infile: Path, outfile: Path, cb: str, ln_image: str, ci: bool = False):
4445
"""
4546
Create a cycle graph with nodes imported from lnd `describegraph` JSON file,
4647
and additionally include 7 extra random outbounds per node. Include lightning
@@ -64,6 +65,8 @@ def import_json(infile: Path, outfile: Path, cb: str, ln_image: str):
6465
graph.nodes[n]["ln_cb_image"] = cb
6566
if ln_image:
6667
graph.nodes[n]["ln_image"] = ln_image
68+
if ci:
69+
graph.nodes[n]["resources"] = "{}"
6770

6871
# Save a map of LN pubkey -> Tank index
6972
ln_ids = {}

src/warnet/graph_schema.json

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,66 +16,79 @@
1616
"node": {
1717
"type": "object",
1818
"properties": {
19-
"version": {
20-
"type": "string",
21-
"comment": "Bitcoin Core version with an available Warnet tank image on Dockerhub. May also be a GitHub repository with format user/repository:branch to build from source code"},
2219
"image": {
2320
"type": "string",
24-
"comment": "Bitcoin Core Warnet tank image on Dockerhub with the format repository/image:tag"},
21+
"default": "bitcoindevproject/bitcoin:27.0",
22+
"comment": "Bitcoin Core Warnet tank image on Dockerhub with the format repository/image:tag"
23+
},
2524
"bitcoin_config": {
2625
"type": "string",
2726
"default": "",
28-
"comment": "A string of Bitcoin Core options in command-line format, e.g. '-debug=net -blocksonly'"},
27+
"comment": "A string of Bitcoin Core options in command-line format, e.g. '-debug=net -blocksonly'"
28+
},
2929
"tc_netem": {
3030
"type": "string",
31-
"comment": "A tc-netem command as a string beginning with 'tc qdisc add dev eth0 root netem'"},
31+
"comment": "A tc-netem command as a string beginning with 'tc qdisc add dev eth0 root netem'"
32+
},
3233
"exporter": {
3334
"type": "boolean",
3435
"default": false,
35-
"comment": "Whether to attach a Prometheus data exporter to the tank"},
36+
"comment": "Whether to attach a Prometheus data exporter to the tank"
37+
},
3638
"metrics": {
3739
"type": "string",
38-
"comment": "A space-separated string of RPC queries to scrape by Prometheus"},
40+
"comment": "A space-separated string of RPC queries to scrape by Prometheus"
41+
},
3942
"collect_logs": {
4043
"type": "boolean",
41-
"default": false,
42-
"comment": "Whether to collect Bitcoin Core debug logs with Promtail"},
44+
"default": true,
45+
"comment": "Whether to collect Bitcoin Core debug logs with Promtail"
46+
},
4347
"build_args": {
4448
"type": "string",
4549
"default": "",
46-
"comment": "A string of configure options used when building Bitcoin Core from source code, e.g. '--without-gui --disable-tests'"},
50+
"comment": "A string of configure options used when building Bitcoin Core from source code, e.g. '--without-gui --disable-tests'"
51+
},
4752
"ln": {
4853
"type": "string",
49-
"comment": "Attach a lightning network node of this implementation (currently only supports 'lnd' or 'cln')"},
54+
"comment": "Attach a lightning network node of this implementation (currently only supports 'lnd' or 'cln')"
55+
},
5056
"ln_image": {
5157
"type": "string",
52-
"comment": "Specify a lightning network node image from Dockerhub with the format repository/image:tag"},
58+
"comment": "Specify a lightning network node image from Dockerhub with the format repository/image:tag"
59+
},
5360
"ln_cb_image": {
5461
"type": "string",
55-
"comment": "Specify a lnd Circuit Breaker image from Dockerhub with the format repository/image:tag"},
62+
"comment": "Specify a lnd Circuit Breaker image from Dockerhub with the format repository/image:tag"
63+
},
5664
"ln_config": {
5765
"type": "string",
58-
"comment": "A string of arguments for the lightning network node in command-line format, e.g. '--protocol.wumbo-channels --bitcoin.timelockdelta=80'"}
66+
"comment": "A string of arguments for the lightning network node in command-line format, e.g. '--protocol.wumbo-channels --bitcoin.timelockdelta=80'"
67+
},
68+
"resources": {
69+
"type": "string",
70+
"comment": "Kubernetes resource requests and limits for the node",
71+
"default": "{'requests':{'cpu':'500m', 'memory':'500Mi'}, 'limits':{'cpu':'1000m', 'memory':'1500Mi'}}"
72+
}
5973
},
60-
"additionalProperties": false,
61-
"oneOf": [
62-
{"required": ["version"]},
63-
{"required": ["image"]}
64-
],
74+
"additionalProperties": false,
6575
"required": []
6676
},
6777
"edge": {
6878
"type": "object",
6979
"properties": {
7080
"channel_open": {
7181
"type": "string",
72-
"comment": "Indicate that this edge is a lightning channel with these arguments passed to lnd openchannel"},
82+
"comment": "Indicate that this edge is a lightning channel with these arguments passed to lnd openchannel"
83+
},
7384
"source_policy": {
7485
"type": "string",
75-
"comment": "Update the channel originator policy by passing these arguments passed to lnd updatechanpolicy"},
86+
"comment": "Update the channel originator policy by passing these arguments passed to lnd updatechanpolicy"
87+
},
7688
"target_policy": {
7789
"type": "string",
78-
"comment": "Update the channel partner policy by passing these arguments passed to lnd updatechanpolicy"}
90+
"comment": "Update the channel partner policy by passing these arguments passed to lnd updatechanpolicy"
91+
}
7992
},
8093
"additionalProperties": false,
8194
"required": []

src/warnet/tank.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __init__(self, index: int, warnet):
4646
self.bitcoin_network = warnet.bitcoin_network
4747
self.version: str = ""
4848
self.image: str = ""
49+
self.resources: dict = dict()
4950
self.bitcoin_config = ""
5051
self.netem = None
5152
self.exporter = False
@@ -81,7 +82,10 @@ def parse_graph_node(self, node):
8182
value = node.get(property, specs.get("default"))
8283
if property == "version":
8384
self._parse_version(value)
84-
setattr(self, property, value)
85+
if property == "resources":
86+
setattr(self, property, eval(value))
87+
else:
88+
setattr(self, property, value)
8589
graph_properties[property] = value
8690

8791
if self.version and self.image:

src/warnet/utils.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -421,15 +421,8 @@ def create_cycle_graph(n: int, version: str, bitcoin_conf: str | None, random_ve
421421
conf_contents = dump_bitcoin_conf(conf_dict, for_graph=True)
422422

423423
# populate our custom fields
424-
for i, node in enumerate(graph.nodes()):
425-
if random_version:
426-
graph.nodes[node]["version"] = random.choice(WEIGHTED_TAGS)
427-
else:
428-
# One node demoing the image tag
429-
if i == 1:
430-
graph.nodes[node]["image"] = f"bitcoindevproject/bitcoin:{version}"
431-
else:
432-
graph.nodes[node]["version"] = version
424+
for node in graph.nodes():
425+
graph.nodes[node]["image"] = f"bitcoindevproject/bitcoin:{version}"
433426
graph.nodes[node]["bitcoin_config"] = conf_contents
434427
graph.nodes[node]["tc_netem"] = ""
435428
graph.nodes[node]["build_args"] = ""

test/data/services.graphml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<key id="ln_image" attr.name="ln_image" attr.type="string" for="node" />
1212
<key id="ln_cb_image" attr.name="ln_cb_image" attr.type="string" for="node" />
1313
<key id="ln_config" attr.name="ln_config" attr.type="string" for="node" />
14+
<key id="resources" attr.name="resources" attr.type="string" for="node" />
1415
<key id="channel_open" attr.name="channel_open" attr.type="string" for="edge" />
1516
<key id="source_policy" attr.name="source_policy" attr.type="string" for="edge" />
1617
<key id="target_policy" attr.name="target_policy" attr.type="string" for="edge" />
@@ -21,6 +22,7 @@
2122
<data key="bitcoin_config">-uacomment=w0 -debug=validation</data>
2223
<data key="exporter">true</data>
2324
<data key="ln">lnd</data>
25+
<data key="resources">{'requests':{'cpu':'25m', 'memory':'100Mi'}, 'limits':{'cpu':'100m', 'memory':'250Mi'}}</data>
2426
</node>
2527
</graph>
2628
</graphml>

test/graph_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_graph_creation_and_import(self):
4141
self.log.info(f"CLI tool importing json and writing test graph file: {self.tf_import}")
4242
self.log.info(
4343
self.warcli(
44-
f"graph import-json {self.json_file_path} --outfile={self.tf_import} --ln_image=carlakirkcohen/lnd:attackathon --cb=carlakirkcohen/circuitbreaker:attackathon-test",
44+
f"graph import-json {self.json_file_path} --outfile={self.tf_import} --ln_image=carlakirkcohen/lnd:attackathon --cb=carlakirkcohen/circuitbreaker:attackathon-test --ci",
4545
network=False,
4646
)
4747
)

0 commit comments

Comments
 (0)