[pve-devel] [PATCH ha-manager 1/2] fix #6613: update rules containing the resource to be deleted

Michael Köppl m.koeppl at proxmox.com
Wed Sep 17 13:53:10 CEST 2025


If the purge param is set, the resource that is deleted is also removed
from any rules referencing it. In the case that a resource is removed
that is also the last resource in a rule, the rule is also removed if
the purge option is enabled. This avoids rules remaining in the rules
config if their resources no longer exist.

Signed-off-by: Michael Köppl <m.koeppl at proxmox.com>
---
 src/PVE/HA/Config.pm | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/PVE/HA/Config.pm b/src/PVE/HA/Config.pm
index 301c62f..9a7ed0e 100644
--- a/src/PVE/HA/Config.pm
+++ b/src/PVE/HA/Config.pm
@@ -419,17 +419,30 @@ sub get_resource_motion_info {
 
 # graceful, as long as locking + cfs_write works
 sub delete_service_from_config {
-    my ($sid) = @_;
+    my ($sid, $purge) = @_;
 
     return 1 if !service_is_configured($sid);
 
     my $res;
     PVE::HA::Config::lock_ha_domain(
         sub {
+
             my $conf = read_resources_config();
             $res = delete $conf->{ids}->{$sid};
             write_resources_config($conf);
 
+            my $rules = read_rules_config();
+
+            if ($purge) {
+                for my $ruleid (keys $rules->{ids}->%*) {
+                    my $rule_resources = $rules->{ids}->{$ruleid}->{resources} // {};
+
+                    delete $rule_resources->{$sid};
+                    delete $rules->{ids}->{$ruleid} if !%$rule_resources;
+                }
+            }
+
+            write_rules_config($rules);
         },
         "delete resource failed",
     );
-- 
2.47.3





More information about the pve-devel mailing list