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

View file

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

View file

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

View file

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