From: Daniel Kral <d.kral@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH ha-manager v5 10/23] manager: migrate ha groups to node affinity rules in-memory
Date: Wed, 30 Jul 2025 19:59:37 +0200 [thread overview]
Message-ID: <20250730175957.386674-11-d.kral@proxmox.com> (raw)
In-Reply-To: <20250730175957.386674-1-d.kral@proxmox.com>
Migrate the currently configured groups to node affinity rules
in-memory, so that they can be applied as such in the next patches and
therefore replace HA groups internally.
HA node affinity rules in their initial implementation are designed to
be as restrictive as HA groups, i.e. only allow a HA resource to be used
in a single node affinity rule, to ease the migration between them.
HA groups map directly to node affinity rules, except that the
'restricted' property is renamed to 'strict' and that the 'failback'
property is moved to the HA resources config.
The 'nofailback' property is moved to the HA resources config, because
it allows users to set it more granularly for individual HA resources
and allows the node affinity rules to be more extendible in the future,
e.g. multiple node affinity rules for a single HA resource.
Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
src/PVE/HA/Config.pm | 3 ++-
src/PVE/HA/Groups.pm | 49 +++++++++++++++++++++++++++++++++++++++++++
src/PVE/HA/Manager.pm | 18 ++++++++++++++--
3 files changed, 67 insertions(+), 3 deletions(-)
diff --git a/src/PVE/HA/Config.pm b/src/PVE/HA/Config.pm
index 7d071f3b..424a6e10 100644
--- a/src/PVE/HA/Config.pm
+++ b/src/PVE/HA/Config.pm
@@ -131,7 +131,8 @@ sub read_and_check_resources_config {
}
}
- return $conf;
+ # TODO PVE 10: Remove digest when HA groups have been fully migrated to rules
+ return wantarray ? ($conf, $res->{digest}) : $conf;
}
sub update_resources_config {
diff --git a/src/PVE/HA/Groups.pm b/src/PVE/HA/Groups.pm
index 821d969b..4bb943e5 100644
--- a/src/PVE/HA/Groups.pm
+++ b/src/PVE/HA/Groups.pm
@@ -107,4 +107,53 @@ sub parse_section_header {
__PACKAGE__->register();
__PACKAGE__->init();
+# Migrate nofailback flag from $groups to $resources
+sub migrate_groups_to_resources {
+ my ($groups, $resources) = @_;
+
+ for my $sid (keys %$resources) {
+ my $groupid = $resources->{$sid}->{group}
+ or next; # skip resources without groups
+
+ $resources->{$sid}->{failback} = int(!$groups->{ids}->{$groupid}->{nofailback});
+ }
+}
+
+# Migrate groups from groups from $groups and $resources to node affinity rules in $rules
+sub migrate_groups_to_rules {
+ my ($rules, $groups, $resources) = @_;
+
+ my $group_resources = {};
+
+ for my $sid (keys %$resources) {
+ my $groupid = $resources->{$sid}->{group}
+ or next; # skip resources without groups
+
+ $group_resources->{$groupid}->{$sid} = 1;
+ }
+
+ while (my ($group, $resources) = each %$group_resources) {
+ next if !$groups->{ids}->{$group}; # skip non-existant groups
+
+ my $nodes = {};
+ for my $entry (keys $groups->{ids}->{$group}->{nodes}->%*) {
+ my ($node, $priority) = PVE::HA::Tools::parse_node_priority($entry);
+
+ $nodes->{$node} = { priority => $priority };
+ }
+
+ my $new_ruleid = "ha-group-$group";
+ $rules->{ids}->{$new_ruleid} = {
+ type => 'node-affinity',
+ resources => $resources,
+ nodes => $nodes,
+ strict => $groups->{ids}->{$group}->{restricted},
+ comment => $groups->{ids}->{$group}->{comment},
+ };
+ $rules->{ids}->{$new_ruleid}->{comment} = "Generated from HA group '$group'."
+ if !$rules->{ids}->{$new_ruleid}->{comment};
+ $rules->{order}->{$new_ruleid} = PVE::HA::Rules::get_next_ordinal($rules);
+ }
+}
+
1;
diff --git a/src/PVE/HA/Manager.pm b/src/PVE/HA/Manager.pm
index 88ff4a65..148447d6 100644
--- a/src/PVE/HA/Manager.pm
+++ b/src/PVE/HA/Manager.pm
@@ -6,6 +6,7 @@ use warnings;
use Digest::MD5 qw(md5_base64);
use PVE::Tools;
+use PVE::HA::Groups;
use PVE::HA::Tools ':exit_codes';
use PVE::HA::NodeStatus;
use PVE::HA::Rules;
@@ -47,6 +48,8 @@ sub new {
haenv => $haenv,
crs => {},
last_rules_digest => '',
+ last_groups_digest => '',
+ last_services_digest => '',
}, $class;
my $old_ms = $haenv->read_manager_status();
@@ -529,7 +532,7 @@ sub manage {
$self->update_crs_scheduler_mode();
- my $sc = $haenv->read_service_config();
+ my ($sc, $services_digest) = $haenv->read_service_config();
$self->{groups} = $haenv->read_group_config(); # update
@@ -564,7 +567,16 @@ sub manage {
my $new_rules = $haenv->read_rules_config();
- if ($new_rules->{digest} ne $self->{last_rules_digest}) {
+ # TODO PVE 10: Remove group migration when HA groups have been fully migrated to rules
+ PVE::HA::Groups::migrate_groups_to_resources($self->{groups}, $sc);
+
+ if (
+ !$self->{rules}
+ || $new_rules->{digest} ne $self->{last_rules_digest}
+ || $self->{groups}->{digest} ne $self->{last_groups_digest}
+ || $services_digest && $services_digest ne $self->{last_services_digest}
+ ) {
+ PVE::HA::Groups::migrate_groups_to_rules($new_rules, $self->{groups}, $sc);
my $messages = PVE::HA::Rules->canonicalize($new_rules);
$haenv->log('info', $_) for @$messages;
@@ -572,6 +584,8 @@ sub manage {
$self->{rules} = $new_rules;
$self->{last_rules_digest} = $self->{rules}->{digest};
+ $self->{last_groups_digest} = $self->{groups}->{digest};
+ $self->{last_services_digest} = $services_digest;
}
$self->update_crm_commands();
--
2.47.2
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-07-30 18:01 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-30 17:59 [pve-devel] [PATCH docs/ha-manager/manager v5 00/29] HA Rules Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 01/23] tree-wide: make arguments for select_service_node explicit Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 02/23] manager: improve signature of select_service_node Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 03/23] introduce rules base plugin Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 04/23] rules: introduce node affinity rule plugin Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 05/23] config, env, hw: add rules read and parse methods Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 06/23] config: delete services from rules if services are deleted from config Daniel Kral
2025-07-31 4:59 ` Thomas Lamprecht
2025-07-31 8:15 ` Daniel Kral
2025-07-31 5:03 ` Thomas Lamprecht
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 07/23] manager: read and update rules config Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 08/23] test: ha tester: add test cases for future node affinity rules Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 09/23] resources: introduce failback property in ha resource config Daniel Kral
2025-07-30 17:59 ` Daniel Kral [this message]
2025-07-31 8:35 ` [pve-devel] [PATCH ha-manager v5 10/23] manager: migrate ha groups to node affinity rules in-memory Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 11/23] manager: apply node affinity rules when selecting service nodes Daniel Kral
2025-07-31 5:26 ` Thomas Lamprecht
2025-07-31 8:21 ` Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 12/23] test: add test cases for rules config Daniel Kral
2025-07-31 5:30 ` Thomas Lamprecht
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 13/23] api: introduce ha rules api endpoints Daniel Kral
2025-07-31 5:36 ` Thomas Lamprecht
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 14/23] cli: expose ha rules api endpoints to ha-manager cli Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 15/23] sim: do not create default groups config Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 16/23] test: ha tester: migrate groups to service and rules config Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 17/23] test: ha tester: replace any reference to groups with node affinity rules Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 18/23] env: add property delete for update_service_config Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 19/23] manager: persistently migrate ha groups to ha rules Daniel Kral
2025-07-30 17:59 ` [pve-devel] [RFC ha-manager v5 20/23] api: groups: disallow calls to ha groups endpoints if fully migrated Daniel Kral
2025-07-30 17:59 ` [pve-devel] [RFC ha-manager v5 21/23] api: resources: exclude group property in reading endpoints if migrated Daniel Kral
2025-07-30 17:59 ` [pve-devel] [RFC ha-manager v5 22/23] api: resources: disallow group prop in modifying " Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH ha-manager v5 23/23] api: rules: disallow modifying api calls if ha groups not migrated Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH docs v5 1/2] ha: add documentation about ha rules and ha node affinity rules Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH docs v5 2/2] ha: crs: add effects of ha node affinity rule on the crs scheduler Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH manager v5 1/4] api: ha: add ha rules api endpoints Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH manager v5 2/4] ui: ha: remove ha groups from ha resource components Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH manager v5 3/4] ui: ha: show failback flag in resources status view Daniel Kral
2025-07-30 17:59 ` [pve-devel] [PATCH manager v5 4/4] ui: ha: replace ha groups with ha node affinity rules Daniel Kral
2025-07-31 7:17 ` [pve-devel] partially-applied-series: [PATCH docs/ha-manager/manager v5 00/29] HA Rules Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250730175957.386674-11-d.kral@proxmox.com \
--to=d.kral@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox