From 3b3809f7af1684557310f8059c74b76c59408acf Mon Sep 17 00:00:00 2001 From: Cyber MacGeddon Date: Mon, 14 Oct 2024 17:29:48 +0100 Subject: [PATCH] Partial K8s implementation --- templates/engine/k8s.jsonnet | 54 ++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/templates/engine/k8s.jsonnet b/templates/engine/k8s.jsonnet index 69aabfd7..86b70d8b 100644 --- a/templates/engine/k8s.jsonnet +++ b/templates/engine/k8s.jsonnet @@ -10,12 +10,15 @@ reservations: {}, ports: [], volumes: [], + environment: {}, with_image:: function(x) self + { image: x }, with_command:: function(x) self + { command: x }, - with_environment:: function(x) self + { environment: x }, + with_environment:: function(x) self + { + environment: super.environment + x, + }, with_limits:: function(c, m) self + { limits: { cpu: c, memory: m } }, @@ -37,6 +40,16 @@ ] }, + with_env_var_secrets:: + function(vars) + std.foldl( + function(obj, x) obj.with_environment( + { [x]: "${" + x + "}" } + ), + vars.variables, + self + ), + add:: function() [ { @@ -97,7 +110,8 @@ (if std.objectHas(container, "command") then { command: container.command } else {}) + - (if std.objectHas(container, "environment") then + + (if ! std.isEmpty(container.environment) then { env: [ { name: e.key, value: e.value } @@ -283,6 +297,42 @@ }, + envSecrets:: function(name) + { + + local volume = self, + + name: name, + + variables: [], + + with_size:: function(size) self + { size: size }, + + add:: function() [ + { + apiVersion: "v1", + kind: "Secret", + metadata: { + name: volume.name, + namespace: "trustgraph", + }, + data: { + } + }, + ], + + volRef:: function() { + name: volume.name, + secret: { secretName: volume.name }, + }, + + with_env_var:: + function(name) self + { + variables: super.variables + [name], + }, + + }, + containers:: function(name, containers) {