From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pve-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 16AAD1FF16F for <inbox@lore.proxmox.com>; Tue, 29 Apr 2025 10:44:36 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5968E6FD7; Tue, 29 Apr 2025 10:44:47 +0200 (CEST) Message-ID: <b2d0aa33-b681-4e77-836b-d84546bd938d@proxmox.com> Date: Tue, 29 Apr 2025 10:44:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Fiona Ebner <f.ebner@proxmox.com>, Proxmox VE development discussion <pve-devel@lists.proxmox.com> References: <20250325151254.193177-1-d.kral@proxmox.com> <20250325151254.193177-7-d.kral@proxmox.com> <6f5df6e4-2f78-4562-bc77-9fe992f0d9a6@proxmox.com> Content-Language: en-US From: Daniel Kral <d.kral@proxmox.com> In-Reply-To: <6f5df6e4-2f78-4562-bc77-9fe992f0d9a6@proxmox.com> 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: Re: [pve-devel] [PATCH ha-manager 05/15] rules: add colocation rule plugin X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> On 4/25/25 16:05, Fiona Ebner wrote: > Not much to add to Fabian's review :) > > Am 25.03.25 um 16:12 schrieb Daniel Kral: >> diff --git a/src/PVE/HA/Rules/Colocation.pm b/src/PVE/HA/Rules/Colocation.pm >> new file mode 100644 >> index 0000000..808d48e >> --- /dev/null >> +++ b/src/PVE/HA/Rules/Colocation.pm >> @@ -0,0 +1,391 @@ >> +package PVE::HA::Rules::Colocation; >> + >> +use strict; >> +use warnings; >> + >> +use Data::Dumper; >> + >> +use PVE::JSONSchema qw(get_standard_option); > > Missing include of PVE::Tools. > > Nit: I'd put a blank here to separate modules from different packages > and modules from the same package. > >> +use PVE::HA::Tools; >> + >> +use base qw(PVE::HA::Rules); >> + >> +sub type { >> + return 'colocation'; >> +} >> + >> +sub properties { >> + return { >> + services => get_standard_option('pve-ha-resource-id-list'), >> + affinity => { >> + description => "Describes whether the services are supposed to be kept on separate" >> + . " nodes, or are supposed to be kept together on the same node.", >> + type => 'string', >> + enum => ['separate', 'together'], >> + optional => 0, >> + }, >> + strict => { >> + description => "Describes whether the colocation rule is mandatory or optional.", >> + type => 'boolean', >> + optional => 0, >> + }, >> + } > > Style nit: missing semicolon > > Since we should move the property definitions to the base module once a > second plugin re-uses them later: should we already declare 'services' > and 'strict' in the base module to start out? Then we could implement > the encode/decode part for 'services' there already. Less moving around > or duplication later on. Yes, especially as Fabian also agreed that it would make sense that users are allowed to make location rules for multiple services in a single rule. I'll start to use the isolated_properties option that @Dominik implemented so that other options can be separated and have plugin-specific descriptions, etc. but services can definitely live with a more general description. > >> +} >> + >> +sub options { >> + return { >> + services => { optional => 0 }, >> + strict => { optional => 0 }, >> + affinity => { optional => 0 }, >> + comment => { optional => 1 }, >> + }; >> +}; >> + >> +sub decode_value { >> + my ($class, $type, $key, $value) = @_; >> + >> + if ($key eq 'services') { >> + my $res = {}; >> + >> + for my $service (PVE::Tools::split_list($value)) { >> + if (PVE::HA::Tools::pve_verify_ha_resource_id($service)) { >> + $res->{$service} = 1; >> + } >> + } >> + >> + return $res; >> + } >> + >> + return $value; >> +} >> + >> +sub encode_value { >> + my ($class, $type, $key, $value) = @_; >> + >> + if ($key eq 'services') { >> + PVE::HA::Tools::pve_verify_ha_resource_id($_) for (keys %$value); > > Style nit: > [I] febner@dev8 /usr/share/perl5/PVE> ag "for keys" | wc -l > 28 > [I] febner@dev8 /usr/share/perl5/PVE> ag "for \(keys" | wc -l > 0 ACK, will change that :) > >> + >> + return join(',', keys %$value); >> + } >> + >> + return $value; >> +} >> + > > ---snip 8<--- > >> +=head3 check_service_count($rules) >> + >> +Returns a list of conflicts caused by colocation rules, which do not have >> +enough services in them, defined in C<$rules>. >> + >> +If there are no conflicts, the returned list is empty. >> + >> +=cut >> + >> +sub check_services_count { >> + my ($rules) = @_; >> + >> + my $conflicts = []; >> + >> + foreach_colocation_rule($rules, sub { >> + my ($rule, $ruleid) = @_; >> + >> + push @$conflicts, $ruleid if (scalar(keys %{$rule->{services}}) < 2); > > Style nit: parentheses for post-if > ACK, removed the outer parentheses _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel