feat: Generate talos configs
This commit is contained in:
+46
-1
@@ -1,4 +1,5 @@
|
||||
use std::net::Ipv4Addr;
|
||||
use std::process::Command;
|
||||
|
||||
use minijinja::Environment;
|
||||
use optional_struct::{Applicable, optional_struct};
|
||||
@@ -6,10 +7,10 @@ use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::cluster::{Base, Cluster};
|
||||
use crate::get_talos_path;
|
||||
use crate::patch::{OptionalPatches, OptionalPatchesString, Patches};
|
||||
use crate::schematic::Schematic;
|
||||
use crate::secret::Secret;
|
||||
use crate::{get_configs_path, get_talos_path};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone, Copy, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -167,6 +168,50 @@ impl Node {
|
||||
|
||||
Node { patches, ..node }
|
||||
}
|
||||
|
||||
pub fn talosctl_gen_config_command(&self, cluster: &Cluster) -> Command {
|
||||
let mut path = get_configs_path().join(&cluster.name).join(&self.hostname);
|
||||
path.add_extension("yaml");
|
||||
|
||||
let mut command = Command::new("talosctl");
|
||||
command.args([
|
||||
"gen",
|
||||
"config",
|
||||
&cluster.name,
|
||||
&format!("https://{}:6443", cluster.control_plane_ip),
|
||||
"--with-secrets",
|
||||
cluster.secrets_file.to_str().expect("Path should be valid"),
|
||||
"--talos-version",
|
||||
&cluster.version.talos(),
|
||||
"--kubernetes-version",
|
||||
&cluster.version.kubernetes(),
|
||||
"--output-types",
|
||||
self.r#type.into(),
|
||||
"--install-image",
|
||||
&format!(
|
||||
"factory.talos.dev/metal-installer/{}:{}",
|
||||
self.schematic,
|
||||
cluster.version.talos()
|
||||
),
|
||||
"--with-docs=false",
|
||||
"--with-examples=false",
|
||||
"-o",
|
||||
path.to_str().expect("Path should be valid utf-8"),
|
||||
]);
|
||||
|
||||
for patch in &self.patches.all {
|
||||
command.args(["--config-patch", &serde_json::to_string(&patch).unwrap()]);
|
||||
}
|
||||
|
||||
for patch in &self.patches.control_plane {
|
||||
command.args([
|
||||
"--config-patch-control-plane",
|
||||
&serde_json::to_string(&patch).unwrap(),
|
||||
]);
|
||||
}
|
||||
|
||||
command
|
||||
}
|
||||
}
|
||||
|
||||
impl JsonSchema for Node {
|
||||
|
||||
Reference in New Issue
Block a user