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 1B03C1FF17A for ; Fri, 4 Jul 2025 20:21:43 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 925373DBBE; Fri, 4 Jul 2025 20:21:40 +0200 (CEST) From: Daniel Kral To: pve-devel@lists.proxmox.com Date: Fri, 4 Jul 2025 20:20:45 +0200 Message-Id: <20250704182102.467624-3-d.kral@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250704182102.467624-1-d.kral@proxmox.com> References: <20250704182102.467624-1-d.kral@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.012 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 v3 02/13] rules: add haenv node list to the rules' canonicalization stage 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 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 --- 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 2e5e382..51e264f 100644 --- a/src/PVE/API2/HA/Rules.pm +++ b/src/PVE/API2/HA/Rules.pm @@ -101,7 +101,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 b2fd896..4bf74d2 100644 --- a/src/PVE/HA/Manager.pm +++ b/src/PVE/HA/Manager.pm @@ -621,7 +621,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 39c349d..3121424 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 Cregister_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 Cregister_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 824afed..d49d14f 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.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel