From ec201a038d4c7c89bfa2bef02f6023f3039fc2cd Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Sun, 14 Apr 2024 21:00:15 +0200 Subject: [PATCH] simplify kubenix definitions --- kubenix-modules/dnsmasq.nix | 5 +- kubenix-modules/forgejo.nix | 14 ++--- kubenix-modules/freshrss.nix | 34 +++++------- kubenix-modules/hedgedoc.nix | 41 +++++---------- kubenix-modules/kitchenowl.nix | 7 +-- kubenix-modules/media.nix | 86 +++++++++---------------------- kubenix-modules/minecraft.nix | 7 +-- kubenix-modules/nextcloud.nix | 19 +++---- kubenix-modules/paperless-ngx.nix | 42 +++++---------- kubenix-modules/pihole.nix | 27 +++------- kubenix-modules/radicale.nix | 14 ++--- kubenix-modules/syncthing.nix | 14 ++--- 12 files changed, 95 insertions(+), 215 deletions(-) diff --git a/kubenix-modules/dnsmasq.nix b/kubenix-modules/dnsmasq.nix index 43ed7f5..8cabdde 100644 --- a/kubenix-modules/dnsmasq.nix +++ b/kubenix-modules/dnsmasq.nix @@ -41,10 +41,7 @@ }]; }; - volumes = [{ - name = "config"; - configMap.name = "dnsmasq-config"; - }]; + volumes.config.configMap.name = "dnsmasq-config"; }; }; }; diff --git a/kubenix-modules/forgejo.nix b/kubenix-modules/forgejo.nix index 029c833..76eda8e 100644 --- a/kubenix-modules/forgejo.nix +++ b/kubenix-modules/forgejo.nix @@ -155,16 +155,10 @@ ]; }; - volumes = [ - { - name = "data"; - persistentVolumeClaim.claimName = "forgejo"; - } - { - name = "config"; - configMap.name = "forgejo-config"; - } - ]; + volumes = { + data.persistentVolumeClaim.claimName = "forgejo"; + config.configMap.name = "forgejo-config"; + }; }; }; }; diff --git a/kubenix-modules/freshrss.nix b/kubenix-modules/freshrss.nix index a832c41..ed574a6 100644 --- a/kubenix-modules/freshrss.nix +++ b/kubenix-modules/freshrss.nix @@ -19,6 +19,8 @@ metadata.labels.app = "freshrss"; spec = { + volumes.data.persistentVolumeClaim.claimName = "freshrss"; + containers.freshrss = { image = "freshrss/freshrss:edge"; envFrom = [{ configMapRef.name = "freshrss"; }]; @@ -28,35 +30,23 @@ protocol = "TCP"; }]; - env = [ - { - name = "ADMIN_PASSWORD"; + env = { + ADMIN_PASSWORD.valueFrom.secretKeyRef = { + name = "freshrss"; + key = "adminPassword"; + }; - valueFrom.secretKeyRef = { - name = "freshrss"; - key = "adminPassword"; - }; - } - { - name = "ADMIN_API_PASSWORD"; - - valueFrom.secretKeyRef = { - name = "freshrss"; - key = "adminPassword"; - }; - } - ]; + ADMIN_API_PASSWORD.valueFrom.secretKeyRef = { + name = "freshrss"; + key = "adminPassword"; + }; + }; volumeMounts = [{ name = "data"; mountPath = "/var/www/FreshRSS/data"; }]; }; - - volumes = [{ - name = "data"; - persistentVolumeClaim.claimName = "freshrss"; - }]; }; }; }; diff --git a/kubenix-modules/hedgedoc.nix b/kubenix-modules/hedgedoc.nix index bcb4a58..9ec49f2 100644 --- a/kubenix-modules/hedgedoc.nix +++ b/kubenix-modules/hedgedoc.nix @@ -43,24 +43,17 @@ protocol = "TCP"; }]; - env = [ - { - name = "CMD_DB_URL"; + env = { + CMD_DB_URL.valueFrom.secretKeyRef = { + name = "hedgedoc"; + key = "databaseURL"; + }; - valueFrom.secretKeyRef = { - name = "hedgedoc"; - key = "databaseURL"; - }; - } - { - name = "CMD_SESSION_SECRET"; - - valueFrom.secretKeyRef = { - name = "hedgedoc"; - key = "sessionSecret"; - }; - } - ]; + CMD_SESSION_SECRET.valueFrom.secretKeyRef = { + name = "hedgedoc"; + key = "sessionSecret"; + }; + }; volumeMounts = [ { @@ -75,16 +68,10 @@ ]; }; - volumes = [ - { - name = "uploads"; - persistentVolumeClaim.claimName = "hedgedoc"; - } - { - name = "config"; - configMap.name = "hedgedoc-config"; - } - ]; + volumes = { + uploads.persistentVolumeClaim.claimName = "hedgedoc"; + config.configMap.name = "hedgedoc-config"; + }; }; }; }; diff --git a/kubenix-modules/kitchenowl.nix b/kubenix-modules/kitchenowl.nix index 6c3fd83..0657dde 100644 --- a/kubenix-modules/kitchenowl.nix +++ b/kubenix-modules/kitchenowl.nix @@ -59,6 +59,8 @@ }; spec = { + volumes.data.persistentVolumeClaim.claimName = "kitchenowl"; + containers.kitchenowl-backend = { image = "tombursch/kitchenowl:v92"; @@ -72,11 +74,6 @@ mountPath = "/data"; }]; }; - - volumes = [{ - name = "data"; - persistentVolumeClaim.claimName = "kitchenowl"; - }]; }; }; }; diff --git a/kubenix-modules/media.nix b/kubenix-modules/media.nix index 17ff19b..7c7568f 100644 --- a/kubenix-modules/media.nix +++ b/kubenix-modules/media.nix @@ -79,16 +79,10 @@ ]; }; - volumes = [ - { - name = "config"; - persistentVolumeClaim.claimName = "jellyfin-config"; - } - { - name = "media"; - persistentVolumeClaim.claimName = "media"; - } - ]; + volumes = { + config.persistentVolumeClaim.claimName = "jellyfin-config"; + media.persistentVolumeClaim.claimName = "media"; + }; }; }; }; @@ -122,8 +116,6 @@ containerPort = 9091; protocol = "TCP"; } - # TODO: Only use TCP, as Kubernetes does not support multiple protocols for a port number. - # Should see if this works as correctly though. { containerPort = 31780; protocol = "TCP"; @@ -142,16 +134,10 @@ ]; }; - volumes = [ - { - name = "config"; - persistentVolumeClaim.claimName = "transmission-config"; - } - { - name = "media"; - persistentVolumeClaim.claimName = "media"; - } - ]; + volumes = { + config.persistentVolumeClaim.claimName = "transmission-config"; + media.persistentVolumeClaim.claimName = "media"; + }; }; }; }; @@ -176,6 +162,8 @@ }; spec = { + volumes.config.persistentVolumeClaim.claimName = "jellyseerr-config"; + containers.jellyseerr = { image = "fallenbagel/jellyseerr:1.7.0"; envFrom = [{ configMapRef.name = "jellyseerr-env"; }]; @@ -190,11 +178,6 @@ mountPath = "/app/config"; }]; }; - - volumes = [{ - name = "config"; - persistentVolumeClaim.claimName = "jellyseerr-config"; - }]; }; }; }; @@ -240,16 +223,10 @@ ]; }; - volumes = [ - { - name = "config"; - persistentVolumeClaim.claimName = "radarr-config"; - } - { - name = "media"; - persistentVolumeClaim.claimName = "media"; - } - ]; + volumes = { + config.persistentVolumeClaim.claimName = "radarr-config"; + media.persistentVolumeClaim.claimName = "media"; + }; }; }; }; @@ -274,6 +251,8 @@ }; spec = { + volumes.config.persistentVolumeClaim.claimName = "prowlarr-config"; + containers.prowlarr = { image = "lscr.io/linuxserver/prowlarr:latest"; envFrom = [{ configMapRef.name = "prowlarr-env"; }]; @@ -288,11 +267,6 @@ mountPath = "/config"; }]; }; - - volumes = [{ - name = "config"; - persistentVolumeClaim.claimName = "prowlarr-config"; - }]; }; }; }; @@ -338,16 +312,10 @@ ]; }; - volumes = [ - { - name = "config"; - persistentVolumeClaim.claimName = "sonarr-config"; - } - { - name = "media"; - persistentVolumeClaim.claimName = "media"; - } - ]; + volumes = { + config.persistentVolumeClaim.claimName = "sonarr-config"; + media.persistentVolumeClaim.claimName = "media"; + }; }; }; }; @@ -393,16 +361,10 @@ ]; }; - volumes = [ - { - name = "config"; - persistentVolumeClaim.claimName = "bazarr-config"; - } - { - name = "media"; - persistentVolumeClaim.claimName = "media"; - } - ]; + volumes = { + config.persistentVolumeClaim.claimName = "bazarr-config"; + media.persistentVolumeClaim.claimName = "media"; + }; }; }; }; diff --git a/kubenix-modules/minecraft.nix b/kubenix-modules/minecraft.nix index 12bc7ad..073a346 100644 --- a/kubenix-modules/minecraft.nix +++ b/kubenix-modules/minecraft.nix @@ -12,6 +12,8 @@ metadata.labels.app = "minecraft"; spec = { + volumes.data.persistentVolumeClaim.claimName = "minecraft"; + containers.minecraft = { image = "itzg/minecraft-server"; envFrom = [{ configMapRef.name = "minecraft-env"; }]; @@ -26,11 +28,6 @@ mountPath = "/data"; }]; }; - - volumes = [{ - name = "data"; - persistentVolumeClaim.claimName = "minecraft"; - }]; }; }; }; diff --git a/kubenix-modules/nextcloud.nix b/kubenix-modules/nextcloud.nix index ddfe05b..da12aeb 100644 --- a/kubenix-modules/nextcloud.nix +++ b/kubenix-modules/nextcloud.nix @@ -18,6 +18,8 @@ metadata.labels.app = "nextcloud"; spec = { + volumes.data.persistentVolumeClaim.claimName = "nextcloud"; + containers.nextcloud = { image = "nextcloud:27"; envFrom = [{ configMapRef.name = "nextcloud"; }]; @@ -27,25 +29,16 @@ protocol = "TCP"; }]; - env = [{ - name = "POSTGRES_PASSWORD"; - - valueFrom.secretKeyRef = { - name = "nextcloud"; - key = "databasePassword"; - }; - }]; + env.POSTGRES_PASSWORD.valueFrom.secretKeyRef = { + name = "nextcloud"; + key = "databasePassword"; + }; volumeMounts = [{ name = "data"; mountPath = "/var/www/html"; }]; }; - - volumes = [{ - name = "data"; - persistentVolumeClaim.claimName = "nextcloud"; - }]; }; }; }; diff --git a/kubenix-modules/paperless-ngx.nix b/kubenix-modules/paperless-ngx.nix index 7afcca1..8b88c07 100644 --- a/kubenix-modules/paperless-ngx.nix +++ b/kubenix-modules/paperless-ngx.nix @@ -41,6 +41,8 @@ }; spec = { + volumes.data.persistentVolumeClaim.claimName = "paperless-ngx-data"; + containers.paperless-ngx = { image = "ghcr.io/paperless-ngx/paperless-ngx:2.3"; envFrom = [{ configMapRef.name = "paperless-ngx"; }]; @@ -50,35 +52,22 @@ protocol = "TCP"; }]; - env = [ - { - name = "PAPERLESS_DBPASS"; - - valueFrom.secretKeyRef = { - name = "paperless-ngx"; - key = "databasePassword"; - }; - } - { - name = "PAPERLESS_SECRET_KEY"; - - valueFrom.secretKeyRef = { - name = "paperless-ngx"; - key = "secretKey"; - }; - } - ]; + env = { + PAPERLESS_DBPASS.valueFrom.secretKeyRef = { + name = "paperless-ngx"; + key = "databasePassword"; + }; + PAPERLESS_SECRET_KEY.valueFrom.secretKeyRef = { + name = "paperless-ngx"; + key = "secretKey"; + }; + }; volumeMounts = [{ name = "data"; mountPath = "/data"; }]; }; - - volumes = [{ - name = "data"; - persistentVolumeClaim.claimName = "paperless-ngx-data"; - }]; }; }; }; @@ -103,6 +92,8 @@ }; spec = { + volumes.data.persistentVolumeClaim.claimName = "paperless-ngx-redisdata"; + containers.redis = { image = "docker.io/library/redis:7"; @@ -116,11 +107,6 @@ mountPath = "/data"; }]; }; - - volumes = [{ - name = "data"; - persistentVolumeClaim.claimName = "paperless-ngx-redisdata"; - }]; }; }; }; diff --git a/kubenix-modules/pihole.nix b/kubenix-modules/pihole.nix index c6ef7fe..61adfb6 100644 --- a/kubenix-modules/pihole.nix +++ b/kubenix-modules/pihole.nix @@ -32,15 +32,10 @@ } ]; - env = [{ - # TODO: simplify this by using env.WEBPASSWORD? - name = "WEBPASSWORD"; - - valueFrom.secretKeyRef = { - name = "pihole"; - key = "webPassword"; - }; - }]; + env.WEBPASSWORD.valueFrom.secretKeyRef = { + name = "pihole"; + key = "webPassword"; + }; volumeMounts = [ { @@ -54,16 +49,10 @@ ]; }; - volumes = [ - { - name = "data"; - persistentVolumeClaim.claimName = "pihole-data"; - } - { - name = "dnsmasq"; - persistentVolumeClaim.claimName = "pihole-dnsmasq"; - } - ]; + volumes = { + data.persistentVolumeClaim.claimName = "pihole-data"; + dnsmasq.persistentVolumeClaim.claimName = "pihole-dnsmasq"; + }; }; }; }; diff --git a/kubenix-modules/radicale.nix b/kubenix-modules/radicale.nix index 5c09ddf..e7914db 100644 --- a/kubenix-modules/radicale.nix +++ b/kubenix-modules/radicale.nix @@ -68,16 +68,10 @@ ]; }; - volumes = [ - { - name = "data"; - persistentVolumeClaim.claimName = "radicale"; - } - { - name = "config"; - configMap.name = "radicale"; - } - ]; + volumes = { + data.persistentVolumeClaim.claimName = "radicale"; + config.configMap.name = "radicale"; + }; }; }; }; diff --git a/kubenix-modules/syncthing.nix b/kubenix-modules/syncthing.nix index 094b46a..231eed5 100644 --- a/kubenix-modules/syncthing.nix +++ b/kubenix-modules/syncthing.nix @@ -37,16 +37,10 @@ ]; }; - volumes = [ - { - name = "config"; - persistentVolumeClaim.claimName = "syncthing"; - } - { - name = "nextcloud-data"; - persistentVolumeClaim.claimName = "nextcloud"; - } - ]; + volumes = { + config.persistentVolumeClaim.claimName = "syncthing"; + nextcloud-data.persistentVolumeClaim.claimName = "nextcloud"; + }; }; }; };