[pve-devel] [PATCH ha-manager v2 22/26] config: prune services from rules if services are deleted from config

Daniel Kral d.kral at proxmox.com
Fri Jun 20 16:31:34 CEST 2025


Remove services from rules, where these services are used, if they are
removed by delete_service_from_config(...), which is called by the
services' delete API endpoint and possibly external callers, e.g. if the
service is removed externally.

If all of the rules' services have been removed, the rule itself must be
removed as it would result in an erroneous rules config, which would
become user-visible at the next read and parse of the rules config.

Signed-off-by: Daniel Kral <d.kral at proxmox.com>
---
changes since v1:
    - NEW!

 src/PVE/HA/Config.pm | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/PVE/HA/Config.pm b/src/PVE/HA/Config.pm
index 2b3d726..3442d31 100644
--- a/src/PVE/HA/Config.pm
+++ b/src/PVE/HA/Config.pm
@@ -362,6 +362,25 @@ sub delete_service_from_config {
         "delete resource failed",
     );
 
+    PVE::HA::Config::lock_ha_domain(
+        sub {
+            my $rules = read_rules_config();
+
+            return if !defined($rules->{ids});
+
+            for my $ruleid (keys %{ $rules->{ids} }) {
+                my $rule_services = $rules->{ids}->{$ruleid}->{services} // {};
+
+                delete $rule_services->{$sid};
+
+                delete $rules->{ids}->{$ruleid} if !%$rule_services;
+            }
+
+            write_rules_config($rules);
+        },
+        "delete resource from rules failed",
+    );
+
     return !!$res;
 }
 
-- 
2.39.5





More information about the pve-devel mailing list