diff --git a/resources/graphs/default.graphml b/resources/graphs/default.graphml index ce84579df..4b17bf6c6 100644 --- a/resources/graphs/default.graphml +++ b/resources/graphs/default.graphml @@ -15,12 +15,14 @@ + 27.0 -uacomment=w0 true true + laptop 27.0 diff --git a/src/warnet/backend/kubernetes_backend.py b/src/warnet/backend/kubernetes_backend.py index f8821888d..5bba425c3 100644 --- a/src/warnet/backend/kubernetes_backend.py +++ b/src/warnet/backend/kubernetes_backend.py @@ -20,6 +20,7 @@ from warnet.status import RunningStatus from warnet.tank import Tank from warnet.utils import parse_raw_messages +from warnet.resources import resource_profiles DOCKER_REGISTRY_CORE = "bitcoindevproject/bitcoin" LOCAL_REGISTRY = "warnet/bitcoin-core" @@ -384,6 +385,7 @@ def create_bitcoind_container(self, tank: Tank) -> client.V1Container: bitcoind_options = tank.get_bitcoin_conf(peers) container_env = [client.V1EnvVar(name="BITCOIN_ARGS", value=bitcoind_options)] + resources = resource_profiles[tank.profile] bitcoind_container = client.V1Container( name=container_name, image=container_image, @@ -406,6 +408,10 @@ def create_bitcoind_container(self, tank: Tank) -> client.V1Container: privileged=True, capabilities=client.V1Capabilities(add=["NET_ADMIN", "NET_RAW"]), ), + resources=client.V1ResourceRequirements( + requests=resources["requests"], + limits=resources["limits"], + ), ) self.log.debug( f"Created bitcoind container for tank {tank.index} using {bitcoind_options=:}" diff --git a/src/warnet/cli/graph.py b/src/warnet/cli/graph.py index 45128d603..da0fb9a8b 100644 --- a/src/warnet/cli/graph.py +++ b/src/warnet/cli/graph.py @@ -25,6 +25,7 @@ def create(number: int, outfile: Path, version: str, bitcoin_conf: Path, random: Returns XML file as string with or without --outfile option """ graph = create_cycle_graph(number, version, bitcoin_conf, random) + validate_graph_schema(graph) if outfile: file_path = Path(outfile) diff --git a/src/warnet/graph_schema.json b/src/warnet/graph_schema.json index ac1f7aa9f..744da6aa0 100644 --- a/src/warnet/graph_schema.json +++ b/src/warnet/graph_schema.json @@ -55,7 +55,11 @@ "comment": "Specify a lnd Circuit Breaker image from Dockerhub with the format repository/image:tag"}, "ln_config": { "type": "string", - "comment": "A string of arguments for the lightning network node in command-line format, e.g. '--protocol.wumbo-channels --bitcoin.timelockdelta=80'"} + "comment": "A string of arguments for the lightning network node in command-line format, e.g. '--protocol.wumbo-channels --bitcoin.timelockdelta=80'"}, + "profile": { + "type": "string", + "default": "default", + "comment": "A resource profile for the node'"} }, "additionalProperties": false, "oneOf": [ diff --git a/src/warnet/resources.py b/src/warnet/resources.py new file mode 100644 index 000000000..e09307b8f --- /dev/null +++ b/src/warnet/resources.py @@ -0,0 +1,23 @@ +# node resource profile presets +resource_profiles = { + "default": { + "requests": {"cpu": "500m", "memory": "500Mi"}, + "limits": {"cpu": "1000m", "memory": "1500Mi"}, + }, + "raspberry_pi": { + "requests": {"cpu": "100m", "memory": "128Mi"}, + "limits": {"cpu": "400m", "memory": "512Mi"}, + }, + "laptop": { + "requests": {"cpu": "500m", "memory": "1Gi"}, + "limits": {"cpu": "2000m", "memory": "4Gi"}, + }, + "desktop": { + "requests": {"cpu": "1000m", "memory": "2Gi"}, + "limits": {"cpu": "4000m", "memory": "8Gi"}, + }, + "server": { + "requests": {"cpu": "2000m", "memory": "4Gi"}, + "limits": {"cpu": "8000m", "memory": "16Gi"}, + }, +} diff --git a/src/warnet/tank.py b/src/warnet/tank.py index ac04d3f70..43d37b3e4 100644 --- a/src/warnet/tank.py +++ b/src/warnet/tank.py @@ -46,11 +46,13 @@ def __init__(self, index: int, warnet): self.bitcoin_network = warnet.bitcoin_network self.version: str = "" self.image: str = "" + self.profile: str = "default" self.bitcoin_config = "" self.netem = None self.exporter = False self.metrics = None self.collect_logs = False + self.resource_profile = "default" self.build_args = "" self.lnnode: LNNode | None = None self.rpc_port = 18443 diff --git a/src/warnet/utils.py b/src/warnet/utils.py index 23dad566b..a4a2133a6 100644 --- a/src/warnet/utils.py +++ b/src/warnet/utils.py @@ -435,6 +435,7 @@ def create_cycle_graph(n: int, version: str, bitcoin_conf: str | None, random_ve graph.nodes[node]["build_args"] = "" graph.nodes[node]["exporter"] = False graph.nodes[node]["collect_logs"] = False + graph.nodes[node]["profile"] = "default" convert_unsupported_attributes(graph) return graph