feat: add replicas
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-11-17 16:02:39 +01:00
parent 1af78da2a2
commit 05d33f1fab
No known key found for this signature in database
9 changed files with 43 additions and 72 deletions

View File

@ -17,6 +17,7 @@ pub struct ClusterVariables {
env: ClusterEnv,
name: String,
namespace: String,
replicas: u64,
}
#[derive(Default)]
@ -36,7 +37,10 @@ impl Component for ClusterVars {
environment: &str,
value: &serde_yaml::Value,
) -> Option<anyhow::Result<minijinja::Value>> {
let mut vars = ClusterVariables::default();
let mut vars = ClusterVariables {
replicas: 3,
..Default::default()
};
// TODO: actually extract values
@ -52,6 +56,12 @@ impl Component for ClusterVars {
}
}
}
if let Some(replicas) = mapping.get("replicas") {
if let Some(replicas) = replicas.as_u64() {
vars.replicas = replicas;
}
}
}
vars.name = environment.into();
@ -67,6 +77,7 @@ impl minijinja::value::Object for ClusterVariables {
"env" => minijinja::Value::from_object(self.env.clone()),
"name" => minijinja::Value::from_safe_string(self.name.clone()),
"namespace" => minijinja::Value::from_safe_string(self.namespace.clone()),
"replicas" => minijinja::Value::from_safe_string(self.replicas.to_string()),
_ => return None,
};

View File

@ -68,17 +68,8 @@ async fn with_cuddle_vars() -> anyhow::Result<()> {
}
#[tokio::test]
async fn with_actual_deployment() -> anyhow::Result<()> {
let current_dir = std::env::current_dir()?.join("tests/with_cuddle_vars");
run_test_with_components(
"with_actual_deployment",
vec![
CuddleVars::new(&current_dir).await?.into_component(),
ClusterVars::default().into_component(),
],
)
.await?;
async fn with_cluster_vars() -> anyhow::Result<()> {
run_test_with_components("with_cluster_vars", vec![ClusterVars::default()]).await?;
Ok(())
}

View File

@ -1,15 +0,0 @@
vars:
service: service
some:
nested:
item: something
array:
- item: item
cuddle/clusters:
dev:
env:
something: thing
nested.item: item

View File

@ -1,8 +0,0 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: service-config
data:
environment:
NESTED_ITEM: item
SOMETHING: thing

View File

@ -1,37 +0,0 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: service
cluster: dev
name: service
namespace: dev
spec:
replicas: 3
selector:
matchLabels:
app: service
cluster: dev
template:
metadata:
labels:
app: service
cluster: dev
spec:
containers:
- args:
- serve
command:
- service
image: kasperhermansen/service:main-1715336504
name: service
envFrom:
- configMapRef:
name: service-config
ports:
- containerPort: 3000
name: external-http
- containerPort: 3001
name: internal-http
- containerPort: 3002
name: internal-grpc

View File

@ -0,0 +1,12 @@
vars:
cuddle/clusters:
dev:
replicas: 1
env:
something.something: something
something:
# ignored
vault: true
prod:
env:

View File

@ -0,0 +1,5 @@
name: dev
namespace: dev
replicas: 1
items:
- something.something

View File

@ -0,0 +1,4 @@
name: prod
namespace: prod
replicas: 3
items:

View File

@ -0,0 +1,8 @@
name: {{ vars.cluster_vars.name }}
namespace: {{ vars.cluster_vars.namespace }}
replicas: {{ vars.cluster_vars.replicas }}
items:
{%- for val in vars.cluster_vars.env %}
- {{val}}
{%- endfor %}