[pve-devel] [PATCH ha-manager v5 10/23] manager: migrate ha groups to node affinity rules in-memory

Daniel Kral d.kral at proxmox.com
Thu Jul 31 10:35:52 CEST 2025


On Wed Jul 30, 2025 at 7:59 PM CEST, Daniel Kral wrote:
> 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) = @_;

FWIW, this will also only migrate those HA groups which are referenced
in a HA resource config and will not migrate any "empty" HA groups,
which are not referenced by any HA resource.

I did this as it was only relevant for migrating the HA groups to HA
rules in-memory at the time. I'll send a follow-up patch which will at
least log that (something like 'do not migrate group xxx as it has no
group members' in the HA Manager's log and maybe also the pve8to9
script). We could also die here (only for the persistent migration) if
there's a HA group, which is not referenced by anyone, but that could be
too much..

> +
> +    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;




More information about the pve-devel mailing list