feat!: Added command to serve config files over tftp

This is a breaking change as the return type of cluster.nodes has
changed, resulting in old templates potentially no longer working.
This commit is contained in:
2026-10-03 21:41:14 +02:00
parent ffeb39923e
commit 50c1b35de1
6 changed files with 102 additions and 18 deletions
+21 -11
View File
@@ -1,10 +1,10 @@
use std::collections::HashMap;
use std::net::Ipv4Addr;
use std::path::PathBuf;
use std::str::FromStr;
use async_walkdir::WalkDir;
use futures::StreamExt;
use futures::future::join_all;
use futures::stream::FuturesUnordered;
use minijinja::Environment;
use optional_struct::{Applicable, optional_struct};
@@ -77,7 +77,7 @@ struct ClusterDeserialize {
pub struct Cluster {
pub(crate) name: String,
pub(crate) version: Version,
nodes: Vec<Node>,
nodes: HashMap<String, Node>,
cluster_env: ClusterEnv,
pub(crate) control_plane_ip: Ipv4Addr,
pub(crate) secrets_file: PathBuf,
@@ -122,22 +122,23 @@ impl Cluster {
let cluster = Self {
name: cluster_name.into(),
version: cluster.version,
nodes: vec![],
nodes: Default::default(),
cluster_env: cluster.cluster_env,
control_plane_ip: cluster.control_plane_ip,
secrets_file,
};
let nodes = nodes
.iter()
.map(|name| async { Node::get(name, env, &cluster, &default, &base).await });
let nodes = nodes.iter().map(|name| async {
let node = Node::get(name, env, &cluster, &default, &base).await;
(node.hostname().to_owned(), node)
});
let nodes = FuturesUnordered::from_iter(nodes).collect().await;
Self { nodes, ..cluster }
}
pub async fn get_all() -> Vec<Cluster> {
pub async fn get_all() -> HashMap<String, Cluster> {
let env = PathEnvironment::new_patches();
let names: Vec<_> = WalkDir::new(get_talos_path().join("clusters"))
@@ -162,17 +163,26 @@ impl Cluster {
.await;
// Get the clusters concurrently
join_all(names.iter().map(|name| {
FuturesUnordered::from_iter(names.iter().map(|name| {
let env = env.clone();
let name = name.clone();
async move { Cluster::get(&name, &env).await }
async move {
let cluster = Cluster::get(&name, &env).await;
(name, cluster)
}
}))
.collect()
.await
}
pub fn nodes(&self) -> &[Node] {
&self.nodes
pub fn nodes(&self) -> impl Iterator<Item = &Node> {
self.nodes.values()
}
pub fn node(&self, node: &str) -> Option<&Node> {
self.nodes.get(node)
}
pub async fn talosconfig(&self) -> String {