add resource loading to yaml

This commit is contained in:
jem 2021-02-26 14:29:01 +01:00
parent bfcabbdf11
commit f5d6d6f27b
5 changed files with 40 additions and 31 deletions

View file

@ -1,5 +1,6 @@
{:source-paths ["src/main/cljc" {:source-paths ["src/main/cljc"
"src/main/cljs" "src/main/cljs"
"src/main/resources"
"src/test/cljc"] "src/test/cljc"]
:dependencies [[aero "1.1.6"]] :dependencies [[aero "1.1.6"]]
:builds {:test {:target :node-test :builds {:test {:target :node-test

View file

@ -1,8 +1,14 @@
(ns dda.k8s-mastodon-bot.yaml (ns dda.k8s-mastodon-bot.yaml
(:require (:require
["js-yaml" :as yaml] ["js-yaml" :as yaml]
[shadow.resource :as rc]
)) ))
(def config (rc/inline "config.yaml"))
(defn load-resource [resource-name]
config)
(defn from-string [input] (defn from-string [input]
(js->clj (yaml/load input) (js->clj (yaml/load input)
:keywordize-keys true)) :keywordize-keys true))

11
src/main/resources/config.yaml Executable file
View file

@ -0,0 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: mastodon-bot
labels:
app.kubernetes.io/name: k8s-mastodon-bot
data:
config.edn: |
some-config-value
credentials.edn: |
some-credentials-value

View file

@ -5,45 +5,28 @@ metadata:
spec: spec:
selector: selector:
matchLabels: matchLabels:
app: k8s-mastodon-bot app.kubernetes.io/name: k8s-mastodon-bot
strategy: strategy:
type: Recreate type: Recreate
template: template:
metadata: metadata:
labels: labels:
app: k8s-mastodon-bot app.kubernetes.io/name: k8s-mastodon-bot
spec: spec:
containers: containers:
- image: postgres - image: mastodon-bot
name: k8s-mastodon-bot name: mastodon-bot
env: env:
- name: POSTGRES_USER_FILE - name: MASTODON_BOT_CREDENTIALS
value: /var/run/secrets/postgres-secrets/postgres-user value: /app/credentials.edn
- name: POSTGRES_DB_FILE
value: /var/run/secrets/postgres-secrets/postgres-db
- name: POSTGRES_PASSWORD_FILE
value: /var/run/secrets/postgres-secrets/postgres-password
ports:
- containerPort: 5432
name: k8s-mastodon-bot
cmd: cmd:
volumeMounts: volumeMounts:
- name: k8s-mastodon-bot - name: mastodon-bot
mountPath: /var/lib/k8s-mastodon-bot/data mountPath: /app/config.edn
- name: postgres-secret-volume subPath: config.conf
mountPath: /var/run/secrets/postgres-secrets
readOnly: true readOnly: true
- name: postgres-config-volume - name: mastodon-bot
mountPath: /etc/k8s-mastodon-bot/k8s-mastodon-bot.conf mountPath: /app/credentials.edn
subPath: k8s-mastodon-bot.conf subPath: credentials.conf
readOnly: true readOnly: true
volumes:
- name: k8s-mastodon-bot
persistentVolumeClaim:
claimName: postgres-claim
- name: postgres-secret-volume
secret:
secretName: postgres-secret
- name: postgres-config-volume
configMap:
name: postgres-config

View file

@ -1,4 +1,4 @@
(ns dda.k8s-mastodon-bot.yaml-test (ns dda.k8s-mastodon-bot.yaml-test
(:require (:require
[clojure.test :refer [deftest is testing are]] [clojure.test :refer [deftest is testing are]]
[dda.k8s-mastodon-bot.yaml :as cut])) [dda.k8s-mastodon-bot.yaml :as cut]))
@ -11,3 +11,11 @@
(is (= "hallo: welt (is (= "hallo: welt
" "
(cut/to-string {:hallo "welt"})))) (cut/to-string {:hallo "welt"}))))
(deftest should-convert-config-yml-to-map
(is (= {:apiVersion "v1", :kind "ConfigMap"
:metadata {:name "mastodon-bot",
:labels {:app.kubernetes.io/name "k8s-mastodon-bot"}},
:data {:config.edn "some-config-value\n",
:credentials.edn "some-credentials-value\n"}}
(cut/from-string (cut/load-resource "config.yml")))))