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
+29 -30
View File
@@ -6,46 +6,40 @@ use serde::{Deserialize, Serialize};
use crate::cluster::Cluster;
use crate::node::Node;
#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub(crate) enum Patch {
Name(String),
#[serde(skip_deserializing)]
#[schemars(with = "serde_json::Value")]
Resolved(serde_yaml::Value),
}
#[optional_struct]
#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Patches {
pub(crate) all: Vec<Patch>,
pub(crate) control_plane: Vec<Patch>,
pub(crate) struct Patches<T> {
pub(crate) all: Vec<T>,
pub(crate) control_plane: Vec<T>,
}
fn render(patches: Vec<Patch>, env: &Environment, cluster: &Cluster, node: &Node) -> Vec<Patch> {
pub(crate) type OptionalPatchesString = OptionalPatches<String>;
fn render(
patches: Vec<String>,
env: &Environment,
cluster: &Cluster,
node: &Node,
) -> Vec<serde_yaml::Value> {
patches
.into_iter()
.map(|patch| {
if let Patch::Name(name) = patch {
let content = env
.get_template(&name)
.unwrap()
.render(context! {
node,
cluster
})
.unwrap();
.map(|name| {
let content = env
.get_template(&name)
.unwrap()
.render(context! {
node,
cluster
})
.unwrap();
Patch::Resolved(serde_yaml::from_str(&content).unwrap())
} else {
patch
}
serde_yaml::from_str(&content).unwrap()
})
.collect()
}
impl Patches {
impl Patches<String> {
pub(crate) fn extend(mut self, other: Self) -> Self {
self.all.extend(other.all);
self.control_plane.extend(other.control_plane);
@@ -56,8 +50,13 @@ impl Patches {
}
}
pub(crate) fn render(self, env: &Environment, cluster: &Cluster, node: &Node) -> Self {
Self {
pub(crate) fn render(
self,
env: &Environment,
cluster: &Cluster,
node: &Node,
) -> Patches<serde_yaml::Value> {
Patches {
all: render(self.all.clone(), env, cluster, node),
control_plane: render(self.control_plane.clone(), env, cluster, node),
}