refactor: Big internal refactor

This commit is contained in:
2026-04-01 06:18:57 +02:00
parent a7578a6b16
commit 7a83a8a4be
11 changed files with 240 additions and 201 deletions
+17 -23
View File
@@ -6,7 +6,7 @@ use std::str::FromStr;
use minijinja::{AutoEscape, Environment, path_loader};
use walkdir::WalkDir;
use crate::{get_repo_path, get_talos_config_path};
use crate::{get_configs_path, get_talos_path};
/// Transparent wrapper around minijinja::Environment that loads templates from a path and
/// configures better defaults. It also implements IntoIter, making it possible to iterate over all
@@ -44,6 +44,20 @@ impl<'a> PathEnvironment<'a> {
}
});
// Helper function for getting the path to kubeconfig files
env.add_filter("kubeconfig", move |names: Vec<String>| {
names
.iter()
.map(|name| {
get_configs_path()
.join(name)
.join("kubeconfig")
.to_string_lossy()
.to_string()
})
.collect::<Vec<_>>()
});
// Add path loader
env.set_loader(path_loader(&path));
@@ -53,28 +67,8 @@ impl<'a> PathEnvironment<'a> {
}
}
pub fn new_patches() -> Self {
Self::new(&get_talos_config_path().join("patches"))
}
pub fn new_templates(repo: &Path) -> Self {
let mut env = Self::new(&get_repo_path().join("templates"));
let path = repo.absolute().unwrap();
env.env.add_filter("kubeconfig", move |names: Vec<String>| {
names
.iter()
.map(|name| {
path.join("configs")
.join(name)
.join("kubeconfig")
.to_string_lossy()
.to_string()
})
.collect::<Vec<_>>()
});
env
pub(crate) fn new_patches() -> Self {
Self::new(&get_talos_path().join("patches"))
}
}