fix macro issue

This commit is contained in:
Michael Jerger 2024-02-28 09:59:28 +01:00
parent 552dcbd1d8
commit 7469fc1cd4
7 changed files with 79 additions and 34 deletions

View file

@ -1,14 +1,25 @@
(ns dda.c4k-common.ingress.ingress-internal
(:require
[clojure.spec.alpha :as s]
#?(:cljs [shadow.resource :as rc])
#?(:clj [orchestra.core :refer [defn-spec]]
:cljs [orchestra.core :refer-macros [defn-spec]])
#?(:cljs [dda.c4k-common.macros :refer-macros [inline-resources]])
[dda.c4k-common.yaml :as yaml]
[dda.c4k-common.common :as cm]
[dda.c4k-common.namespace :as ns]
[dda.c4k-common.predicate :as pred]))
#?(:cljs
(defmethod yaml/load-resource :ingress [resource-name]
(case resource-name
"ingress/certificate.yaml" (rc/inline "ingress/certificate.yaml")
"ingress/host-rule.yaml" (rc/inline "ingress/host-rule.yaml")
"ingress/ingress.yaml" (rc/inline "ingress/ingress.yaml")
"ingress/middleware-ratelimit.yaml" (rc/inline "ingress/middleware-ratelimit.yaml")
(throw (js/Error. (str "Undefined Resource: " resource-name))))))
(s/def ::issuer pred/letsencrypt-issuer?)
(s/def ::service-name string?)
(s/def ::app-name string?)
@ -17,6 +28,7 @@
(s/def ::service-port pos-int?)
(s/def ::fqdns (s/coll-of pred/fqdn-string?))
(s/def ::average-rate pos-int?)
(s/def ::burst-rate pos-int?)
(def ingress? (s/keys :req-un [::ingress-name ::app-name
@ -28,6 +40,7 @@
(def certificate? (s/keys :req-un [::fqdns ::app-name ::cert-name ::issuer ::ns/namespace]))
(def rate-limit-config? (s/keys :req-un [::rate-limit-name ::average-rate ::burst-rate]))
@ -87,9 +100,4 @@
(assoc-in [:spec :tls 0 :secretName] cert-name)
(assoc-in [:spec :tls 0 :hosts] fqdns)
(assoc-in [:spec :rules]
(mapv (partial generate-host-rule service-name service-port) fqdns)))))
#?(:cljs
(defmethod yaml/load-resource :ingress [resource-name]
(get (inline-resources "ingress") resource-name)))
(mapv (partial generate-host-rule service-name service-port) fqdns)))))

View file

@ -5,4 +5,5 @@
(let [files (.listFiles (io/file (io/resource resource-path)))
file-contents (map slurp files)
file-names (map #(str resource-path "/" (.getName %)) files)]
(zipmap file-names file-contents)))
(zipmap file-names file-contents))
)

View file

@ -1,24 +1,49 @@
(ns dda.c4k-common.monitoring.monitoring-internal
(:require
[clojure.spec.alpha :as s]
#?(:cljs [shadow.resource :as rc])
#?(:clj [orchestra.core :refer [defn-spec]]
:cljs [orchestra.core :refer-macros [defn-spec]])
#?(:cljs [dda.c4k-common.macros :refer-macros [inline-resources]])
[dda.c4k-common.yaml :as yaml]
[dda.c4k-common.predicate :as cp]
[dda.c4k-common.common :as cm]
[clojure.string :as str]))
#?(:cljs
(defmethod yaml/load-resource :monitoring [resource-name]
(case resource-name
"monitoring/kube-state-metrics-cluster-role-binding.yaml" (rc/inline "monitoring/kube-state-metrics-cluster-role-binding.yaml")
"monitoring/kube-state-metrics-cluster-role.yaml" (rc/inline "monitoring/kube-state-metrics-cluster-role.yaml")
"monitoring/kube-state-metrics-deployment.yaml" (rc/inline "monitoring/kube-state-metrics-deployment.yaml")
"monitoring/kube-state-metrics-service-account.yaml" (rc/inline "monitoring/kube-state-metrics-service-account.yaml")
"monitoring/kube-state-metrics-service.yaml" (rc/inline "monitoring/kube-state-metrics-service.yaml")
"monitoring/namespace.yaml" (rc/inline "monitoring/namespace.yaml")
"monitoring/node-exporter-cluster-role-binding.yaml" (rc/inline "monitoring/node-exporter-cluster-role-binding.yaml")
"monitoring/node-exporter-cluster-role.yaml" (rc/inline "monitoring/node-exporter-cluster-role.yaml")
"monitoring/node-exporter-daemon-set.yaml" (rc/inline "monitoring/node-exporter-daemon-set.yaml")
"monitoring/node-exporter-service-account.yaml" (rc/inline "monitoring/node-exporter-service-account.yaml")
"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-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")
"monitoring/prometheus-service.yaml" (rc/inline "monitoring/prometheus-service.yaml")
(throw (js/Error. (str "Undefined Resource: " resource-name))))))
(s/def ::grafana-cloud-user cp/bash-env-string?)
(s/def ::grafana-cloud-password cp/bash-env-string?)
(s/def ::grafana-cloud-url string?)
(s/def ::cluster-name string?)
(s/def ::cluster-stage cp/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 metric-regex {:node-regex
(str "node_cpu_sec.+|node_load[0-9]+|node_memory_Buf.*|node_memory_Mem.*|"
@ -65,7 +90,3 @@
(assoc-in [:stringData :prometheus.yaml]
(yaml/to-string
(generate-prometheus-config config auth)))))
#?(:cljs
(defmethod yaml/load-resource :monitoring [resource-name]
(get (inline-resources "monitoring") resource-name)))

