Skip to content

Commit 89ad425

Browse files
committed
Add config exmaples to README for resource reservations on node level
Fixes: #373
1 parent 2ce3d73 commit 89ad425

6 files changed

Lines changed: 23 additions & 33 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
added:
2+
- Add resource reservation support for PVE nodes (@Chipmonk2). [#373]

‎.gitignore‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,3 @@ build/
55
dist/
66
*.egg-info/
77
proxlb_dev.yaml
8-
log.log
9-
proxlb/log.log
10-
proxlb.yaml
11-
proxlb_reservation.yaml

‎README.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ The following options can be set in the configuration file `proxlb.yaml`:
290290
| | method | | memory | `Str` | The balancing method that should be used. [values: `memory` (default), `cpu`, `disk`]|
291291
| | mode | | used | `Str` | The balancing mode that should be used. [values: `used` (default), `assigned`, `psi` (pressure)] |
292292
| | balance_larger_guests_first | | False | `Bool` | Option to prefer larger/smaller guests first |
293+
| | node_resource_reserve | | { default: { memory: 4 }, { node01: { memory: 6 }} } | `Dict` | A dict of pool names and their type for creating affinity/anti-affinity rules |
293294
| | psi | | { nodes: { memory: { pressure_full: 0.20, pressure_some: 0.20, pressure_spikes: 1.00 }}} | `Dict` | A dict of PSI based thresholds for nodes and guests |
294295
| | pools | | pools: { dev: { type: affinity }, de-nbg01-db: { type: anti-affinity }} | `Dict` | A dict of pool names and their type for creating affinity/anti-affinity rules |
295296
| `service` | | | | | |
@@ -338,6 +339,11 @@ balancing:
338339
method: memory
339340
mode: used
340341
balance_larger_guests_first: False
342+
node_resource_reserve:
343+
defaults:
344+
memory: 4
345+
node01:
346+
memory: 6
341347
# # PSI thresholds only apply when using mode 'psi'
342348
# # PSI based balancing is currently in beta and req. PVE >= 9
343349
# psi:
@@ -530,7 +536,7 @@ Connect with us in our dedicated chat room for immediate support and live intera
530536
| Support Channel | Link |
531537
|------|:------:|
532538
| Matrix | [#proxlb:gyptazy.com](https://matrix.to/#/#proxlb:gyptazy.com) |
533-
| Discord | [Discord](https://discord.gg/JemGu7WbfQ) |
539+
| Discord | [Discord](https://discord.gg/JemGu7WbfQ) |
534540
| GitHub Community | [GitHub Community](https://github.com/gyptazy/ProxLB/discussions/)
535541
| GitHub | [ProxLB GitHub](https://github.com/gyptazy/ProxLB/issues) |
536542

‎config/proxlb_example.yaml‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ balancing:
3333
method: memory # 'memory' | 'cpu' | 'disk'
3434
mode: used # 'assigned' | 'used' | 'psi'
3535
balance_larger_guests_first: False # Option to prioritize balancing of larger or smaller guests first
36+
node_resource_reserve: # Optional: Define resource reservations for nodes (in GB)
37+
defaults: # Default reservation values applying to all nodes (unless explicitly overridden)
38+
memory: 4 # Default: 4 GB memory reserved per node
39+
node01: # Specific node reservation override for node 'node01'
40+
memory: 6 # Specific: 6 GB memory reserved for node 'node01'
3641
# # PSI thresholds only apply when using mode 'psi'
3742
# psi:
3843
# nodes:
@@ -69,15 +74,6 @@ balancing:
6974
pin: # Define a pinning og guests to specific node(s)
7075
- virt66
7176
- virt77
72-
# reserve some ressource for proxmox and / or other application on the nodes
73-
node_resource_reserve:
74-
# defaults - cpu in %, memory in GB, disk in %
75-
defaults:
76-
cpu: 10
77-
memory: 4
78-
disk: 20
79-
node1:
80-
memory: 4
8177

8278
service:
8379
daemon: True

‎proxlb/models/nodes.py‎

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -256,32 +256,26 @@ def get_node_pve_version(proxmox_api, node_name: str) -> float:
256256
logger.debug("Finished: get_node_pve_version.")
257257
return version["version"]
258258

259-
260259
@staticmethod
261260
def apply_resource_reservation(node_name, proxlb_config: Dict[str, Any], node_data: Dict[str, Any]) -> None:
262261
"""
263262
Check if there is a a configured resource reservation for the current nodes and apply it as needed.
264263
Checks for a node specific config first, then if there is any configured default and if neither then nothing is reserved.
265264
Reservations are applied by directly modifying the data gathered from the nodes.
266265
267-
Args:
268-
node_name: (str) the name of the node
266+
Args:
267+
node_name: (str) the name of the node
269268
proxlb_config (Dict[str, Any]): A dictionary containing the ProxLB configuration.
270269
node_data: (Dict[str, Any]): Dict containing the current nodes data
271270
Returns: none
272271
"""
273-
logger.debug(f"Starting: Resource reservation")
274-
logger.debug(f"Processing resource reservation for node {node_name}")
275-
# load the balancing section from the config dict, will create an empty dict if there isnt anything
272+
logger.debug(f"Starting: apply_resource_reservation")
276273
balancing_cfg = proxlb_config.get("balancing", {})
277-
# get the reservation dict from the previously loaded dict , will create an empty dict if there isnt anything
278-
reserve_cfg = balancing_cfg.get("node_resource_reserve", {})
279-
# try to get the reserved memory for the node
274+
reserve_cfg = balancing_cfg.get("node_resource_reserve", {})
280275
reserved_memory_gb_node = reserve_cfg.get(node_name, {}).get("memory")
281-
# try to load the default reserved memory - will set to 0 if there isn't anything
282276
reserved_memory_gb_default = reserve_cfg.get("defaults", {}).get("memory", 0)
283277

284-
# make sure the reservation is a numeric value - check for both, default and node specific
278+
# Make sure the reservation is a numeric value - check for both, default and node specific
285279
if not isinstance(reserved_memory_gb_default, (int, float)):
286280
if reserved_memory_gb_default is not None:
287281
logger.info("Invalid default memory reservation: Found a string while expecting a numeric value - skipping default reservation")
@@ -292,16 +286,16 @@ def apply_resource_reservation(node_name, proxlb_config: Dict[str, Any], node_da
292286
logger.info(f"Invalid memory reservation: Found a string while expecting a numeric value - applying current default of {reserved_memory_gb_default} Bytes")
293287
reserved_memory_gb_node = reserved_memory_gb_default
294288

295-
# make sure the reservation is positive
289+
# Make sure the reservation is positive
296290
if reserved_memory_gb_node < 0:
297291
logger.info(f"{nodes['nodes'][node['node']]['name']}: Invalid assigned memory reservation, applying defaults")
298292
reserved_memory_gb_node = reserved_memory_gb_default
299293

300-
# convert the reservation from GB to Bytes, get the current nodes physical memory
294+
# Convert the reservation from GB to Bytes, get the current nodes physical memory
301295
reserved_memory_node = int(round(reserved_memory_gb_node * 1024 ** 3))
302296
total_mem = node_data.get("memory_total")
303297

304-
# check if the reservation doesnt exceed the nodes total memory
298+
# Check if the reservation doesnt exceed the nodes total memory
305299
if reserved_memory_node > total_mem:
306300
logger.debug(f"Reservation of {reserved_memory_node} Bytes exceeds available memory of {total_mem} Bytes- skipping reservation")
307301
reserved_memory_node = 0
@@ -310,7 +304,4 @@ def apply_resource_reservation(node_name, proxlb_config: Dict[str, Any], node_da
310304
logger.debug(f"Reserved Memory: {reserved_memory_gb_node} GB ({reserved_memory_node} Bytes)")
311305
node_data["memory_total"] -= reserved_memory_node
312306
Helper.update_node_resource_percentages(node_data)
313-
314-
logger.debug(f"End: Resource reservation")
315-
return
316-
307+
logger.debug(f"Finished: apply_resource_reservation")

‎proxlb/utils/helper.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,3 @@ def update_node_resource_percentages(node_data: Dict[str, any]) -> None:
362362
logger.debug(f"node data: {node_data}")
363363
logger.debug(f"End: Update resource percentages")
364364
return
365-

0 commit comments

Comments
 (0)