32 Commits

Author SHA1 Message Date
4bb9eccb40 fix(deps): update all dependencies 2025-04-19 00:19:28 +00:00
7ab7dc7a6f chore: update deps 2025-03-26 21:31:33 +01:00
098f0033d0 chore(deps): update rust crate anyhow to v1.0.97
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-03-04 05:29:43 +00:00
5cf69eaf3a chore(deps): update all dependencies
Some checks failed
renovate/artifacts Artifact file update failure
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is failing
2025-03-04 01:31:43 +00:00
9fafe6d3aa fix(deps): update rust crate uuid to v1.15.1
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-02-27 01:32:24 +00:00
74d196a45c chore(deps): update all dependencies
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-02-25 01:29:19 +00:00
192e0212ae chore(deps): update all dependencies
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-02-21 05:27:01 +00:00
dbe7d998ae fix(deps): update rust crate serde to v1.0.218
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-02-21 01:31:03 +00:00
1fca3c5b8e chore(deps): update all dependencies
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-02-18 01:29:57 +00:00
49d72a2677 chore(deps): update rust crate clap to v4.5.29
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-02-12 01:31:21 +00:00
8dc643f614 fix(deps): update rust crate uuid to v1.13.1
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-02-06 01:29:32 +00:00
3150db8653 chore(deps): update rust crate clap to v4.5.28
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-02-04 01:29:02 +00:00
c454354a94 fix(deps): update rust crate minijinja to v2.7.0
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-01-29 01:31:09 +00:00
e06d55a593 fix(deps): update rust crate uuid to v1.12.1
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-01-21 05:29:17 +00:00
483143d2cc chore(deps): update rust crate clap to v4.5.27
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-01-21 01:27:23 +00:00
ff16753ac9 chore(deps): update rust crate similar-asserts to v1.6.1
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-01-20 01:27:56 +00:00
117fb0bed8 fix(deps): update rust crate uuid to v1.12.0
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-01-15 01:32:31 +00:00
187423d5f4 feat: add port as string
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2025-01-12 23:07:33 +01:00
34020d2939 chore: replace - with _ for postgres
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2025-01-12 22:55:27 +01:00
5b3432d6d8 fix(deps): update rust crate uuid to v1.11.1
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-01-10 05:24:05 +00:00
52d931ce42 chore(deps): update rust crate clap to v4.5.26
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is failing
2025-01-10 01:23:56 +00:00
b92e352096 fix(deps): update all dependencies
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-01-09 01:25:46 +00:00
02cbcf336c chore(deps): update rust crate clap to v4.5.24
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2025-01-08 01:23:07 +00:00
8716e64c4c fix(deps): update rust crate serde to v1.0.217
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2024-12-28 01:27:43 +00:00
f911a5a27e chore(deps): update rust crate anyhow to v1.0.95
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2024-12-23 01:28:09 +00:00
a1841c28e8 fix(deps): update rust crate serde to v1.0.216
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2024-12-11 05:23:45 +00:00
e86ed49b65 fix(deps): update rust crate tokio-stream to v0.1.17
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2024-12-07 01:29:52 +00:00
fe80539ddd chore(deps): update rust crate clap to v4.5.23
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2024-12-06 01:31:06 +00:00
b70f3f4f72 chore(deps): update all dependencies
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2024-12-04 01:29:26 +00:00
29a98b5ef5 chore(deps): update rust crate tracing-subscriber to v0.3.19
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2024-11-30 01:41:27 +00:00
a9c81a8f1b chore(release): v0.2.0 (#4)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
chore(release): 0.2.0

Co-authored-by: cuddle-please <bot@cuddle.sh>
Reviewed-on: https://git.front.kjuulh.io/kjuulh/cuddle-clusters/pulls/4
2024-11-29 09:10:38 +01:00
3956366d28 feat/add-postgres-database (#20)
All checks were successful
continuous-integration/drone/push Build is passing
feat: add postgres database

Signed-off-by: kjuulh <contact@kjuulh.io>

feat: add postgres and more templates

Signed-off-by: kjuulh <contact@kjuulh.io>

Reviewed-on: https://git.front.kjuulh.io/kjuulh/cuddle-clusters/pulls/20
Co-authored-by: kjuulh <contact@kjuulh.io>
Co-committed-by: kjuulh <contact@kjuulh.io>
2024-11-29 09:05:50 +01:00
27 changed files with 1524 additions and 815 deletions

View File

@@ -6,6 +6,87 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [0.2.0] - 2024-11-29
### Added
- feat/add-postgres-database (#20)
feat: add postgres database
Signed-off-by: kjuulh <contact@kjuulh.io>
feat: add postgres and more templates
Signed-off-by: kjuulh <contact@kjuulh.io>
Reviewed-on: https://git.front.kjuulh.io/kjuulh/cuddle-clusters/pulls/20
Co-authored-by: kjuulh <contact@kjuulh.io>
Co-committed-by: kjuulh <contact@kjuulh.io>
- add support for raw reading of variables
- add replicas
- set interval down to a minute
- with native roots
- with explicit install
- with install
- with ring
- enable stuff
- update packages
- update packages
- add actual grpc service
- fix typo
- revert to actual label
- fix scheme
- trying with h2c service
- add grpc ports as well
- fix name
- rename
- remove suffix
- add ingress
- add ingress wip
- use lower case
- use actual service name
- cannot use lowe case
- update filename
- add namespace
- update env
- add crdb
- add webroots
- with tls
- use new tokio stream
- update client
- more debugging
- update
- update flux releaser
- actually set registry
- add option for releaser
- add slot for upload strategy
- add user variables to input
- without remove all
- plan -> base
- add sync
- add send
- use arc instead
### Fixed
- *(deps)* update rust crate serde to v1.0.215
- *(deps)* update rust crate futures to v0.3.31
- *(deps)* update rust crate minijinja to v2.3.1
- *(deps)* update rust crate minijinja to v2.3.0
- *(deps)* update rust crate serde to v1.0.203
- only create vault secret template if actual secret found
### Other
- *(deps)* update rust crate tracing to v0.1.41
- *(deps)* update all dependencies
- *(deps)* update rust crate clap to v4.5.20
- *(deps)* update rust crate clap to v4.5.19
- *(deps)* update rust crate clap to v4.5.18
- *(deps)* update rust crate anyhow to v1.0.89
- *(deps)* update rust crate anyhow to v1.0.88
- *(deps)* update all dependencies
- move crdb to own file
## [0.1.1] - 2024-05-25
### Other

1920
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -14,4 +14,4 @@ dotenv = { version = "0.15" }
flux-releaser = { git = "https://git.front.kjuulh.io/kjuulh/flux-releaser", branch = "main" }
[workspace.package]
version = "0.1.1"
version = "0.2.0"

View File

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

View File

@@ -81,10 +81,6 @@ impl Component for ClusterVars {
}
}
}
// vars.raw = match value.clone().try_into() {
// Ok(o) => o,
// Err(e) => panic!("{}", e),
// };
vars.raw = value.into();
vars.name = environment.into();

View File

@@ -0,0 +1,146 @@
use std::path::Path;
use minijinja::{value::Object, Value};
use crate::Component;
use super::cuddle_vars::{load_cuddle_file, CuddleVariable, CuddleVariables};
pub struct PostgresDatabase {
variables: CuddleVariables,
}
impl PostgresDatabase {
pub async fn new(path: &Path) -> anyhow::Result<Self> {
let variables = load_cuddle_file(path).await?;
Ok(Self { variables })
}
}
impl Component for PostgresDatabase {
fn name(&self) -> String {
"cuddle/postgres".into()
}
fn render_value(
&self,
environment: &str,
_value: &serde_yaml::Value,
) -> Option<anyhow::Result<minijinja::Value>> {
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("postgres"))
.and_then(|o| match o {
CuddleVariable::String(o) => {
if o == "true" {
Some(true)
} else {
None
}
}
_ => None,
})
{
return Some(Ok(minijinja::Value::from_object(PostgresDatabaseValues {
name: self.name(),
enabled: true,
})));
}
Some(Ok(minijinja::Value::from_object(PostgresDatabaseValues {
name: self.name(),
enabled: false,
})))
}
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("postgres"))
.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#"
{%- if environment == "dev" %}
{%- set port = 5433 %}
{%- else %}
{%- set port = 5432 %}
{%- endif %}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ vars.cuddle_postgres.file_name(vars.cuddle_vars.service) }}
namespace: {{ vars.cluster_vars.namespace }}
data:
DATABASE_TYPE: postgresql
DATABASE_HOST: {{ environment }}.postgresql.kjuulh.app
DATABASE_PORT: "{{ port }}"
DATABASE_USER: {{ vars.cuddle_vars.service | replace("-", "_") }}
DATABASE_DB: {{ vars.cuddle_vars.service | replace("-", "_") }}
"#
.into(),
)));
}
None
}
}
#[derive(Debug)]
struct PostgresDatabaseValues {
name: String,
enabled: bool,
}
impl Object for PostgresDatabaseValues {
fn get_value(self: &std::sync::Arc<Self>, key: &minijinja::Value) -> Option<minijinja::Value> {
let name = self.name.clone();
match key.as_str()? {
"has_values" => {
if self.enabled {
Some(minijinja::Value::from_serialize(true))
} else {
Some(minijinja::Value::from_serialize(false))
}
}
"file_name" => Some(Value::from_function(move |file_name: String| {
format!("{}-{}", file_name, name.replace("/", "-"))
})),
"env" => Some(Value::from_serialize(vec![
"DATABASE_HOST",
"DATABASE_PORT",
"DATABASE_USER",
"DATABASE_DB",
])),
_ => None,
}
}
}

