From ca8ab8d7085a3cdec0fd02813d80a9c1e51fb2dc Mon Sep 17 00:00:00 2001 From: Clemens Date: Wed, 17 Jul 2024 10:48:44 +0200 Subject: [PATCH 01/17] split monitoring into config and auth --- src/main/clj/dda/c4k_common/uberjar.clj | 1 + src/main/cljc/dda/c4k_common/monitoring.cljc | 38 ++++++++++++++++--- .../monitoring/monitoring_internal.cljc | 14 ++++++- ...fig.yaml => prometheus-config-secret.yaml} | 0 4 files changed, 45 insertions(+), 8 deletions(-) rename src/main/resources/monitoring/{prometheus-config.yaml => prometheus-config-secret.yaml} (100%) diff --git a/src/main/clj/dda/c4k_common/uberjar.clj b/src/main/clj/dda/c4k_common/uberjar.clj index 89a4c25..3cf55cc 100644 --- a/src/main/clj/dda/c4k_common/uberjar.clj +++ b/src/main/clj/dda/c4k_common/uberjar.clj @@ -101,6 +101,7 @@ (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? diff --git a/src/main/cljc/dda/c4k_common/monitoring.cljc b/src/main/cljc/dda/c4k_common/monitoring.cljc index a3c70a4..7e662a0 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,28 @@ (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? + [config ::mon-cfg + auth ::mon-auth] + [(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..87c787f 100644 --- a/src/main/cljc/dda/c4k_common/monitoring/monitoring_internal.cljc +++ b/src/main/cljc/dda/c4k_common/monitoring/monitoring_internal.cljc @@ -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/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 From 52e3ba6ae1de429efeb36267a6b431dc1e087bf5 Mon Sep 17 00:00:00 2001 From: Clemens Date: Wed, 17 Jul 2024 11:02:37 +0200 Subject: [PATCH 02/17] fix tests --- .../dda/c4k_common/monitoring/monitoring_internal.cljc | 2 +- .../c4k_common/monitoring/monitoring_internal_test.cljc | 8 ++++---- src/test/cljc/dda/c4k_common/monitoring_test.cljc | 9 ++++++--- 3 files changed, 11 insertions(+), 8 deletions(-) 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 87c787f..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") 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..6dc168c 100644 --- a/src/test/cljc/dda/c4k_common/monitoring_test.cljc +++ b/src/test/cljc/dda/c4k_common/monitoring_test.cljc @@ -5,7 +5,8 @@ [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) (def conf {:cluster-name "clustername" :cluster-stage "test" @@ -17,5 +18,7 @@ (deftest should-generate - (is (= 17 - (count (cut/generate conf auth))))) + (is (= 16 + (count (cut/generate-config conf auth)))) + (is (= 1 + (count (cut/generate-auth conf auth))))) From 7fc4380bb082038af7d4f283cb585e0b86d44705 Mon Sep 17 00:00:00 2001 From: Clemens Date: Wed, 17 Jul 2024 11:31:19 +0200 Subject: [PATCH 03/17] added config auth split for postgres generate --- src/main/cljc/dda/c4k_common/postgres.cljc | 36 ++++++++++++++----- .../postgres/postgres_internal.cljc | 12 ++++++- .../cljc/dda/c4k_common/monitoring_test.cljc | 3 ++ .../postgres/postgres_internal_test.cljc | 14 ++++---- .../cljc/dda/c4k_common/postgres_test.cljc | 18 +++++++--- 5 files changed, 61 insertions(+), 22 deletions(-) diff --git a/src/main/cljc/dda/c4k_common/postgres.cljc b/src/main/cljc/dda/c4k_common/postgres.cljc index 98364d5..687b6e1 100644 --- a/src/main/cljc/dda/c4k_common/postgres.cljc +++ b/src/main/cljc/dda/c4k_common/postgres.cljc @@ -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? @@ -56,11 +56,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 +81,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-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)])) 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..48a456b 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-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] (-> diff --git a/src/test/cljc/dda/c4k_common/monitoring_test.cljc b/src/test/cljc/dda/c4k_common/monitoring_test.cljc index 6dc168c..e9fd302 100644 --- a/src/test/cljc/dda/c4k_common/monitoring_test.cljc +++ b/src/test/cljc/dda/c4k_common/monitoring_test.cljc @@ -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 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..3e37fcc 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-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" diff --git a/src/test/cljc/dda/c4k_common/postgres_test.cljc b/src/test/cljc/dda/c4k_common/postgres_test.cljc index 236928a..a9c958e 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-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" @@ -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 From 74d5a63beabcfe2cdceb7499898350eb2bfee8be Mon Sep 17 00:00:00 2001 From: Clemens Date: Wed, 17 Jul 2024 14:08:33 +0200 Subject: [PATCH 04/17] remove unused parameters --- src/main/cljc/dda/c4k_common/monitoring.cljc | 3 +-- src/test/cljc/dda/c4k_common/monitoring_test.cljc | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/cljc/dda/c4k_common/monitoring.cljc b/src/main/cljc/dda/c4k_common/monitoring.cljc index 7e662a0..9c8d788 100644 --- a/src/main/cljc/dda/c4k_common/monitoring.cljc +++ b/src/main/cljc/dda/c4k_common/monitoring.cljc @@ -44,8 +44,7 @@ (yaml/load-as-edn "monitoring/kube-state-metrics-service.yaml")]) (defn-spec generate-config seq? - [config ::mon-cfg - auth ::mon-auth] + [] [(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") diff --git a/src/test/cljc/dda/c4k_common/monitoring_test.cljc b/src/test/cljc/dda/c4k_common/monitoring_test.cljc index e9fd302..1efc434 100644 --- a/src/test/cljc/dda/c4k_common/monitoring_test.cljc +++ b/src/test/cljc/dda/c4k_common/monitoring_test.cljc @@ -22,6 +22,6 @@ (is (= 17 (count (cut/generate conf auth)))) (is (= 16 - (count (cut/generate-config conf auth)))) + (count (cut/generate-config)))) (is (= 1 (count (cut/generate-auth conf auth))))) From 57a9340109c9f6a6e217d9d04de820bfe8f5040d Mon Sep 17 00:00:00 2001 From: Clemens Date: Thu, 18 Jul 2024 08:50:31 +0200 Subject: [PATCH 05/17] breaking: apply config and auth to auth-objects --- src/main/cljc/dda/c4k_common/common.cljc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/cljc/dda/c4k_common/common.cljc b/src/main/cljc/dda/c4k_common/common.cljc index 3caf9c6..d9ec440 100644 --- a/src/main/cljc/dda/c4k_common/common.cljc +++ b/src/main/cljc/dda/c4k_common/common.cljc @@ -63,7 +63,7 @@ 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))] + only-auth (auth-objects my-config my-auth))] (cs/join "\n---\n" res-vec))) From 2154bed190eca74f1993ba84596104b57cfea0df Mon Sep 17 00:00:00 2001 From: Clemens Date: Thu, 18 Jul 2024 09:03:38 +0200 Subject: [PATCH 06/17] fix: consistent parameter apply for auth-objects --- src/main/cljc/dda/c4k_common/common.cljc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/cljc/dda/c4k_common/common.cljc b/src/main/cljc/dda/c4k_common/common.cljc index d9ec440..759fc7e 100644 --- a/src/main/cljc/dda/c4k_common/common.cljc +++ b/src/main/cljc/dda/c4k_common/common.cljc @@ -61,7 +61,7 @@ (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)) + both (concat-vec (config-objects resulting-config) (auth-objects my-config my-auth)) only-config (config-objects my-config) only-auth (auth-objects my-config my-auth))] (cs/join From b62fa7b9ecb6fac507c85f7af1a15310b48068a3 Mon Sep 17 00:00:00 2001 From: Clemens Date: Thu, 18 Jul 2024 09:31:04 +0200 Subject: [PATCH 07/17] consistent use of config defaults --- src/main/cljc/dda/c4k_common/common.cljc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/cljc/dda/c4k_common/common.cljc b/src/main/cljc/dda/c4k_common/common.cljc index 759fc7e..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-config my-auth)) - only-config (config-objects my-config) - only-auth (auth-objects my-config 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))) From 1bcbca58c811754e87275945487e355dde1b99ae Mon Sep 17 00:00:00 2001 From: Clemens Date: Fri, 19 Jul 2024 10:47:06 +0200 Subject: [PATCH 08/17] updated main function --- src/main/clj/dda/c4k_common/uberjar.clj | 35 ++++++++++--------- src/main/cljc/dda/c4k_common/core.cljc | 15 +++++--- src/test/cljc/dda/c4k_common/core_test.cljc | 22 ++++++++++++ .../resources/common-test/valid-auth.yaml | 3 ++ .../resources/common-test/valid-config.yaml | 4 +++ 5 files changed, 58 insertions(+), 21 deletions(-) create mode 100644 src/test/cljc/dda/c4k_common/core_test.cljc create mode 100644 src/test/resources/common-test/valid-auth.yaml create mode 100644 src/test/resources/common-test/valid-config.yaml diff --git a/src/main/clj/dda/c4k_common/uberjar.clj b/src/main/clj/dda/c4k_common/uberjar.clj index 3cf55cc..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,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)) \ 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/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/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/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 From fb16a34a7531308a2f024345296958a4f35912fc Mon Sep 17 00:00:00 2001 From: Clemens Date: Fri, 19 Jul 2024 10:51:47 +0200 Subject: [PATCH 09/17] renaming for generate-configmap --- src/main/cljc/dda/c4k_common/postgres.cljc | 9 ++++----- .../dda/c4k_common/postgres/postgres_internal.cljc | 4 ++-- .../postgres/postgres_internal_test.cljc | 14 +++++++------- src/test/cljc/dda/c4k_common/postgres_test.cljc | 6 +++--- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/main/cljc/dda/c4k_common/postgres.cljc b/src/main/cljc/dda/c4k_common/postgres.cljc index 687b6e1..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"})) -; 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)])) 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 48a456b..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,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] (-> 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 3e37fcc..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-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" diff --git a/src/test/cljc/dda/c4k_common/postgres_test.cljc b/src/test/cljc/dda/c4k_common/postgres_test.cljc index a9c958e..4117667 100644 --- a/src/test/cljc/dda/c4k_common/postgres_test.cljc +++ b/src/test/cljc/dda/c4k_common/postgres_test.cljc @@ -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" From 14fe8d8ee0bfd65292672712648b0bb3ed2af287 Mon Sep 17 00:00:00 2001 From: Clemens Date: Fri, 19 Jul 2024 11:08:08 +0200 Subject: [PATCH 10/17] release: 7.0.0 --- project-cljs.clj | 2 +- project.clj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/project-cljs.clj b/project-cljs.clj index 6be8482..92d87c0 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 "7.0.0" :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..7cd3cd3 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 "7.0.0" :description "Contains predicates and tools for c4k" :url "https://domaindrivenarchitecture.org" :license {:name "Apache License, Version 2.0" From a94e8165de7bc25092317acdefe57b23ffd21e77 Mon Sep 17 00:00:00 2001 From: Clemens Date: Fri, 19 Jul 2024 11:08:08 +0200 Subject: [PATCH 11/17] bump version to: 7.0.1-SNAPSHOT --- project-cljs.clj | 2 +- project.clj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/project-cljs.clj b/project-cljs.clj index 92d87c0..5266d0c 100644 --- a/project-cljs.clj +++ b/project-cljs.clj @@ -1,4 +1,4 @@ -(defproject org.domaindrivenarchitecture/c4k-common-cljs "7.0.0" +(defproject org.domaindrivenarchitecture/c4k-common-cljs "7.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 7cd3cd3..15b24f8 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject org.domaindrivenarchitecture/c4k-common-clj "7.0.0" +(defproject org.domaindrivenarchitecture/c4k-common-clj "7.0.1-SNAPSHOT" :description "Contains predicates and tools for c4k" :url "https://domaindrivenarchitecture.org" :license {:name "Apache License, Version 2.0" From 5ae28c6af52698ee4508ee27ac08a71b9aa82dc8 Mon Sep 17 00:00:00 2001 From: Clemens Date: Fri, 19 Jul 2024 11:33:18 +0200 Subject: [PATCH 12/17] updated refactoring overview --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f410027..2a31f52 100644 --- a/README.md +++ b/README.md @@ -380,13 +380,13 @@ You can connect your application to grafana cloud. | 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-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-forgejo/pulls/5 [ns]: https://repo.prod.meissa.de/meissa/c4k-keycloak/commit/3639f3d5e6d5b364822a05b3d5d569bbc556a68b ## Development & Mirrors From 94bfec3da9f07e56da1d6b2d3871da0f70f3649a Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Fri, 2 Aug 2024 16:31:51 +0200 Subject: [PATCH 13/17] update refactoring --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2a31f52..663d283 100644 --- a/README.md +++ b/README.md @@ -379,7 +379,7 @@ 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-jitsi | 2.1 | 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 | | | From d7e2c2536a1d9e41ccfece5c09f8cef87b1bf827 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Fri, 2 Aug 2024 16:53:57 +0200 Subject: [PATCH 14/17] release: 8.0.0 --- project-cljs.clj | 2 +- project.clj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/project-cljs.clj b/project-cljs.clj index 5266d0c..9fa3983 100644 --- a/project-cljs.clj +++ b/project-cljs.clj @@ -1,4 +1,4 @@ -(defproject org.domaindrivenarchitecture/c4k-common-cljs "7.0.1-SNAPSHOT" +(defproject org.domaindrivenarchitecture/c4k-common-cljs "8.0.0" :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 15b24f8..e11e66b 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject org.domaindrivenarchitecture/c4k-common-clj "7.0.1-SNAPSHOT" +(defproject org.domaindrivenarchitecture/c4k-common-clj "8.0.0" :description "Contains predicates and tools for c4k" :url "https://domaindrivenarchitecture.org" :license {:name "Apache License, Version 2.0" From fa6a5011d8617c9f02acb8ab918387da4bcbdd2f Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Fri, 2 Aug 2024 16:53:57 +0200 Subject: [PATCH 15/17] bump version to: 8.0.1-SNAPSHOT --- project-cljs.clj | 2 +- project.clj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/project-cljs.clj b/project-cljs.clj index 9fa3983..cbcf979 100644 --- a/project-cljs.clj +++ b/project-cljs.clj @@ -1,4 +1,4 @@ -(defproject org.domaindrivenarchitecture/c4k-common-cljs "8.0.0" +(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 e11e66b..20112c6 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject org.domaindrivenarchitecture/c4k-common-clj "8.0.0" +(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" From f4f2e97ebb6b037002a273afa9ed715181389527 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Fri, 2 Aug 2024 17:18:35 +0200 Subject: [PATCH 16/17] update refactorings --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 663d283..4698cfe 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 | 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-forgejo/pulls/5 +[split]: https://repo.prod.meissa.de/meissa/c4k-jitsi/commit/d4fb8ca9e2ab44f9f9923d2e09c81a61e44b39b2 [ns]: https://repo.prod.meissa.de/meissa/c4k-keycloak/commit/3639f3d5e6d5b364822a05b3d5d569bbc556a68b ## Development & Mirrors From b37661f155a03ce820cf7c75891e657f11e6ecbe Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Mon, 5 Aug 2024 08:57:16 +0200 Subject: [PATCH 17/17] updated federation --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4698cfe..59efb4c 100644 --- a/README.md +++ b/README.md @@ -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