From: Daniel Kral <d.kral@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH ha-manager v5 05/14] rules: add global checks between node and resource affinity rules
Date: Wed, 30 Jul 2025 20:14:09 +0200 [thread overview]
Message-ID: <20250730181428.392906-6-d.kral@proxmox.com> (raw)
In-Reply-To: <20250730181428.392906-1-d.kral@proxmox.com>
Add checks, which determine infeasible resource affinity rules, because
their resources are already restricted by their node affinity rules in
such a way, that these cannot be satisfied or are reasonable to be
proven to be satisfiable.
Node affinity rules restrict resources to certain nodes by their nature,
but resources in positive resource affinity rule need to have at least
one common node to be feasible and resources in negative resource
affinity rule need to have at least the amount of nodes available that
nodes are restricted to in total.
Since node affinity rules allow nodes to be put in priority groups, but
the information which priority group is relevant depends on the online
nodes, these checks currently prohibit resource affinity rules with
resources, which make use of these kinds of node affinity rules.
Even though node affinity rules are restricted to only allow a resource
to be used in a single node affinity rule, the checks here still go over
all node affinity rules, as this restriction is bound to be changed in
the future.
Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
src/PVE/HA/Rules.pm | 71 ++++++++++++++++++++++++++++
src/PVE/HA/Rules/ResourceAffinity.pm | 3 +-
2 files changed, 73 insertions(+), 1 deletion(-)
diff --git a/src/PVE/HA/Rules.pm b/src/PVE/HA/Rules.pm
index 3121424c..75dbeecf 100644
--- a/src/PVE/HA/Rules.pm
+++ b/src/PVE/HA/Rules.pm
@@ -6,6 +6,7 @@ use warnings;
use PVE::JSONSchema qw(get_standard_option);
use PVE::Tools;
+use PVE::HA::HashTools qw(set_intersect set_union sets_are_disjoint);
use PVE::HA::Tools;
use base qw(PVE::SectionConfig);
@@ -476,4 +477,74 @@ sub get_next_ordinal : prototype($) {
return $current_order + 1;
}
+=head1 INTER-PLUGIN RULE CHECKERS
+
+=cut
+
+=head3 check_single_global_resource_reference($node_affinity_rules, $resource_affinity_rules)
+
+Returns all rules in C<$node_affinity_rules> and C<$resource_affinity_rules> as
+a list of lists, each consisting of the rule id and the resource id, where one
+of the resources is used in both a node affinity rule and resource affinity rule
+at the same time.
+
+If there are none, the returned list is empty.
+
+=cut
+
+sub check_single_global_resource_reference {
+ my ($node_affinity_rules, $resource_affinity_rules) = @_;
+
+ my @conflicts = ();
+ my $resource_ruleids = {};
+
+ while (my ($ruleid, $rule) = each %$node_affinity_rules) {
+ for my $sid (keys $rule->{resources}->%*) {
+ push $resource_ruleids->{$sid}->{node_affinity}->@*, $ruleid;
+ }
+ }
+ while (my ($ruleid, $rule) = each %$resource_affinity_rules) {
+ for my $sid (keys $rule->{resources}->%*) {
+ push $resource_ruleids->{$sid}->{resource_affinity}->@*, $ruleid;
+ }
+ }
+
+ for my $sid (keys %$resource_ruleids) {
+ my $node_affinity_ruleids = $resource_ruleids->{$sid}->{node_affinity} // [];
+ my $resource_affinity_ruleids = $resource_ruleids->{$sid}->{resource_affinity} // [];
+
+ next if @$node_affinity_ruleids > 0 && !@$resource_affinity_ruleids;
+ next if @$resource_affinity_ruleids > 0 && !@$node_affinity_ruleids;
+
+ for my $ruleid (@$node_affinity_ruleids, @$resource_affinity_ruleids) {
+ push @conflicts, [$ruleid, $sid];
+ }
+ }
+
+ @conflicts = sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @conflicts;
+ return \@conflicts;
+}
+
+__PACKAGE__->register_check(
+ sub {
+ my ($args) = @_;
+
+ return check_single_global_resource_reference(
+ $args->{node_affinity_rules},
+ $args->{resource_affinity_rules},
+ );
+ },
+ sub {
+ my ($conflicts, $errors) = @_;
+
+ for my $conflict (@$conflicts) {
+ my ($ruleid, $sid) = @$conflict;
+
+ push $errors->{$ruleid}->{resources}->@*,
+ "resource '$sid' cannot be used in both a node affinity rule"
+ . " and a resource affinity rule at the same time";
+ }
+ },
+);
+
1;
diff --git a/src/PVE/HA/Rules/ResourceAffinity.pm b/src/PVE/HA/Rules/ResourceAffinity.pm
index 8fc640f4..6415c9d7 100644
--- a/src/PVE/HA/Rules/ResourceAffinity.pm
+++ b/src/PVE/HA/Rules/ResourceAffinity.pm
@@ -167,7 +167,8 @@ __PACKAGE__->register_check(
my ($args) = @_;
return check_negative_resource_affinity_resources_count(
- $args->{negative_rules}, $args->{nodes},
+ $args->{negative_rules},
+ $args->{nodes},
);
},
sub {
--
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:13 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-30 18:14 [pve-devel] [PATCH container/docs/ha-manager/manager/qemu-server v5 00/20] HA " Daniel Kral
2025-07-30 18:14 ` [pve-devel] [PATCH ha-manager v5 01/14] introduce PVE::HA::HashTools module Daniel Kral
2025-07-30 18:14 ` [pve-devel] [PATCH ha-manager v5 02/14] rules: introduce plugin-specific canonicalize routines Daniel Kral
2025-07-30 18:14 ` [pve-devel] [PATCH ha-manager v5 03/14] rules: add haenv node list to the rules' canonicalization stage Daniel Kral
2025-07-30 18:14 ` [pve-devel] [PATCH ha-manager v5 04/14] rules: introduce resource affinity rule plugin Daniel Kral
2025-07-30 18:14 ` Daniel Kral [this message]
2025-07-30 18:14 ` [pve-devel] [PATCH ha-manager v5 06/14] usage: add information about a service's assigned nodes Daniel Kral
2025-07-30 18:14 ` [pve-devel] [PATCH ha-manager v5 07/14] manager: apply resource affinity rules when selecting service nodes Daniel Kral
2025-07-30 18:14 ` [pve-devel] [PATCH ha-manager v5 08/14] manager: handle resource affinity rules in manual migrations Daniel Kral
2025-07-30 18:14 ` [pve-devel] [PATCH ha-manager v5 09/14] sim: resources: add option to limit start and migrate tries to node Daniel Kral
2025-07-30 18:14 ` [pve-devel] [PATCH ha-manager v5 10/14] test: ha tester: add test cases for negative resource affinity rules Daniel Kral
2025-07-30 18:14 ` [pve-devel] [PATCH ha-manager v5 11/14] test: ha tester: add test cases for positive " Daniel Kral
2025-07-30 18:14 ` [pve-devel] [PATCH ha-manager v5 12/14] test: ha tester: add test cases for static scheduler resource affinity Daniel Kral
2025-07-30 18:14 ` [pve-devel] [PATCH ha-manager v5 13/14] test: rules: add test cases for resource affinity rules Daniel Kral
2025-07-30 18:14 ` [pve-devel] [PATCH ha-manager v5 14/14] api: resources: add check for resource affinity in resource migrations Daniel Kral
2025-07-30 18:14 ` [pve-devel] [PATCH docs v5 1/1] ha: add documentation about ha resource affinity rules Daniel Kral
2025-08-04 13:00 ` Hannes Duerr
2025-07-30 18:14 ` [pve-devel] [PATCH manager v5 1/3] ui: ha: rules: add " Daniel Kral
2025-07-30 18:14 ` [pve-devel] [PATCH manager v5 2/3] ui: migrate: lxc: display precondition messages for ha resource affinity Daniel Kral
2025-07-30 18:14 ` [pve-devel] [PATCH manager v5 3/3] ui: migrate: vm: " Daniel Kral
2025-07-30 18:14 ` [pve-devel] [PATCH container v5 1/1] api: introduce migration preconditions api endpoint Daniel Kral
2025-07-30 18:14 ` [pve-devel] [PATCH qemu-server v5 1/1] api: migration preconditions: add checks for ha resource affinity rules Daniel Kral
2025-08-04 9:50 ` [pve-devel] applied-series: [PATCH container/docs/ha-manager/manager/qemu-server v5 00/20] HA " Fiona Ebner
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=20250730181428.392906-6-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.