View File

@@ -354,6 +354,12 @@ async fn process_render_template(
vars => variables
})?;
let rendered = if rendered.is_empty() || rendered.ends_with("\n") {
rendered
} else {
format!("{rendered}\n")
};
dest_file.write_all(rendered.as_bytes()).await?;
Ok(())

View File

@@ -3,4 +3,4 @@
some = {
thing = "some"
}
}
}

View File

@@ -1 +1 @@
env: dev
env: dev

View File

@@ -1 +1 @@
env: prod
env: prod

View File

@@ -1 +1 @@
some_file: 4
some_file: 4

View File

@@ -1 +1 @@
service
service

View File

@@ -1 +1 @@
service
service

View File

@@ -6,7 +6,7 @@ mod cuddle_vars;
use cuddle_clusters::{
catalog::{
cluster_vars::ClusterVars, crdb_database::CockroachDB, cuddle_vars::CuddleVars,
ingress::Ingress, vault_secret::VaultSecret,
ingress::Ingress, postgres_database::PostgresDatabase, vault_secret::VaultSecret,
},
IntoComponent,
};
@@ -125,3 +125,21 @@ async fn with_ingress() -> anyhow::Result<()> {
Ok(())
}
#[tokio::test]
async fn with_postgres_databse() -> anyhow::Result<()> {
let current_dir = std::env::current_dir()?.join("tests/with_postgres_database");
run_test_with_components(
"with_postgres_database",
vec![
CuddleVars::new(&current_dir).await?.into_component(),
ClusterVars::default().into_component(),
VaultSecret::default().into_component(),
PostgresDatabase::new(&current_dir).await?.into_component(),
],
)
.await?;
Ok(())
}

