From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 048741FF183 for ; Wed, 30 Jul 2025 20:13:34 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2968617DFD; Wed, 30 Jul 2025 20:14:37 +0200 (CEST) From: Daniel Kral To: pve-devel@lists.proxmox.com Date: Wed, 30 Jul 2025 20:14:09 +0200 Message-ID: <20250730181428.392906-6-d.kral@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250730181428.392906-1-d.kral@proxmox.com> References: <20250730181428.392906-1-d.kral@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1753899260827 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.014 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH ha-manager v5 05/14] rules: add global checks between node and resource affinity rules X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" 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 --- 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