Split for generation of config and auth objects #4

Merged
gec merged 9 commits from split-config-auth into main 2024-07-19 09:06:52 +00:00
5 changed files with 61 additions and 22 deletions
Showing only changes of commit 7fc4380bb0 - Show all commits

View file

@ -34,12 +34,12 @@
:pv-storage-size-gb 10
:pvc-storage-class-name "manual"}))
(defn-spec generate-config map?
; REVIEW gec: This breaking change means, every call from outside to generate-config will mean something completely different.
(defn-spec generate-config-configmap map?
[& config (s/? pg-config?)]
(let [final-config (merge default-config
(first config))]
(int/generate-config final-config)))
(int/generate-config-configmap final-config)))
(defn-spec generate-deployment map?
@ -59,8 +59,8 @@
(defn-spec generate-pvc map?
[config pg-config?]
(let [final-config (merge default-config
config)]
(int/generate-pvc final-config)))
config)]
(int/generate-pvc final-config)))
(defn-spec generate-secret map?
@ -81,14 +81,32 @@
(int/generate-service final-config)))
(defn-spec generate seq?
(defn-spec ^{:deprecated "6.4.1"} generate seq?
"use generate-config and generate-auth instead"
[config pg-config?
auth pg-auth?]
(let [final-config (merge default-config
config)]
[(int/generate-secret final-config auth)
(int/generate-persistent-volume final-config)
(int/generate-config final-config)
(int/generate-config-configmap final-config)
(int/generate-pvc final-config)
(int/generate-deployment final-config)
(int/generate-service final-config)]))
(defn-spec generate-config seq?
[config pg-config?]
(let [final-config (merge default-config
config)]
[(int/generate-persistent-volume final-config)
(int/generate-config-configmap final-config)
(int/generate-pvc final-config)
(int/generate-deployment final-config)
(int/generate-service final-config)]))
(defn-spec generate-auth seq?
[config pg-config?
auth pg-auth?]
(let [final-config (merge default-config
config)]
[(int/generate-secret final-config auth)]))

View file

@ -52,7 +52,17 @@
(def postgres-function (s/keys :opt-un [::deserializer ::optional]))
(defn-spec generate-config map?
(defn-spec generate-config-configmap map?
[config pg-config?]
(let [{:keys [postgres-size db-name namespace]} config]
(->
(yaml/from-string (yaml/load-resource
(str "postgres/config-" (name postgres-size) ".yaml")))
(assoc-in [:metadata :namespace] namespace)
(assoc-in [:data :postgres-db] db-name))))
(defn-spec ^{:deprecated "6.4.1"} generate-config map?
"use generate-config-configmap instead"
[config pg-config?]
(let [{:keys [postgres-size db-name namespace]} config]
(->

View file

@ -5,6 +5,7 @@
[clojure.spec.test.alpha :as st]
[dda.c4k-common.monitoring :as cut]))
(st/instrument `cut/generate)
(st/instrument `cut/generate-config)
(st/instrument `cut/generate-auth)
@ -18,6 +19,8 @@
(deftest should-generate
(is (= 17
(count (cut/generate conf auth))))
(is (= 16
(count (cut/generate-config conf auth))))
(is (= 1

View file

@ -5,18 +5,18 @@
[clojure.spec.test.alpha :as st]
[dda.c4k-common.postgres.postgres-internal :as cut]))
(st/instrument `cut/generate-config)
(st/instrument `cut/generate-config-configmap)
(st/instrument `cut/generate-deployment)
(st/instrument `cut/generate-persistent-volume)
(st/instrument `cut/generate-pvc)
(st/instrument `cut/generate-secret)
(st/instrument `cut/generate-service)
(deftest should-generate-config
(deftest should-generate-config-configmap
(is (= {:name "postgres-config",
:namespace "default"
:labels {:app "postgres"}}
(:metadata (cut/generate-config {:postgres-image "postgres:13"
(:metadata (cut/generate-config-configmap {:postgres-image "postgres:13"
:postgres-size :2gb
:db-name "postgres"
:postgres-data-volume-path "/var/postgres"
@ -26,7 +26,7 @@
(is (= {:name "postgres-config",
:namespace "myapp"
:labels {:app "postgres"}}
(:metadata (cut/generate-config {:postgres-image "postgres:13"
(:metadata (cut/generate-config-configmap {:postgres-image "postgres:13"
:postgres-size :2gb
:db-name "postgres"
:postgres-data-volume-path "/var/postgres"
@ -36,7 +36,7 @@
(is (= {:postgres-db "postgres"
:postgresql.conf
"max_connections = 100\nwork_mem = 4MB\nshared_buffers = 512MB\n"}
(:data (cut/generate-config {:postgres-image "postgres:13"
(:data (cut/generate-config-configmap {:postgres-image "postgres:13"
:postgres-size :2gb
:db-name "postgres"
:postgres-data-volume-path "/var/postgres"
@ -46,7 +46,7 @@
(is (= {:postgres-db "postgres"
:postgresql.conf
"max_connections = 700\nwork_mem = 3MB\nshared_buffers = 2048MB\n"}
(:data (cut/generate-config {:postgres-image "postgres:13"
(:data (cut/generate-config-configmap {:postgres-image "postgres:13"
:postgres-size :8gb
:db-name "postgres"
:postgres-data-volume-path "/var/postgres"
@ -56,7 +56,7 @@
(is (= {:postgres-db "test"
:postgresql.conf
"max_connections = 100\nwork_mem = 4MB\nshared_buffers = 512MB\n"}
(:data (cut/generate-config {:postgres-image "postgres:13"
(:data (cut/generate-config-configmap {:postgres-image "postgres:13"
:postgres-size :2gb
:db-name "test"
:postgres-data-volume-path "/var/postgres"

View file

@ -5,16 +5,18 @@
[clojure.spec.test.alpha :as st]
[dda.c4k-common.postgres :as cut]))
(st/instrument `cut/generate-config)
(st/instrument `cut/generate-config-configmap)
(st/instrument `cut/generate-persistent-volume)
(st/instrument `cut/generate-secret)
(st/instrument `cut/generate)
(st/instrument `cut/generate-config)
(st/instrument `cut/generate-auth)
(deftest should-generate-config
(deftest should-generate-config-configmap
(is (= {:postgres-db "postgres"
:postgresql.conf
"max_connections = 100\nwork_mem = 4MB\nshared_buffers = 512MB\n"}
(:data (cut/generate-config)))))
(:data (cut/generate-config-configmap)))))
(deftest should-generate-persistent-volume
(is (= {:kind "PersistentVolume"
@ -54,4 +56,10 @@
(is (= 6
(count (cut/generate {}
{:postgres-db-user "user"
:postgres-db-password "password"})))))
:postgres-db-password "password"}))))
(is (= 5
(count (cut/generate-config {}))))
(is (= 1
(count (cut/generate-auth {}
{:postgres-db-user "user"
:postgres-db-password "password"})))))