View File

@@ -6,4 +6,4 @@ metadata:
namespace: dev
data:
DATABASE_URL: postgresql://root@dev-cluster:26257/service

View File

@@ -36,4 +36,4 @@ spec:
- containerPort: 3001
name: internal-http
- containerPort: 3002
name: internal-grpc
name: internal-grpc

View File

@@ -118,4 +118,4 @@ spec:
tls:
- hosts:
- grpc.service.dev.internal.kjuulh.app
secretName: tls-service-kjuulh-app-internal-grpc-ingress-dns
secretName: tls-service-kjuulh-app-internal-grpc-ingress-dns

View File

@@ -27,4 +27,4 @@ spec:
- containerPort: 3001
name: internal-http
- containerPort: 3002
name: internal-grpc
name: internal-grpc

View File

@@ -118,4 +118,4 @@ spec:
tls:
- hosts:
- grpc.service.prod.internal.kjuulh.app
secretName: tls-service-kjuulh-app-internal-grpc-ingress-dns
secretName: tls-service-kjuulh-app-internal-grpc-ingress-dns

View File

@@ -27,4 +27,4 @@ spec:
- containerPort: 3001
name: internal-http
- containerPort: 3002
name: internal-grpc
name: internal-grpc

View File

@@ -0,0 +1,7 @@
vars:
service: service
database:
postgres: "true"
cuddle/clusters:
dev:

