65 lines
1.6 KiB
Rust
65 lines
1.6 KiB
Rust
use minijinja::{Environment, context};
|
|
use optional_struct::optional_struct;
|
|
use schemars::JsonSchema;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::cluster::Cluster;
|
|
use crate::node::Node;
|
|
|
|
#[optional_struct]
|
|
#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone, PartialEq, Eq, Default)]
|
|
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
|
pub(crate) struct Patches<T> {
|
|
pub(crate) all: Vec<T>,
|
|
pub(crate) control_plane: Vec<T>,
|
|
}
|
|
|
|
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(|name| {
|
|
let content = env
|
|
.get_template(&name)
|
|
.unwrap()
|
|
.render(context! {
|
|
node,
|
|
cluster
|
|
})
|
|
.unwrap();
|
|
|
|
serde_yaml::from_str(&content).unwrap()
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
impl Patches<String> {
|
|
pub(crate) fn extend(mut self, other: Self) -> Self {
|
|
self.all.extend(other.all);
|
|
self.control_plane.extend(other.control_plane);
|
|
|
|
Self {
|
|
all: self.all,
|
|
control_plane: self.control_plane,
|
|
}
|
|
}
|
|
|
|
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),
|
|
}
|
|
}
|
|
}
|