feat: add ingress wip
Some checks reported errors
continuous-integration/drone/push Build encountered an error

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-05-27 21:39:29 +02:00
parent 252d0852ae
commit 8f806474d1
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
3 changed files with 72 additions and 5 deletions

10
Cargo.lock generated
View File

@ -899,9 +899,9 @@ dependencies = [
[[package]]
name = "clang-sys"
version = "1.7.0"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1"
checksum = "a483f3cbf7cec2e153d424d0e92329d816becc6421389bd494375c6065921b9b"
dependencies = [
"glob",
"libc",
@ -1032,9 +1032,9 @@ checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5"
[[package]]
name = "crc32c"
version = "0.6.5"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89254598aa9b9fa608de44b3ae54c810f0f06d755e24c50177f1f8f31ff50ce2"
checksum = "716b38bb6e49e9071060ab2c5e26195b70274f83fdf6cbc44542d63bb2f45c7d"
dependencies = [
"rustc_version",
]
@ -1406,7 +1406,7 @@ dependencies = [
[[package]]
name = "flux-releaser"
version = "0.1.0"
source = "git+https://git.front.kjuulh.io/kjuulh/flux-releaser?branch=main#921a7c6fbf60b222c1bcc94ddfab2fe6d4c58582"
source = "git+https://git.front.kjuulh.io/kjuulh/flux-releaser?branch=main#3ca0a836ca9382dfc53ecc159a7ddc10e08e6755"
dependencies = [
"anyhow",
"async-trait",

View File

@ -1,4 +1,5 @@
pub mod cluster_vars;
pub mod crdb_database;
pub mod cuddle_vars;
pub mod ingress;
pub mod vault_secret;

View File

@ -0,0 +1,66 @@
use std::path::Path;
use crate::Component;
use super::cuddle_vars::{load_cuddle_file, CuddleVariable, CuddleVariables};
pub struct Ingress {
variables: CuddleVariables,
}
impl Ingress {
pub async fn new(path: &Path) -> anyhow::Result<Self> {
let variables = load_cuddle_file(path).await?;
Ok(Self { variables })
}
}
impl Component for Ingress {
fn name(&self) -> String {
format!("cuddle/ingress")
}
fn render(
&self,
environment: &str,
value: &serde_yaml::Value,
) -> Option<anyhow::Result<(String, String)>> {
if let Some(true) = self
.variables
.0
.get("database")
.and_then(|v| match v {
CuddleVariable::Object(o) => Some(o),
_ => None,
})
.and_then(|o| o.0.get("crdb"))
.and_then(|o| match o {
CuddleVariable::String(o) => {
if o == "true" {
Some(true)
} else {
None
}
}
_ => None,
})
{
return Some(Ok((
format!("{}.yaml", self.name().replace("/", "-")),
r#"
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ vars.cuddle_crdb.file_name(vars.cuddle_vars.service) }}
namespace: {{ vars.cluster_vars.namespace }}
data:
DATABASE_URL: postgresql://root@{{environment}}-cluster:26257/{{ vars.cuddle_vars.service | replace("-", "_") }}
"#
.into(),
)));
}
None
}
}