Compare commits
2 commits
b62fa7b9ec
...
fb16a34a75
Author | SHA1 | Date | |
---|---|---|---|
|
fb16a34a75 | ||
|
1bcbca58c8 |
9 changed files with 74 additions and 38 deletions
|
@ -23,7 +23,7 @@
|
|||
|
||||
" name " {your configuraton file} {your authorization file}"))
|
||||
|
||||
(s/def ::options (s/* #{"-h"
|
||||
(s/def ::options (s/* #{"-h"
|
||||
"-v" "--version"
|
||||
"-c" "--config"
|
||||
"-a" "--auth"}))
|
||||
|
@ -91,21 +91,22 @@
|
|||
auth-edn (auth-parse-fn auth-str)
|
||||
config-valid? (s/valid? config-spec? config-edn)
|
||||
auth-valid? (s/valid? auth-spec? auth-edn)]
|
||||
(if (and config-valid? auth-valid?)
|
||||
(println (cm/generate-common config-edn auth-edn config-defaults k8s-objects))
|
||||
(do
|
||||
(when (not config-valid?)
|
||||
(println
|
||||
(expound/expound-str config-spec? config-edn {:print-specs? false})))
|
||||
(when (not auth-valid?)
|
||||
(println
|
||||
(expound/expound-str auth-spec? auth-edn {:print-specs? false})))))))))))
|
||||
(if (and config-valid? auth-valid?)
|
||||
(println (cm/generate-common config-edn auth-edn config-defaults k8s-objects))
|
||||
(do
|
||||
(when (not config-valid?)
|
||||
(println
|
||||
(expound/expound-str config-spec? config-edn {:print-specs? false})))
|
||||
(when (not auth-valid?)
|
||||
(println
|
||||
(expound/expound-str auth-spec? auth-edn {:print-specs? false})))))))))))
|
||||
|
||||
; REVIEW gec: should this also be changed to main-cm? This would mean a breaking change.
|
||||
(defn -main [& cmd-args]
|
||||
(main-common "c4k-common"
|
||||
core/config?
|
||||
core/auth?
|
||||
core/config-defaults
|
||||
core/k8s-objects
|
||||
cmd-args))
|
||||
(main-cm
|
||||
"c4k-common"
|
||||
core/config?
|
||||
core/auth?
|
||||
core/config-defaults
|
||||
core/config-objects
|
||||
core/auth-objects
|
||||
cmd-args))
|
|
@ -7,15 +7,22 @@
|
|||
|
||||
(def config-defaults {})
|
||||
|
||||
(def config? (s/keys :req-un []
|
||||
(def config? (s/keys :req-un [::monitoring/mon-cfg]
|
||||
:opt-un []))
|
||||
|
||||
(def auth? (s/keys :req-un []
|
||||
(def auth? (s/keys :req-un [::monitoring/mon-auth]
|
||||
:opt-un []))
|
||||
|
||||
(defn k8s-objects [config auth]
|
||||
(defn config-objects [config]
|
||||
(let []
|
||||
(map yaml/to-string
|
||||
(filter #(not (nil? %))
|
||||
(cm/concat-vec
|
||||
(monitoring/generate config auth))))))
|
||||
(monitoring/generate-config))))))
|
||||
|
||||
(defn auth-objects [config auth]
|
||||
(let []
|
||||
(map yaml/to-string
|
||||
(filter #(not (nil? %))
|
||||
(cm/concat-vec
|
||||
(monitoring/generate-auth (:mon-cfg config) (:mon-auth auth)))))))
|
|
@ -34,12 +34,11 @@
|
|||
:pv-storage-size-gb 10
|
||||
: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-configmap map?
|
||||
(defn-spec generate-configmap map?
|
||||
[& config (s/? pg-config?)]
|
||||
(let [final-config (merge default-config
|
||||
(first config))]
|
||||
(int/generate-config-configmap final-config)))
|
||||
(int/generate-configmap final-config)))
|
||||
|
||||
|
||||
(defn-spec generate-deployment map?
|
||||
|
@ -89,7 +88,7 @@
|
|||
config)]
|
||||
[(int/generate-secret final-config auth)
|
||||
(int/generate-persistent-volume final-config)
|
||||
(int/generate-config-configmap final-config)
|
||||
(int/generate-configmap final-config)
|
||||
(int/generate-pvc final-config)
|
||||
(int/generate-deployment final-config)
|
||||
(int/generate-service final-config)]))
|
||||
|
@ -99,7 +98,7 @@
|
|||
(let [final-config (merge default-config
|
||||
config)]
|
||||
[(int/generate-persistent-volume final-config)
|
||||
(int/generate-config-configmap final-config)
|
||||
(int/generate-configmap final-config)
|
||||
(int/generate-pvc final-config)
|
||||
(int/generate-deployment final-config)
|
||||
(int/generate-service final-config)]))
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
(def postgres-function (s/keys :opt-un [::deserializer ::optional]))
|
||||
|
||||
|
||||
(defn-spec generate-config-configmap map?
|
||||
(defn-spec generate-configmap map?
|
||||
[config pg-config?]
|
||||
(let [{:keys [postgres-size db-name namespace]} config]
|
||||
(->
|
||||
|
@ -62,7 +62,7 @@
|
|||
(assoc-in [:data :postgres-db] db-name))))
|
||||
|
||||
(defn-spec ^{:deprecated "6.4.1"} generate-config map?
|
||||
"use generate-config-configmap instead"
|
||||
"use generate-configmap instead"
|
||||
[config pg-config?]
|
||||
(let [{:keys [postgres-size db-name namespace]} config]
|
||||
(->
|
||||
|
|
22
src/test/cljc/dda/c4k_common/core_test.cljc
Normal file
22
src/test/cljc/dda/c4k_common/core_test.cljc
Normal file
|
@ -0,0 +1,22 @@
|
|||
(ns dda.c4k-common.core-test
|
||||
(:require
|
||||
#?(:cljs [shadow.resource :as rc])
|
||||
#?(:clj [clojure.test :refer [deftest is are testing run-tests]]
|
||||
:cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
|
||||
[clojure.spec.alpha :as s]
|
||||
[dda.c4k-common.yaml :as yaml]
|
||||
[dda.c4k-common.core :as cut]))
|
||||
|
||||
#?(:cljs
|
||||
(defmethod yaml/load-resource :common-test [resource-name]
|
||||
(case resource-name
|
||||
"common-test/valid-auth.yaml" (rc/inline "common-test/valid-auth.yaml")
|
||||
"common-test/valid-config.yaml" (rc/inline "common-test/valid-config.yaml")
|
||||
(throw (js/Error. "Undefined Resource!")))))
|
||||
|
||||
(def conf (yaml/load-as-edn "common-test/valid-config.yaml"))
|
||||
(def auth (yaml/load-as-edn "common-test/valid-auth.yaml"))
|
||||
|
||||
(deftest validate-valid-resources
|
||||
(is (s/valid? cut/config? conf))
|
||||
(is (s/valid? cut/auth? auth)))
|
|
@ -5,18 +5,18 @@
|
|||
[clojure.spec.test.alpha :as st]
|
||||
[dda.c4k-common.postgres.postgres-internal :as cut]))
|
||||
|
||||
(st/instrument `cut/generate-config-configmap)
|
||||
(st/instrument `cut/generate-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-configmap
|
||||
(deftest should-generate-configmap
|
||||
(is (= {:name "postgres-config",
|
||||
:namespace "default"
|
||||
:labels {:app "postgres"}}
|
||||
(:metadata (cut/generate-config-configmap {:postgres-image "postgres:13"
|
||||
(:metadata (cut/generate-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-configmap {:postgres-image "postgres:13"
|
||||
(:metadata (cut/generate-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-configmap {:postgres-image "postgres:13"
|
||||
(:data (cut/generate-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-configmap {:postgres-image "postgres:13"
|
||||
(:data (cut/generate-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-configmap {:postgres-image "postgres:13"
|
||||
(:data (cut/generate-configmap {:postgres-image "postgres:13"
|
||||
:postgres-size :2gb
|
||||
:db-name "test"
|
||||
:postgres-data-volume-path "/var/postgres"
|
||||
|
|
|
@ -5,18 +5,18 @@
|
|||
[clojure.spec.test.alpha :as st]
|
||||
[dda.c4k-common.postgres :as cut]))
|
||||
|
||||
(st/instrument `cut/generate-config-configmap)
|
||||
(st/instrument `cut/generate-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-configmap
|
||||
(deftest should-generate-configmap
|
||||
(is (= {:postgres-db "postgres"
|
||||
:postgresql.conf
|
||||
"max_connections = 100\nwork_mem = 4MB\nshared_buffers = 512MB\n"}
|
||||
(:data (cut/generate-config-configmap)))))
|
||||
(:data (cut/generate-configmap)))))
|
||||
|
||||
(deftest should-generate-persistent-volume
|
||||
(is (= {:kind "PersistentVolume"
|
||||
|
|
3
src/test/resources/common-test/valid-auth.yaml
Normal file
3
src/test/resources/common-test/valid-auth.yaml
Normal file
|
@ -0,0 +1,3 @@
|
|||
mon-auth:
|
||||
grafana-cloud-user: "user"
|
||||
grafana-cloud-password: "password"
|
4
src/test/resources/common-test/valid-config.yaml
Normal file
4
src/test/resources/common-test/valid-config.yaml
Normal file
|
@ -0,0 +1,4 @@
|
|||
mon-cfg:
|
||||
grafana-cloud-url: "url-for-your-prom-remote-write-endpoint"
|
||||
cluster-name: "forgejo"
|
||||
cluster-stage: "test"
|
Loading…
Reference in a new issue