diff --git a/README.md b/README.md index 91a1671..10693f8 100644 --- a/README.md +++ b/README.md @@ -379,14 +379,14 @@ You can connect your application to grafana cloud. | c4k-keycloak | 1.2.1 | x | x | x | | | c4k-taiga | 1.1.1 | x | x | | | | c4k-nextcloud | 10.2 | x | x | x | | -| c4k-jitsi | 2.1 | x | x | | | -| c4k-forgejo | 3.4.0 | x | x | x | | +| c4k-jitsi | 2.1 | x | x | x | x | +| c4k-forgejo | 3.5.0 | x | x | x | x | | c4k-shynet | 1.0 | x | x | | x | | c4k-website | 2.0 | x | x | | | [macro]: https://repo.prod.meissa.de/meissa/c4k-jitsi/commit/61d05ceedb6dcbc6bb96b96fe6f03598e2878195 [native]: https://repo.prod.meissa.de/meissa/c4k-forgejo/pulls/4/files -[split]: https://repo.prod.meissa.de/meissa/c4k-shynet/pulls/1 +[split]: https://repo.prod.meissa.de/meissa/c4k-jitsi/commit/d4fb8ca9e2ab44f9f9923d2e09c81a61e44b39b2 [ns]: https://repo.prod.meissa.de/meissa/c4k-keycloak/commit/3639f3d5e6d5b364822a05b3d5d569bbc556a68b ## Development & Mirrors @@ -395,7 +395,8 @@ Development happens at: https://repo.prod.meissa.de/meissa/c4k-common Mirrors are: -* https://gitlab.com/domaindrivenarchitecture/c4k-common (issues and PR) +* https://codeberg.org/meissa/c4k-common (Issues and PR) +* https://gitlab.com/domaindrivenarchitecture/c4k-common (CI) * https://github.com/DomainDrivenArchitecture/c4k-common For more details about our repository model see: https://repo.prod.meissa.de/meissa/federate-your-repos diff --git a/project-cljs.clj b/project-cljs.clj index 6be8482..cbcf979 100644 --- a/project-cljs.clj +++ b/project-cljs.clj @@ -1,4 +1,4 @@ -(defproject org.domaindrivenarchitecture/c4k-common-cljs "6.4.2-SNAPSHOT" +(defproject org.domaindrivenarchitecture/c4k-common-cljs "8.0.1-SNAPSHOT" :description "Contains predicates and tools for c4k" :url "https://domaindrivenarchitecture.org" :license {:name "Apache License, Version 2.0" diff --git a/project.clj b/project.clj index b0c74e1..20112c6 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject org.domaindrivenarchitecture/c4k-common-clj "6.4.2-SNAPSHOT" +(defproject org.domaindrivenarchitecture/c4k-common-clj "8.0.1-SNAPSHOT" :description "Contains predicates and tools for c4k" :url "https://domaindrivenarchitecture.org" :license {:name "Apache License, Version 2.0" diff --git a/src/main/clj/dda/c4k_common/uberjar.clj b/src/main/clj/dda/c4k_common/uberjar.clj index 89a4c25..6d716c2 100644 --- a/src/main/clj/dda/c4k_common/uberjar.clj +++ b/src/main/clj/dda/c4k_common/uberjar.clj @@ -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,20 +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}))))))))))) (defn -main [& cmd-args] - (main-common "c4k-common" - core/config? - core/auth? - core/config-defaults - core/k8s-objects - cmd-args)) \ No newline at end of file + (main-cm + "c4k-common" + core/config? + core/auth? + core/config-defaults + core/config-objects + core/auth-objects + cmd-args)) \ No newline at end of file diff --git a/src/main/cljc/dda/c4k_common/common.cljc b/src/main/cljc/dda/c4k_common/common.cljc index 3caf9c6..d378238 100644 --- a/src/main/cljc/dda/c4k_common/common.cljc +++ b/src/main/cljc/dda/c4k_common/common.cljc @@ -61,9 +61,9 @@ (let [resulting-config (merge config-defaults my-config) both (or (and only-config only-auth) (and (not only-config) (not only-auth))) res-vec (cond - both (concat-vec (config-objects resulting-config) (auth-objects my-auth)) - only-config (config-objects my-config) - only-auth (auth-objects my-auth))] + both (concat-vec (config-objects resulting-config) (auth-objects resulting-config my-auth)) + only-config (config-objects resulting-config) + only-auth (auth-objects resulting-config my-auth))] (cs/join "\n---\n" res-vec))) diff --git a/src/main/cljc/dda/c4k_common/core.cljc b/src/main/cljc/dda/c4k_common/core.cljc index 98e78eb..c8675a2 100644 --- a/src/main/cljc/dda/c4k_common/core.cljc +++ b/src/main/cljc/dda/c4k_common/core.cljc @@ -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)))))) \ No newline at end of file + (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))))))) \ No newline at end of file diff --git a/src/main/cljc/dda/c4k_common/monitoring.cljc b/src/main/cljc/dda/c4k_common/monitoring.cljc index a3c70a4..9c8d788 100644 --- a/src/main/cljc/dda/c4k_common/monitoring.cljc +++ b/src/main/cljc/dda/c4k_common/monitoring.cljc @@ -12,16 +12,17 @@ (s/def ::cluster-name ::int/cluster-name) (s/def ::cluster-stage ::int/cluster-stage) (s/def ::mon-cfg (s/keys :req-un [::grafana-cloud-url - ::cluster-name - ::cluster-stage])) -(s/def ::mon-auth (s/keys :req-un [::grafana-cloud-user - ::grafana-cloud-password])) + ::cluster-name + ::cluster-stage])) +(s/def ::mon-auth (s/keys :req-un [::grafana-cloud-user + ::grafana-cloud-password])) (def filter-regex-string int/filter-regex-string) -(defn-spec generate seq? +(defn-spec ^{:deprecated "6.4.1"} generate seq? + "use generate-config and generate-auth instead" [config ::mon-cfg auth ::mon-auth] [(yaml/load-as-edn "monitoring/namespace.yaml") @@ -29,7 +30,7 @@ (yaml/load-as-edn "monitoring/prometheus-cluster-role-binding.yaml") (yaml/load-as-edn "monitoring/prometheus-service.yaml") (yaml/load-as-edn "monitoring/prometheus-service-account.yaml") - (int/generate-config config auth) + (int/generate-config-secret config auth) (yaml/load-as-edn "monitoring/prometheus-deployment.yaml") (yaml/load-as-edn "monitoring/node-exporter-service-account.yaml") (yaml/load-as-edn "monitoring/node-exporter-cluster-role.yaml") @@ -41,3 +42,27 @@ (yaml/load-as-edn "monitoring/kube-state-metrics-deployment.yaml") (yaml/load-as-edn "monitoring/kube-state-metrics-service-account.yaml") (yaml/load-as-edn "monitoring/kube-state-metrics-service.yaml")]) + +(defn-spec generate-config seq? + [] + [(yaml/load-as-edn "monitoring/namespace.yaml") + (yaml/load-as-edn "monitoring/prometheus-cluster-role.yaml") + (yaml/load-as-edn "monitoring/prometheus-cluster-role-binding.yaml") + (yaml/load-as-edn "monitoring/prometheus-service.yaml") + (yaml/load-as-edn "monitoring/prometheus-service-account.yaml") + (yaml/load-as-edn "monitoring/prometheus-deployment.yaml") + (yaml/load-as-edn "monitoring/node-exporter-service-account.yaml") + (yaml/load-as-edn "monitoring/node-exporter-cluster-role.yaml") + (yaml/load-as-edn "monitoring/node-exporter-cluster-role-binding.yaml") + (yaml/load-as-edn "monitoring/node-exporter-daemon-set.yaml") + (yaml/load-as-edn "monitoring/node-exporter-service.yaml") + (yaml/load-as-edn "monitoring/kube-state-metrics-cluster-role-binding.yaml") + (yaml/load-as-edn "monitoring/kube-state-metrics-cluster-role.yaml") + (yaml/load-as-edn "monitoring/kube-state-metrics-deployment.yaml") + (yaml/load-as-edn "monitoring/kube-state-metrics-service-account.yaml") + (yaml/load-as-edn "monitoring/kube-state-metrics-service.yaml")]) + +(defn-spec generate-auth seq? + [config ::mon-cfg + auth ::mon-auth] + [(int/generate-config-secret config auth)]) diff --git a/src/main/cljc/dda/c4k_common/monitoring/monitoring_internal.cljc b/src/main/cljc/dda/c4k_common/monitoring/monitoring_internal.cljc index e807017..651fead 100644 --- a/src/main/cljc/dda/c4k_common/monitoring/monitoring_internal.cljc +++ b/src/main/cljc/dda/c4k_common/monitoring/monitoring_internal.cljc @@ -26,7 +26,7 @@ "monitoring/node-exporter-service.yaml" (rc/inline "monitoring/node-exporter-service.yaml") "monitoring/prometheus-cluster-role-binding.yaml" (rc/inline "monitoring/prometheus-cluster-role-binding.yaml") "monitoring/prometheus-cluster-role.yaml" (rc/inline "monitoring/prometheus-cluster-role.yaml") - "monitoring/prometheus-config.yaml" (rc/inline "monitoring/prometheus-config.yaml") + "monitoring/prometheus-config-secret.yaml" (rc/inline "monitoring/prometheus-config-secret.yaml") "monitoring/prometheus-deployment.yaml" (rc/inline "monitoring/prometheus-deployment.yaml") "monitoring/prometheus-prometheus.yaml" (rc/inline "monitoring/prometheus-prometheus.yaml") "monitoring/prometheus-service-account.yaml" (rc/inline "monitoring/prometheus-service-account.yaml") @@ -82,11 +82,21 @@ grafana-cloud-password) (cm/replace-all-matching "FILTER_REGEX" filter-regex-string)))) -(defn-spec generate-config map? +(defn-spec generate-config-secret map? [config ::mon-cfg auth ::mon-auth] (-> - (yaml/load-as-edn "monitoring/prometheus-config.yaml") + (yaml/load-as-edn "monitoring/prometheus-config-secret.yaml") + (assoc-in [:stringData :prometheus.yaml] + (yaml/to-string + (generate-prometheus-config config auth))))) + +(defn-spec ^{:deprecated "6.4.1"} generate-config map? + "Use generate-config-secret instead" + [config ::mon-cfg + auth ::mon-auth] + (-> + (yaml/load-as-edn "monitoring/prometheus-config-secret.yaml") (assoc-in [:stringData :prometheus.yaml] (yaml/to-string (generate-prometheus-config config auth))))) diff --git a/src/main/cljc/dda/c4k_common/postgres.cljc b/src/main/cljc/dda/c4k_common/postgres.cljc index 98364d5..64f5fde 100644 --- a/src/main/cljc/dda/c4k_common/postgres.cljc +++ b/src/main/cljc/dda/c4k_common/postgres.cljc @@ -34,12 +34,11 @@ :pv-storage-size-gb 10 :pvc-storage-class-name "manual"})) - -(defn-spec generate-config map? +(defn-spec generate-configmap map? [& config (s/? pg-config?)] (let [final-config (merge default-config (first config))] - (int/generate-config final-config))) + (int/generate-configmap final-config))) (defn-spec generate-deployment map? @@ -56,11 +55,11 @@ (int/generate-persistent-volume final-config))) -(defn-spec generate-pvc map? +(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 +80,32 @@ (int/generate-service final-config))) -(defn-spec generate seq? - [config pg-config? +(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-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-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)])) diff --git a/src/main/cljc/dda/c4k_common/postgres/postgres_internal.cljc b/src/main/cljc/dda/c4k_common/postgres/postgres_internal.cljc index ad4c253..84dd022 100644 --- a/src/main/cljc/dda/c4k_common/postgres/postgres_internal.cljc +++ b/src/main/cljc/dda/c4k_common/postgres/postgres_internal.cljc @@ -52,7 +52,17 @@ (def postgres-function (s/keys :opt-un [::deserializer ::optional])) -(defn-spec generate-config map? +(defn-spec generate-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-configmap instead" [config pg-config?] (let [{:keys [postgres-size db-name namespace]} config] (-> diff --git a/src/main/resources/monitoring/prometheus-config.yaml b/src/main/resources/monitoring/prometheus-config-secret.yaml similarity index 100% rename from src/main/resources/monitoring/prometheus-config.yaml rename to src/main/resources/monitoring/prometheus-config-secret.yaml diff --git a/src/test/cljc/dda/c4k_common/core_test.cljc b/src/test/cljc/dda/c4k_common/core_test.cljc new file mode 100644 index 0000000..a73e79c --- /dev/null +++ b/src/test/cljc/dda/c4k_common/core_test.cljc @@ -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))) diff --git a/src/test/cljc/dda/c4k_common/monitoring/monitoring_internal_test.cljc b/src/test/cljc/dda/c4k_common/monitoring/monitoring_internal_test.cljc index b763456..dbb4389 100644 --- a/src/test/cljc/dda/c4k_common/monitoring/monitoring_internal_test.cljc +++ b/src/test/cljc/dda/c4k_common/monitoring/monitoring_internal_test.cljc @@ -8,7 +8,7 @@ (st/instrument `cut/generate-stateful-set) (st/instrument `cut/generate-agent-config) -(st/instrument `cut/generate-config) +(st/instrument `cut/generate-config-secret) (def conf {:cluster-name "clustername" :cluster-stage "test" @@ -29,12 +29,12 @@ (deftest should-not-generate-config (is (thrown? #?(:clj Exception :cljs js/Error) - (cut/generate-config invalid-conf auth)))) + (cut/generate-config-secret invalid-conf auth)))) (deftest should-not-generate-auth (is (thrown? #?(:clj Exception :cljs js/Error) - (cut/generate-config conf invalid-auth)))) + (cut/generate-config-secret conf invalid-auth)))) (deftest should-generate-prometheus-remote-write-auth @@ -54,6 +54,6 @@ (deftest should-generate-config (is (str/starts-with? (get-in - (cut/generate-config conf auth) + (cut/generate-config-secret conf auth) [:stringData :prometheus.yaml]) "global:\n scrape_interval:"))) \ No newline at end of file diff --git a/src/test/cljc/dda/c4k_common/monitoring_test.cljc b/src/test/cljc/dda/c4k_common/monitoring_test.cljc index 5e5332b..1efc434 100644 --- a/src/test/cljc/dda/c4k_common/monitoring_test.cljc +++ b/src/test/cljc/dda/c4k_common/monitoring_test.cljc @@ -6,6 +6,8 @@ [dda.c4k-common.monitoring :as cut])) (st/instrument `cut/generate) +(st/instrument `cut/generate-config) +(st/instrument `cut/generate-auth) (def conf {:cluster-name "clustername" :cluster-stage "test" @@ -18,4 +20,8 @@ (deftest should-generate (is (= 17 - (count (cut/generate conf auth))))) + (count (cut/generate conf auth)))) + (is (= 16 + (count (cut/generate-config)))) + (is (= 1 + (count (cut/generate-auth conf auth))))) diff --git a/src/test/cljc/dda/c4k_common/postgres/postgres_internal_test.cljc b/src/test/cljc/dda/c4k_common/postgres/postgres_internal_test.cljc index 55116db..187a18e 100644 --- a/src/test/cljc/dda/c4k_common/postgres/postgres_internal_test.cljc +++ b/src/test/cljc/dda/c4k_common/postgres/postgres_internal_test.cljc @@ -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-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-configmap (is (= {:name "postgres-config", :namespace "default" :labels {:app "postgres"}} - (:metadata (cut/generate-config {: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 {: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 {: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 {: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 {:postgres-image "postgres:13" + (:data (cut/generate-configmap {:postgres-image "postgres:13" :postgres-size :2gb :db-name "test" :postgres-data-volume-path "/var/postgres" diff --git a/src/test/cljc/dda/c4k_common/postgres_test.cljc b/src/test/cljc/dda/c4k_common/postgres_test.cljc index 236928a..4117667 100644 --- a/src/test/cljc/dda/c4k_common/postgres_test.cljc +++ b/src/test/cljc/dda/c4k_common/postgres_test.cljc @@ -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-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-configmap (is (= {:postgres-db "postgres" :postgresql.conf "max_connections = 100\nwork_mem = 4MB\nshared_buffers = 512MB\n"} - (:data (cut/generate-config))))) + (:data (cut/generate-configmap))))) (deftest should-generate-persistent-volume (is (= {:kind "PersistentVolume" @@ -52,6 +54,12 @@ (deftest should-generate (is (= 6 - (count (cut/generate {} + (count (cut/generate {} {:postgres-db-user "user" - :postgres-db-password "password"}))))) \ No newline at end of file + :postgres-db-password "password"})))) + (is (= 5 + (count (cut/generate-config {})))) + (is (= 1 + (count (cut/generate-auth {} + {:postgres-db-user "user" + :postgres-db-password "password"}))))) \ No newline at end of file diff --git a/src/test/resources/common-test/valid-auth.yaml b/src/test/resources/common-test/valid-auth.yaml new file mode 100644 index 0000000..2103b03 --- /dev/null +++ b/src/test/resources/common-test/valid-auth.yaml @@ -0,0 +1,3 @@ +mon-auth: + grafana-cloud-user: "user" + grafana-cloud-password: "password" diff --git a/src/test/resources/common-test/valid-config.yaml b/src/test/resources/common-test/valid-config.yaml new file mode 100644 index 0000000..08da11f --- /dev/null +++ b/src/test/resources/common-test/valid-config.yaml @@ -0,0 +1,4 @@ +mon-cfg: + grafana-cloud-url: "url-for-your-prom-remote-write-endpoint" + cluster-name: "forgejo" + cluster-stage: "test" \ No newline at end of file