View File

@@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: service-cuddle-postgres
namespace: dev
data:
DATABASE_TYPE: postgresql
DATABASE_HOST: dev.postgresql.kjuulh.app
DATABASE_PORT: "5433"
DATABASE_USER: service
DATABASE_DB: service

View File

@@ -0,0 +1,54 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: service
name: service
spec:
replicas: 3
selector:
matchLabels:
app: service
template:
metadata:
labels:
app: service
spec:
containers:
- args:
- serve
command:
- service
image: kasperhermansen/service:main-1715336504
name: service
envFrom:
- configMapRef:
name: service-config
env:
- name: DATABASE_HOST
valueFrom:
secretKeyRef:
name: service-cuddle-postgres
key: DATABASE_HOST
- name: DATABASE_PORT
valueFrom:
secretKeyRef:
name: service-cuddle-postgres
key: DATABASE_PORT
- name: DATABASE_USER
valueFrom:
secretKeyRef:
name: service-cuddle-postgres
key: DATABASE_USER
- name: DATABASE_DB
valueFrom:
secretKeyRef:
name: service-cuddle-postgres
key: DATABASE_DB
ports:
- containerPort: 3000
name: external-http
- containerPort: 3001
name: internal-http
- containerPort: 3002
name: internal-grpc

View File

@@ -0,0 +1,56 @@
{%- set service_name = vars.cuddle_vars.service -%}
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: {{ service_name }}
name: {{ service_name }}
spec:
replicas: 3
selector:
matchLabels:
app: {{ service_name }}
template:
metadata:
labels:
app: {{ service_name }}
spec:
containers:
- args:
- serve
command:
- {{ service_name }}
image: kasperhermansen/{{ service_name }}:main-1715336504
name: {{ service_name }}
envFrom:
- configMapRef:
name: {{service_name}}-config
{%- if vars.vault_secret.has_values or vars.cuddle_postgres.has_values %}
env:
{%- if vars.vault_secret.has_values %}
{%- for secret in vars.vault_secret.secrets %}
- name: {{secret | upper | replace(".", "_") | replace("-", "_") }}
valueFrom:
secretKeyRef:
name: {{ vars.vault_secret.file_name(service_name) }}
key: {{ secret }}
{%- endfor %}
{%- endif %}
{%- if vars.cuddle_postgres.has_values %}
{%- for env in vars.cuddle_postgres.env %}
- name: {{ env }}
valueFrom:
secretKeyRef:
name: {{ vars.cuddle_postgres.file_name(service_name) }}
key: {{ env }}
{%- endfor %}
{%- endif %}
{%- endif %}
ports:
- containerPort: 3000
name: external-http
- containerPort: 3001
name: internal-http
- containerPort: 3002
name: internal-grpc

View File

@@ -36,4 +36,4 @@ spec:
- containerPort: 3001
name: internal-http
- containerPort: 3002
name: internal-grpc
name: internal-grpc

View File

@@ -10,4 +10,4 @@ spec:
mount: kvv2
path: service/dev
refreshAfter: 30s
type: kv-v2
type: kv-v2