From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id B15B21FF186 for ; Fri, 1 Aug 2025 18:22:01 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 88EE91E4CC; Fri, 1 Aug 2025 18:23:08 +0200 (CEST) From: Daniel Kral To: pve-devel@lists.proxmox.com Date: Fri, 1 Aug 2025 18:22:24 +0200 Message-ID: <20250801162230.296214-10-d.kral@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250801162230.296214-1-d.kral@proxmox.com> References: <20250801162230.296214-1-d.kral@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1754065339980 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 v2 09/12] rules: allow same resources in 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" In preparation of the next patch, remove the overly restrictive checker, which disallows that resources are used in node affinity rules and resource affinity rules at the same time. Signed-off-by: Daniel Kral --- This could be squashed into the next, but I figured it's good measure for documentation to have its own patch. src/PVE/HA/Rules.pm | 70 ----------- .../multiple-resource-refs-in-rules.cfg | 52 -------- ...multiple-resource-refs-in-rules.cfg.expect | 111 ------------------ 3 files changed, 233 deletions(-) delete mode 100644 src/test/rules_cfgs/multiple-resource-refs-in-rules.cfg delete mode 100644 src/test/rules_cfgs/multiple-resource-refs-in-rules.cfg.expect diff --git a/src/PVE/HA/Rules.pm b/src/PVE/HA/Rules.pm index e2b77215..64dae1e4 100644 --- a/src/PVE/HA/Rules.pm +++ b/src/PVE/HA/Rules.pm @@ -475,74 +475,4 @@ 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/test/rules_cfgs/multiple-resource-refs-in-rules.cfg b/src/test/rules_cfgs/multiple-resource-refs-in-rules.cfg deleted file mode 100644 index 6608a5c3..00000000 --- a/src/test/rules_cfgs/multiple-resource-refs-in-rules.cfg +++ /dev/null @@ -1,52 +0,0 @@ -# Case 1: Do not remove node/resource affinity rules, which do not share resources between these types. -node-affinity: different-resource1 - resources vm:101,vm:102,vm:103 - nodes node1,node2:2 - strict 0 - -resource-affinity: different-resource2 - resources vm:104,vm:105 - affinity positive - -node-affinity: different-resource3 - resources vm:106 - nodes node1,node2:2 - strict 1 - -resource-affinity: different-resource4 - resources vm:107,vm:109 - affinity negative - -# Case 2: Remove rules, which share the same resource(s) between different rule types. -node-affinity: same-resource1 - resources vm:201 - nodes node1,node2:2 - strict 0 - -resource-affinity: same-resource2 - resources vm:201,vm:205 - affinity negative - -resource-affinity: same-resource3 - resources vm:201,vm:203,vm:204 - affinity negative - -node-affinity: same-resource4 - resources vm:205,vm:206,vm:207 - nodes node1:2,node3:3 - strict 1 - -# Case 3: Do not remove rules, which do not share resources between them. -node-affinity: other-different-resource1 - resources vm:301,vm:308 - nodes node1,node2:2 - strict 0 - -resource-affinity: other-different-resource2 - resources vm:302,vm:304,vm:305 - affinity positive - -node-affinity: other-different-resource3 - resources vm:303,vm:306,vm:309 - nodes node1,node2:2 - strict 1 diff --git a/src/test/rules_cfgs/multiple-resource-refs-in-rules.cfg.expect b/src/test/rules_cfgs/multiple-resource-refs-in-rules.cfg.expect deleted file mode 100644 index 972c042d..00000000 --- a/src/test/rules_cfgs/multiple-resource-refs-in-rules.cfg.expect +++ /dev/null @@ -1,111 +0,0 @@ ---- Log --- -Drop rule 'same-resource1', because resource 'vm:201' cannot be used in both a node affinity rule and a resource affinity rule at the same time. -Drop rule 'same-resource2', because resource 'vm:201' cannot be used in both a node affinity rule and a resource affinity rule at the same time. -Drop rule 'same-resource2', because resource 'vm:205' cannot be used in both a node affinity rule and a resource affinity rule at the same time. -Drop rule 'same-resource3', because resource 'vm:201' cannot be used in both a node affinity rule and a resource affinity rule at the same time. -Drop rule 'same-resource4', because resource 'vm:205' cannot be used in both a node affinity rule and a resource affinity rule at the same time. ---- Config --- -$VAR1 = { - 'digest' => 'fcbdf84d442d38b4c901d989c211fb62024c5515', - 'ids' => { - 'different-resource1' => { - 'nodes' => { - 'node1' => { - 'priority' => 0 - }, - 'node2' => { - 'priority' => 2 - } - }, - 'resources' => { - 'vm:101' => 1, - 'vm:102' => 1, - 'vm:103' => 1 - }, - 'strict' => 0, - 'type' => 'node-affinity' - }, - 'different-resource2' => { - 'affinity' => 'positive', - 'resources' => { - 'vm:104' => 1, - 'vm:105' => 1 - }, - 'type' => 'resource-affinity' - }, - 'different-resource3' => { - 'nodes' => { - 'node1' => { - 'priority' => 0 - }, - 'node2' => { - 'priority' => 2 - } - }, - 'resources' => { - 'vm:106' => 1 - }, - 'strict' => 1, - 'type' => 'node-affinity' - }, - 'different-resource4' => { - 'affinity' => 'negative', - 'resources' => { - 'vm:107' => 1, - 'vm:109' => 1 - }, - 'type' => 'resource-affinity' - }, - 'other-different-resource1' => { - 'nodes' => { - 'node1' => { - 'priority' => 0 - }, - 'node2' => { - 'priority' => 2 - } - }, - 'resources' => { - 'vm:301' => 1, - 'vm:308' => 1 - }, - 'strict' => 0, - 'type' => 'node-affinity' - }, - 'other-different-resource2' => { - 'affinity' => 'positive', - 'resources' => { - 'vm:302' => 1, - 'vm:304' => 1, - 'vm:305' => 1 - }, - 'type' => 'resource-affinity' - }, - 'other-different-resource3' => { - 'nodes' => { - 'node1' => { - 'priority' => 0 - }, - 'node2' => { - 'priority' => 2 - } - }, - 'resources' => { - 'vm:303' => 1, - 'vm:306' => 1, - 'vm:309' => 1 - }, - 'strict' => 1, - 'type' => 'node-affinity' - } - }, - 'order' => { - 'different-resource1' => 1, - 'different-resource2' => 2, - 'different-resource3' => 3, - 'different-resource4' => 4, - 'other-different-resource1' => 9, - 'other-different-resource2' => 10, - 'other-different-resource3' => 11 - } - }; -- 2.47.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel