all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Daniel Kral <d.kral@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH ha-manager v2 09/12] rules: allow same resources in node and resource affinity rules
Date: Fri,  1 Aug 2025 18:22:24 +0200	[thread overview]
Message-ID: <20250801162230.296214-10-d.kral@proxmox.com> (raw)
In-Reply-To: <20250801162230.296214-1-d.kral@proxmox.com>

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 <d.kral@proxmox.com>
---
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


  parent reply	other threads:[~2025-08-01 16:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-01 16:22 [pve-devel] [PATCH ha-manager v2 00/12] HA rules follow up (part 1) Daniel Kral
2025-08-01 16:22 ` [pve-devel] [PATCH ha-manager v2 01/12] manager: fix ~revision version check for ha groups migration Daniel Kral
2025-08-01 16:22 ` [pve-devel] [PATCH ha-manager v2 02/12] test: ha tester: add ha groups migration tests with runtime upgrades Daniel Kral
2025-08-01 16:22 ` [pve-devel] [PATCH ha-manager v2 03/12] tree-wide: pass optional parameters as hash values for for_each_rule helper Daniel Kral
2025-08-01 16:22 ` [pve-devel] [PATCH ha-manager v2 04/12] api: rules: add missing return schema for the read_rule api endpoint Daniel Kral
2025-08-01 16:22 ` [pve-devel] [PATCH ha-manager v2 05/12] api: rules: ignore disable parameter if it is set to a falsy value Daniel Kral
2025-08-01 16:22 ` [pve-devel] [PATCH ha-manager v2 06/12] rules: resource affinity: make message in inter-consistency check clearer Daniel Kral
2025-08-01 16:22 ` [pve-devel] [PATCH ha-manager v2 07/12] config, manager: do not check ignored resources with affinity when migrating Daniel Kral
2025-08-01 16:22 ` [pve-devel] [PATCH ha-manager v2 08/12] rules: make positive affinity resources migrate on single resource fail Daniel Kral
2025-08-01 16:22 ` Daniel Kral [this message]
2025-08-01 16:22 ` [pve-devel] [PATCH ha-manager v2 10/12] rules: restrict inter-plugin resource references to simple cases Daniel Kral
2025-08-01 16:22 ` [pve-devel] [PATCH ha-manager v2 11/12] test: rules: add test cases for inter-plugin checks allowing simple use cases Daniel Kral
2025-08-01 16:22 ` [pve-devel] [PATCH ha-manager v2 12/12] test: ha tester: add resource affinity test cases mixed with node affinity rules Daniel Kral
2025-08-01 17:36 ` [pve-devel] applied: [PATCH ha-manager v2 00/12] HA rules follow up (part 1) 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=20250801162230.296214-10-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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal