feat: Configs are captured in a string first

This commit is contained in:
2026-10-01 02:21:39 +02:00
parent f03c06fdf2
commit 1f268116de
4 changed files with 54 additions and 32 deletions
+21 -10
View File
@@ -15,7 +15,7 @@ use tokio::process::Command;
use crate::environment::PathEnvironment;
use crate::node::{Node, OptionalNodeDeserialize};
use crate::patch::Patches;
use crate::{get_configs_path, get_talos_path};
use crate::{get_configs_path, get_talos_path, run_command};
#[optional_struct]
#[derive(Debug, Deserialize, JsonSchema, Clone)]
@@ -174,9 +174,7 @@ impl Cluster {
&self.nodes
}
pub fn talosctl_gen_config_command(&self) -> Command {
let path = get_configs_path().join(&self.name).join("talosconfig");
pub async fn talosconfig(&self) -> String {
let mut command = Command::new("talosctl");
command.args([
"gen",
@@ -188,13 +186,13 @@ impl Cluster {
"--output-types",
"talosconfig",
"-o",
path.to_str().expect("Path should be valid utf-8"),
"-",
]);
command
run_command(command).await
}
pub fn talosctl_add_endpoint_command(&self) -> Command {
async fn talosconfig_add_endpoint(&self) {
let path = get_configs_path().join(&self.name).join("talosconfig");
let mut command = Command::new("talosctl");
@@ -206,10 +204,23 @@ impl Cluster {
&self.control_plane_ip.to_string(),
]);
command
run_command(command).await;
}
pub fn talosctl_merge_command(&self) -> Command {
pub async fn talosconfig_write(&self) {
let config = self.talosconfig().await;
let path = get_configs_path().join(&self.name).join("talosconfig");
tokio::fs::create_dir_all(path.parent().expect("talosconfig should have parent"))
.await
.unwrap();
tokio::fs::write(path, config).await.unwrap();
self.talosconfig_add_endpoint().await
}
pub async fn talosconfig_merge(&self) {
let cluster_path = get_configs_path().join(&self.name).join("talosconfig");
let path = get_configs_path().join("talosconfig");
@@ -222,7 +233,7 @@ impl Cluster {
cluster_path.to_str().expect("Path should be valid utf-8"),
]);
command
run_command(command).await;
}
}