From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id BABA41FF09F for ; Tue, 01 Dec 2026 16:15:43 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id D0B80216B9; Tue, 01 Dec 2026 16:15:36 +0100 (CET) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Subject: [PATCH datacenter-manager 1/4] server: remote mapping: remember whether a pve remote is a cluster Date: Tue, 1 Dec 2026 16:12:05 +0100 Message-ID: <20261201151531.3348382-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261201151531.3348382-1-d.csapak@proxmox.com> References: <20261201151531.3348382-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.242 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 2TC43GJHZD2R2K454SG5ZPVL2VX7QQRA X-Message-ID-Hash: 2TC43GJHZD2R2K454SG5ZPVL2VX7QQRA X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: so that we can tell standalone nodes and clusters apart without having to query the remote, e.g. for showing a fitting icon in the UI. The mapping task already queries '/cluster/status' of every endpoint, which only contains an entry of type 'cluster' when the node is part of one. The cluster ID can't be used for that, since standalone nodes report one too. Like the cluster ID, the info belongs to the old endpoints when they change, so reset it then. Signed-off-by: Dominik Csapak --- .../tasks/remote_node_mapping.rs | 47 ++++++++++++------- server/src/remote_cache/mod.rs | 33 +++++++++++-- 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/server/src/bin/proxmox-datacenter-api/tasks/remote_node_mapping.rs b/server/src/bin/proxmox-datacenter-api/tasks/remote_node_mapping.rs index 23422008..27749a04 100644 --- a/server/src/bin/proxmox-datacenter-api/tasks/remote_node_mapping.rs +++ b/server/src/bin/proxmox-datacenter-api/tasks/remote_node_mapping.rs @@ -167,9 +167,10 @@ impl CachingTask { } } - // The cluster ID belongs to the old endpoints until one of the new ones reports it. + // The cluster info belongs to the old endpoints until one of the new ones reports it. if changed { entry.cluster_id = None; + entry.cluster = None; } } @@ -227,12 +228,12 @@ impl CachingTask { if let Some(connection_state) = connection_state { cache.mark_host_reachable(&remote.id, &node.hostname, connection_state); } - if let Ok((node_name, cluster_id)) = query_result { - if node_name.is_some() { - cache.set_node_name(&remote.id, &node.hostname, node_name); + if let Ok(status) = query_result { + if status.node_name.is_some() { + cache.set_node_name(&remote.id, &node.hostname, status.node_name); } if let Some(entry) = cache.remotes.get_mut(&remote.id) { - entry.set_cluster_id(&node.hostname, cluster_id); + entry.set_cluster_info(&node.hostname, status.cluster_id, status.cluster); } } cache.save()?; @@ -242,27 +243,36 @@ impl CachingTask { } } -/// Calls `/cluster/status` directly on a specific node to find its name, which the status lacks if -/// it does not mark one node as the local one, and the ID of its cluster. -async fn query_node( - remote: &Remote, - hostname: &str, -) -> Result<(Option, Option), Error> { +/// What the `/cluster/status` of a node tells about it. +struct NodeClusterStatus { + /// The name of the node, which the status lacks if it does not mark one node as the local one. + node_name: Option, + cluster_id: Option, + cluster: bool, +} + +/// Calls `/cluster/status` directly on a specific node. +async fn query_node(remote: &Remote, hostname: &str) -> Result { log::trace!("querying node name {hostname:?} for remote {:?}", remote.id); let client = server::connection::make_pve_client_with_endpoint(remote, Some(hostname))?; let node_status_list = client.cluster_status().await?; let cluster_id = remote_cache::cluster_id(&node_status_list); - let name = node_status_list + let cluster = remote_cache::is_cluster(&node_status_list); + let node_name = node_status_list .into_iter() .find(|node| node.local == Some(true)) .map(|node| node.name); - if name.is_none() { + if node_name.is_none() { log::warn!( "the cluster status of remote '{}' node '{hostname}' names no local node", remote.id ); } - Ok((name, cluster_id)) + Ok(NodeClusterStatus { + node_name, + cluster_id, + cluster, + }) } #[cfg(test)] @@ -272,7 +282,7 @@ mod tests { use super::*; #[test] - fn changed_endpoints_drop_the_cluster_id() -> Result<(), Error> { + fn changed_endpoints_drop_the_cluster_info() -> Result<(), Error> { let remote = |hostname: &str| -> Result { let raw = format!("pve: pve-a\n\tauthid root@pam!pdm\n\tnodes {hostname}\n\ttoken -\n"); Ok(Remote::parse_section_config("remotes.cfg", &raw)? @@ -285,17 +295,20 @@ mod tests { let old = remote("x1.example")?; task.prune_remote_nodes(&mut cache, "pve-a", &old); let entry = cache.remotes.get_mut("pve-a").unwrap(); - entry.set_cluster_id("x1.example", Some("x".into())); + entry.set_cluster_info("x1.example", Some("x".into()), true); task.prune_remote_nodes(&mut cache, "pve-a", &old); assert_eq!(cache.cluster_id("pve-a"), Some("x")); + assert_eq!(cache.is_cluster("pve-a"), Some(true)); // Repointed to another cluster that does not answer: the old cluster is free to be added. task.prune_remote_nodes(&mut cache, "pve-a", &remote("y1.example")?); assert_eq!(cache.cluster_id("pve-a"), None); + assert_eq!(cache.is_cluster("pve-a"), None); // An answer of the old endpoint that arrives late does not count either. let entry = cache.remotes.get_mut("pve-a").unwrap(); - entry.set_cluster_id("x1.example", Some("x".into())); + entry.set_cluster_info("x1.example", Some("x".into()), true); assert_eq!(cache.cluster_id("pve-a"), None); + assert_eq!(cache.is_cluster("pve-a"), None); Ok(()) } diff --git a/server/src/remote_cache/mod.rs b/server/src/remote_cache/mod.rs index a532adc0..a78328ae 100644 --- a/server/src/remote_cache/mod.rs +++ b/server/src/remote_cache/mod.rs @@ -28,7 +28,7 @@ use proxmox_time::{epoch_i64, epoch_to_rfc2822}; use pdm_api_types::remotes::RemoteType; use pdm_config::ConfigVersionCache; -use pve_api_types::ClusterNodeStatus; +use pve_api_types::{ClusterNodeStatus, ClusterNodeStatusType}; mod back_off; use back_off::BackOffState; @@ -208,6 +208,11 @@ impl RemoteMappingCache { self.remotes.get(remote)?.cluster_id.as_deref() } + /// Whether a remote was a cluster when it answered last. + pub fn is_cluster(&self, remote: &str) -> Option { + self.remotes.get(remote)?.cluster + } + /// Attempt to retrieve the host name from a node name. pub fn node_name_to_hostname(&self, remote: &str, node_name: &str) -> Option<&str> { Some(self.remotes.get(remote)?.node_to_host.get(node_name)?) @@ -432,6 +437,14 @@ pub fn cluster_id(status: &[ClusterNodeStatus]) -> Option { status.iter().find_map(|entry| entry.cluster_id.clone()) } +/// Whether a `/cluster/status` of Proxmox VE is that of a cluster, a standalone node lists no +/// cluster entry. +pub fn is_cluster(status: &[ClusterNodeStatus]) -> bool { + status + .iter() + .any(|entry| entry.ty == ClusterNodeStatusType::Cluster) +} + /// If a remote is reachable or not pub enum ConnectionState { /// The host/remote/etc. is reachable @@ -455,6 +468,10 @@ pub struct RemoteMapping { /// The ID of the cluster, as last reported by an endpoint, see [`cluster_id`]. #[serde(default, skip_serializing_if = "Option::is_none")] pub cluster_id: Option, + + /// Whether the remote is a cluster, as last reported by an endpoint, see [`is_cluster`]. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub cluster: Option, } impl RemoteMapping { @@ -464,14 +481,17 @@ impl RemoteMapping { hosts: HashMap::new(), node_to_host: HashMap::new(), cluster_id: None, + cluster: None, } } - /// Update the cluster ID that a host reported, if the host exists (otherwise this does - /// nothing), so that the answer of an endpoint that was removed meanwhile does not count. - pub fn set_cluster_id(&mut self, hostname: &str, cluster_id: Option) { + /// Update the cluster ID and whether the remote is a cluster, as a host reported them, if the + /// host exists (otherwise this does nothing), so that the answer of an endpoint that was + /// removed meanwhile does not count. + pub fn set_cluster_info(&mut self, hostname: &str, cluster_id: Option, cluster: bool) { if self.hosts.contains_key(hostname) { self.cluster_id = cluster_id; + self.cluster = Some(cluster); } } @@ -569,7 +589,7 @@ mod tests { use super::*; #[test] - fn cluster_id_of_clusters_and_standalone_nodes() { + fn cluster_info_of_clusters_and_standalone_nodes() { let status = |entries| serde_json::from_value::>(entries).unwrap(); let cluster = status(json!([ @@ -581,6 +601,7 @@ mod tests { cluster_id(&cluster).as_deref(), Some("abcdefghij2345672345") ); + assert!(is_cluster(&cluster)); let standalone = status(json!([ { "type": "node", "id": "node/a", "name": "a", "cluster-id": "zyxwvutsrq7654327654" }, @@ -589,11 +610,13 @@ mod tests { cluster_id(&standalone).as_deref(), Some("zyxwvutsrq7654327654") ); + assert!(!is_cluster(&standalone)); let older = status(json!([ { "type": "cluster", "id": "cluster", "name": "dc1" }, { "type": "node", "id": "node/a", "name": "a", "local": 1 }, ])); assert_eq!(cluster_id(&older), None); + assert!(is_cluster(&older)); } } -- 2.47.3