feat: Generate talos configs

This commit is contained in:
2026-04-05 04:15:28 +02:00
parent 7a83a8a4be
commit 3c7a29261d
3 changed files with 144 additions and 7 deletions
+31 -1
View File
@@ -1,10 +1,12 @@
mod cli;
use std::process::Command;
use clap::{CommandFactory, Parser};
use clap_complete::{Shell, generate as generate_complete};
use crete::cluster::Cluster;
use crete::environment::PathEnvironment;
use crete::{get_repo_path, set_repo_path};
use crete::{get_configs_path, get_repo_path, set_repo_path};
use minijinja::context;
use thiserror::Error;
@@ -16,6 +18,16 @@ enum Error {
NoClustersFound,
}
fn run_command(mut command: Command) {
let output = command.output().unwrap();
if !output.stdout.is_empty() {
println!("{}", String::from_utf8_lossy(&output.stdout).trim_end());
}
if !output.stderr.is_empty() {
println!("{}", String::from_utf8_lossy(&output.stderr).trim_end());
}
}
fn generate(opts: &GlobalOpts) -> Result<(), Error> {
set_repo_path(&opts.repo);
@@ -46,6 +58,24 @@ fn generate(opts: &GlobalOpts) -> Result<(), Error> {
std::fs::write(path.join(template_name), content).unwrap();
}
// Remove existing config files and create output directory
let path = get_configs_path();
if path.exists() {
std::fs::remove_dir_all(&path).unwrap();
}
std::fs::create_dir(&path).unwrap();
// Generate config files
for cluster in clusters {
for node in cluster.nodes() {
run_command(node.talosctl_gen_config_command(&cluster));
}
run_command(cluster.talosctl_gen_config_command());
run_command(cluster.talosctl_add_endpoint_command());
run_command(cluster.talosctl_merge_command());
}
Ok(())
}