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 v5 03/14] rules: add haenv node list to the rules' canonicalization stage
Date: Wed, 30 Jul 2025 20:14:07 +0200	[thread overview]
Message-ID: <20250730181428.392906-4-d.kral@proxmox.com> (raw)
In-Reply-To: <20250730181428.392906-1-d.kral@proxmox.com>

Add the HA environment's node list information to the feasibility
check/canonicalization stage, which is needed for at least one rule
check for negative resource affinity rules in an upcoming patch, which
verifies that there are enough available nodes to separate the HA
resources on.

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
 src/PVE/API2/HA/Rules.pm      |  5 ++++-
 src/PVE/HA/Manager.pm         |  3 ++-
 src/PVE/HA/Rules.pm           | 20 +++++++++++++-------
 src/test/test_rules_config.pl |  4 +++-
 4 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/src/PVE/API2/HA/Rules.pm b/src/PVE/API2/HA/Rules.pm
index 881f36f6..1591df28 100644
--- a/src/PVE/API2/HA/Rules.pm
+++ b/src/PVE/API2/HA/Rules.pm
@@ -98,7 +98,10 @@ my $check_feasibility = sub {
 
     $rules = $get_full_rules_config->($rules);
 
-    return PVE::HA::Rules->check_feasibility($rules);
+    my $manager_status = PVE::HA::Config::read_manager_status();
+    my $nodes = [keys $manager_status->{node_status}->%*];
+
+    return PVE::HA::Rules->check_feasibility($rules, $nodes);
 };
 
 my $assert_feasibility = sub {
diff --git a/src/PVE/HA/Manager.pm b/src/PVE/HA/Manager.pm
index 374700cf..272bbe3a 100644
--- a/src/PVE/HA/Manager.pm
+++ b/src/PVE/HA/Manager.pm
@@ -683,7 +683,8 @@ sub manage {
     ) {
         PVE::HA::Groups::migrate_groups_to_rules($new_rules, $self->{groups}, $sc);
 
-        my $messages = PVE::HA::Rules->canonicalize($new_rules);
+        my $nodes = $self->{ns}->list_nodes();
+        my $messages = PVE::HA::Rules->canonicalize($new_rules, $nodes);
         $haenv->log('info', $_) for @$messages;
 
         $self->{rules} = $new_rules;
diff --git a/src/PVE/HA/Rules.pm b/src/PVE/HA/Rules.pm
index 39c349d5..3121424c 100644
--- a/src/PVE/HA/Rules.pm
+++ b/src/PVE/HA/Rules.pm
@@ -322,26 +322,30 @@ sub get_check_arguments : prototype($$) {
     return $global_args;
 }
 
-=head3 $class->check_feasibility($rules)
+=head3 $class->check_feasibility($rules, $nodes)
 
 Checks whether the given C<$rules> are feasible by running all checks, which
 were registered with C<L<< register_check()|/$class->register_check(...) >>>,
 and returns a hash map of errorneous rules.
 
+C<$nodes> is a list of the configured cluster nodes.
+
 The checks are run in the order in which the rule plugins were registered,
 while global checks, i.e. checks between different rule types, are run at the
 very last.
 
 =cut
 
-sub check_feasibility : prototype($$) {
-    my ($class, $rules) = @_;
+sub check_feasibility : prototype($$$) {
+    my ($class, $rules, $nodes) = @_;
 
     my $global_errors = {};
     my $removable_ruleids = [];
 
     my $global_args = $class->get_check_arguments($rules);
 
+    $global_args->{nodes} = $nodes;
+
     for my $type (@$types, 'global') {
         for my $entry (@{ $checkdef->{$type} }) {
             my ($check, $collect_errors) = @$entry;
@@ -366,10 +370,12 @@ sub plugin_canonicalize : prototype($$) {
     my ($class, $rules) = @_;
 }
 
-=head3 $class->canonicalize($rules)
+=head3 $class->canonicalize($rules, $nodes)
 
 Modifies C<$rules> to contain only feasible rules.
 
+C<$nodes> is a list of the configured cluster nodes.
+
 This is done by running all checks, which were registered with
 C<L<< register_check()|/$class->register_check(...) >>> and removing any
 rule, which makes the rule set infeasible.
@@ -378,11 +384,11 @@ Returns a list of messages with the reasons why rules were removed.
 
 =cut
 
-sub canonicalize : prototype($$) {
-    my ($class, $rules) = @_;
+sub canonicalize : prototype($$$) {
+    my ($class, $rules, $nodes) = @_;
 
     my $messages = [];
-    my $global_errors = $class->check_feasibility($rules);
+    my $global_errors = $class->check_feasibility($rules, $nodes);
 
     for my $ruleid (keys %$global_errors) {
         delete $rules->{ids}->{$ruleid};
diff --git a/src/test/test_rules_config.pl b/src/test/test_rules_config.pl
index 824afed1..d49d14f1 100755
--- a/src/test/test_rules_config.pl
+++ b/src/test/test_rules_config.pl
@@ -42,6 +42,8 @@ sub check_cfg {
 
     my $raw = PVE::Tools::file_get_contents($cfg_fn);
 
+    my $nodes = ['node1', 'node2', 'node3'];
+
     open(my $LOG, '>', "$outfile");
     select($LOG);
     $| = 1;
@@ -49,7 +51,7 @@ sub check_cfg {
     print "--- Log ---\n";
     my $cfg = PVE::HA::Rules->parse_config($cfg_fn, $raw);
     PVE::HA::Rules->set_rule_defaults($_) for values %{ $cfg->{ids} };
-    my $messages = PVE::HA::Rules->canonicalize($cfg);
+    my $messages = PVE::HA::Rules->canonicalize($cfg, $nodes);
     print $_ for @$messages;
     print "--- Config ---\n";
     {
-- 
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-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 resource affinity rules 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 ` Daniel Kral [this message]
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 ` [pve-devel] [PATCH ha-manager v5 05/14] rules: add global checks between node and resource affinity rules Daniel Kral
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-4-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