Skip to content

Commit da193f9

Browse files
authored
Merge pull request #412 from gyptazy/feature/406-strict-nonstrict-node-pinning
Add support for configuring node-pinning strictness (default: true) within pools
2 parents 0af770c + f11ca26 commit da193f9

7 files changed

Lines changed: 46 additions & 2 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
feature:
1+
added:
22
- Add support for Proxmox's native HA (affinity/anti-affinity) rules (@gyptazy). [#391]
33
- Add support for Proxmox's native HA (node-affinity) rules for pinning guests to nodes (@gyptazy). [#391]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
added:
2+
- Add support for configuring node-pinning strictness (default: true) within pools (@gyptazy). [#406]

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ balancing:
393393
pin:
394394
- virt66
395395
- virt77
396+
strict: False
396397
397398
service:
398399
daemon: True

‎config/proxlb_example.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ balancing:
7474
pin: # Define a pinning og guests to specific node(s)
7575
- virt66
7676
- virt77
77+
strict: False # Disable strict mode of node pinning for this pool
7778

7879
service:
7980
daemon: True

‎proxlb/models/calculations.py‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,20 @@ def val_node_relationships(proxlb_data: Dict[str, Any], guest_name: str):
519519
if len(proxlb_data["guests"][guest_name]["node_relationships"]) > 0:
520520
logger.debug(f"Guest '{guest_name}' has relationships defined to node(s): {','.join(proxlb_data['guests'][guest_name]['node_relationships'])}. Pinning to node.")
521521

522-
# Get the node with the most free resources of the group
522+
# Get the list of nodes that are defined as relationship for the guest
523523
guest_node_relation_list = proxlb_data["guests"][guest_name]["node_relationships"]
524+
525+
# Validate if strict relationships are defined. If not, we prefer
526+
# the most free node in addition to the relationship list.
527+
if proxlb_data["guests"][guest_name]["node_relationships_strict"]:
528+
logger.debug(f"Guest '{guest_name}' has strict node relationships defined. Only nodes in the relationship list will be considered for pinning.")
529+
else:
530+
logger.debug(f"Guest '{guest_name}' has non-strict node relationships defined. Prefering nodes in the relationship list for pinning.")
531+
Calculations.get_most_free_node(proxlb_data)
532+
most_free_node = proxlb_data["meta"]["balancing"]["balance_next_node"]
533+
guest_node_relation_list.append(most_free_node)
534+
535+
# Get the most free node from the relationship list, or the most free node overall
524536
Calculations.get_most_free_node(proxlb_data, False, guest_node_relation_list)
525537

526538
# Validate if the specified node name is really part of the cluster

‎proxlb/models/guests.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def get_guests(proxmox_api: any, pools: Dict[str, Any], ha_rules: Dict[str, Any]
103103
guests['guests'][guest['name']]['anti_affinity_groups'] = Tags.get_anti_affinity_groups(guests['guests'][guest['name']]['tags'], guests['guests'][guest['name']]['pools'], guests['guests'][guest['name']]['ha_rules'], proxlb_config)
104104
guests['guests'][guest['name']]['ignore'] = Tags.get_ignore(guests['guests'][guest['name']]['tags'])
105105
guests['guests'][guest['name']]['node_relationships'] = Tags.get_node_relationships(guests['guests'][guest['name']]['tags'], nodes, guests['guests'][guest['name']]['pools'], guests['guests'][guest['name']]['ha_rules'], proxlb_config)
106+
guests['guests'][guest['name']]['node_relationships_strict'] = Pools.get_pool_node_affinity_strictness(proxlb_config, guests['guests'][guest['name']]['pools'])
106107
guests['guests'][guest['name']]['type'] = 'vm'
107108

108109
logger.debug(f"Resources of Guest {guest['name']} (type VM) added: {guests['guests'][guest['name']]}")
@@ -149,6 +150,7 @@ def get_guests(proxmox_api: any, pools: Dict[str, Any], ha_rules: Dict[str, Any]
149150
guests['guests'][guest['name']]['anti_affinity_groups'] = Tags.get_anti_affinity_groups(guests['guests'][guest['name']]['tags'], guests['guests'][guest['name']]['pools'], guests['guests'][guest['name']]['ha_rules'], proxlb_config)
150151
guests['guests'][guest['name']]['ignore'] = Tags.get_ignore(guests['guests'][guest['name']]['tags'])
151152
guests['guests'][guest['name']]['node_relationships'] = Tags.get_node_relationships(guests['guests'][guest['name']]['tags'], nodes, guests['guests'][guest['name']]['pools'], guests['guests'][guest['name']]['ha_rules'], proxlb_config)
153+
guests['guests'][guest['name']]['node_relationships_strict'] = Pools.get_pool_node_affinity_strictness(proxlb_config, guests['guests'][guest['name']]['pools'])
152154
guests['guests'][guest['name']]['type'] = 'ct'
153155

154156
logger.debug(f"Resources of Guest {guest['name']} (type CT) added: {guests['guests'][guest['name']]}")

‎proxlb/models/pools.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,29 @@ def get_pools_for_guest(guest_name: str, pools: Dict[str, Any]) -> Dict[str, Any
115115

116116
logger.debug("Finished: get_pools_for_guests.")
117117
return guest_pools
118+
119+
@staticmethod
120+
def get_pool_node_affinity_strictness(proxlb_config: Dict[str, Any], guest_pools: list) -> bool:
121+
"""
122+
Retrieve the node affinity strictness setting for a guest across its pools.
123+
124+
Queries the ProxLB configuration to determine the node affinity strictness
125+
level for the specified guest based on its pool memberships. Returns the
126+
strictness setting from the first matching pool configuration.
127+
128+
Args:
129+
proxlb_config (Dict[str, Any]): ProxLB configuration dictionary.
130+
guest_pools (list): List of pool names the guest belongs to.
131+
132+
Returns:
133+
bool: Node affinity strictness setting (default True if not specified).
134+
"""
135+
logger.debug("Starting: get_pool_node_affinity_strictness.")
136+
137+
node_strictness = True
138+
for pool in guest_pools:
139+
pool_settings = proxlb_config.get("balancing", {}).get("pools", {}).get(pool, {})
140+
node_strictness = pool_settings.get("strict", True)
141+
142+
logger.debug("Finished: get_pool_node_affinity_strictness.")
143+
return node_strictness

0 commit comments

Comments
 (0)