View file

@ -1,11 +1,19 @@
(ns dda.c4k-common.namespace.namespace-internal
(:require
[clojure.spec.alpha :as s]
#?(:cljs [shadow.resource :as rc])
#?(:clj [orchestra.core :refer [defn-spec]]
:cljs [orchestra.core :refer-macros [defn-spec]])
#?(:cljs [dda.c4k-common.macros :refer-macros [inline-resources]])
[dda.c4k-common.yaml :as yaml]))
#?(:cljs
(defmethod yaml/load-resource :namespace [resource-name]
(case resource-name
"namespace/namespace.yaml" (rc/inline "namespace/namespace.yaml")
(throw (js/Error. (str "Undefined Resource: " resource-name))))))
(s/def ::namespace string?)
(def config? (s/keys :req-un [::namespace]
@ -16,8 +24,4 @@
(let [{:keys [namespace]} config]
(->
(yaml/load-as-edn "namespace/namespace.yaml")
(assoc-in [:metadata :name] namespace))))
#?(:cljs
(defmethod yaml/load-resource :namespace [resource-name]
(get (inline-resources "namespace") resource-name)))
(assoc-in [:metadata :name] namespace))))

View file

@ -1,15 +1,31 @@
(ns dda.c4k-common.postgres.postgres-internal
(:require
[clojure.spec.alpha :as s]
#?(:cljs [shadow.resource :as rc])
#?(:clj [orchestra.core :refer [defn-spec]]
:cljs [orchestra.core :refer-macros [defn-spec]])
#?(:cljs [dda.c4k-common.macros :refer-macros [inline-resources]])
[dda.c4k-common.yaml :as yaml]
[dda.c4k-common.base64 :as b64]
[dda.c4k-common.predicate :as cp]
[dda.c4k-common.common :as cm]
[dda.c4k-common.namespace :as ns]))
#?(:cljs
(defmethod yaml/load-resource :postgres [resource-name]
(case resource-name
"postgres/config-2gb.yaml" (rc/inline "postgres/config-2gb.yaml")
"postgres/config-4gb.yaml" (rc/inline "postgres/config-4gb.yaml")
"postgres/config-8gb.yaml" (rc/inline "postgres/config-8gb.yaml")
"postgres/config-16gb.yaml" (rc/inline "postgres/config-16gb.yaml")
"postgres/deployment.yaml" (rc/inline "postgres/deployment.yaml")
"postgres/persistent-volume.yaml" (rc/inline "postgres/persistent-volume.yaml")
"postgres/pvc.yaml" (rc/inline "postgres/pvc.yaml")
"postgres/secret.yaml" (rc/inline "postgres/secret.yaml")
"postgres/service.yaml" (rc/inline "postgres/service.yaml")
(throw (js/Error. (str "Undefined Resource: " resource-name))))))
(defn postgres-size?
[input]
(contains? #{:2gb :4gb :8gb :16gb} input))
@ -17,21 +33,22 @@
(defn postgres-image?
[input]
(contains? #{"postgres:13" "postgres:14" "postgres:15" "postgres:16"} input))
(s/def ::postgres-db-user cp/bash-env-string?)
(s/def ::postgres-db-password cp/bash-env-string?)
(s/def ::postgres-data-volume-path string?)
(s/def ::postgres-size postgres-size?)
(s/def ::db-name cp/bash-env-string?)
(s/def ::pvc-storage-class-name cp/pvc-storage-class-name?)
(s/def ::pv-storage-size-gb pos?)
(s/def ::pv-storage-size-gb pos?)
(def pg-config?
(s/keys :req-un [::postgres-size ::db-name ::postgres-data-volume-path
::pvc-storage-class-name ::pv-storage-size-gb ::ns/namespace]))
(def pg-auth?
(s/keys :req-un [::postgres-db-user ::postgres-db-password]))
(def postgres-function (s/keys :opt-un [::deserializer ::optional]))
@ -92,8 +109,3 @@
(->
(yaml/from-string (yaml/load-resource "postgres/service.yaml"))
(assoc-in [:metadata :namespace] namespace))))
#?(:cljs
(defmethod yaml/load-resource :postgres [resource-name]
(get (inline-resources "postgres") resource-name)))

View file

@ -3,7 +3,6 @@
["js-yaml" :as yaml]
[clojure.string :as st]
[orchestra.core :refer-macros [defn-spec]]
[shadow.resource :as rc]
[dda.c4k-common.predicate :as cp]))
(defn string-or-keyword? [input]

View file

@ -4,10 +4,10 @@
[dda.c4k-common.macros :refer [inline-resources]]))
(deftest should-count-inline-resources
(is (= 4 (count (inline-resources "ingress")))))
(is (= 3 (count (inline-resources "dda/c4k_common/inline_resources_test")))))
(deftest should-inline-resources
(let [resource-path (fn [name] (str "dda/c4k_common/inline_resources_test/" name))]
(is (= "1" (get (inline-resources "dda/c4k_common/inline_resources_test") (resource-path "inline_resource_1.yaml"))))
(is (= "2" (get (inline-resources "dda/c4k_common/inline_resources_test") (resource-path "inline_resource_2.yaml"))))
(is (= "3" (get (inline-resources "dda/c4k_common/inline_resources_test") (resource-path "inline_resource_3.yaml"))))))
(is (= "3" (get (inline-resources "dda/c4k_common/inline_resources_test") (resource-path "inline_resource_3.yaml"))))))