On Wed Sep 17, 2025 at 1:53 PM CEST, Michael Köppl wrote:
> 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 <[email protected]>
> ---
> 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();
The {read,write}_rules_config(...) should be included in the
if ($purge) {} block here
> +
> + 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",
> );
_______________________________________________
pve-devel mailing list
[email protected]
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel