refactor: Deduplicate paths
This commit is contained in:
+15
-9
@@ -15,6 +15,7 @@ use tokio::process::Command;
|
||||
use crate::environment::PathEnvironment;
|
||||
use crate::node::{Node, OptionalNodeDeserialize};
|
||||
use crate::patch::Patches;
|
||||
use crate::talosconfig::TalosConfig;
|
||||
use crate::{get_configs_path, get_talos_path, run_command};
|
||||
|
||||
#[optional_struct]
|
||||
@@ -192,14 +193,18 @@ impl Cluster {
|
||||
run_command(command).await
|
||||
}
|
||||
|
||||
async fn talosconfig_add_endpoint(&self) {
|
||||
let path = get_configs_path().join(&self.name).join("talosconfig");
|
||||
pub fn talosconfig_path(&self) -> PathBuf {
|
||||
get_configs_path().join(&self.name).join("talosconfig")
|
||||
}
|
||||
|
||||
async fn talosconfig_add_endpoint(&self) {
|
||||
let mut command = Command::new("talosctl");
|
||||
command.args([
|
||||
"config",
|
||||
"--talosconfig",
|
||||
path.to_str().expect("Path should be valid utf-8"),
|
||||
self.talosconfig_path()
|
||||
.to_str()
|
||||
.expect("Path should be valid utf-8"),
|
||||
"endpoint",
|
||||
&self.control_plane_ip.to_string(),
|
||||
]);
|
||||
@@ -210,7 +215,7 @@ impl Cluster {
|
||||
pub async fn talosconfig_write(&self) {
|
||||
let config = self.talosconfig().await;
|
||||
|
||||
let path = get_configs_path().join(&self.name).join("talosconfig");
|
||||
let path = self.talosconfig_path();
|
||||
tokio::fs::create_dir_all(path.parent().expect("talosconfig should have parent"))
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -221,16 +226,17 @@ impl Cluster {
|
||||
}
|
||||
|
||||
pub async fn talosconfig_merge(&self) {
|
||||
let path = get_configs_path().join("talosconfig");
|
||||
let cluster_path = get_configs_path().join(&self.name).join("talosconfig");
|
||||
|
||||
let mut command = Command::new("talosctl");
|
||||
command.args([
|
||||
"config",
|
||||
"--talosconfig",
|
||||
path.to_str().expect("Path should be valid utf-8"),
|
||||
TalosConfig::merged_path()
|
||||
.to_str()
|
||||
.expect("Path should be valid utf-8"),
|
||||
"merge",
|
||||
cluster_path.to_str().expect("Path should be valid utf-8"),
|
||||
self.talosconfig_path()
|
||||
.to_str()
|
||||
.expect("Path should be valid utf-8"),
|
||||
]);
|
||||
|
||||
run_command(command).await;
|
||||
|
||||
Reference in New Issue
Block a user