feat: Include boot.ipxe script

This commit is contained in:
2026-10-20 02:59:13 +02:00
parent 620f36d0bb
commit 8149ffbc37
6 changed files with 107 additions and 43 deletions
+25 -2
View File
@@ -1,9 +1,14 @@
use crete::cluster::Cluster;
use crete::environment::configure_environment;
use ipxe::IPXE_DIR;
use minijinja::{Environment, context};
use regex::Regex;
// TODO: Make this a proper async function
pub fn get_file(filename: impl ToString) -> impl Future<Output = Option<(Vec<u8>, &'static str)>> {
pub fn get_file(
filename: impl ToString,
http_url: impl ToString,
) -> impl Future<Output = Option<(Vec<u8>, &'static str)>> {
// TODO: Make this a static that is initialized once
let re =
Regex::new(r"^talos/(?<cluster>.+)/(?<node>.+)\.ya?ml$").expect("regex should be valid");
@@ -13,7 +18,25 @@ pub fn get_file(filename: impl ToString) -> impl Future<Output = Option<(Vec<u8>
async move {
const IPXE_PATTERN: &str = "ipxe/";
if let Some(filename) = filename.strip_prefix(IPXE_PATTERN) {
if filename == format!("{IPXE_PATTERN}boot.ipxe") {
let mut env = Environment::new();
configure_environment(&mut env);
let template = env
.template_from_str(include_str!("./boot.ipxe"))
.expect("Template should be valid");
let clusters = Cluster::get_all().await;
let content = template
.render(context! {
clusters => clusters.values().collect::<Vec<_>>(),
httpUrl => http_url.to_string()
})
.unwrap();
Some((content.into(), "text/plain; charset=utf-8"))
} else if let Some(filename) = filename.strip_prefix(IPXE_PATTERN) {
Some((
IPXE_DIR.get_file(filename)?.contents().to_owned(),
"application/octet-stream",