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 (ns dda.c4k-common.ingress.ingress-internal
(:require (:require
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
#?(:cljs [shadow.resource :as rc])
#?(:clj [orchestra.core :refer [defn-spec]] #?(:clj [orchestra.core :refer [defn-spec]]
:cljs [orchestra.core :refer-macros [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.yaml :as yaml]
[dda.c4k-common.common :as cm] [dda.c4k-common.common :as cm]
[dda.c4k-common.namespace :as ns] [dda.c4k-common.namespace :as ns]
[dda.c4k-common.predicate :as pred])) [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 ::issuer pred/letsencrypt-issuer?)
(s/def ::service-name string?) (s/def ::service-name string?)
(s/def ::app-name string?) (s/def ::app-name string?)
@ -17,6 +28,7 @@
(s/def ::service-port pos-int?) (s/def ::service-port pos-int?)
(s/def ::fqdns (s/coll-of pred/fqdn-string?)) (s/def ::fqdns (s/coll-of pred/fqdn-string?))
(s/def ::average-rate pos-int?) (s/def ::average-rate pos-int?)
(s/def ::burst-rate pos-int?) (s/def ::burst-rate pos-int?)
(def ingress? (s/keys :req-un [::ingress-name ::app-name (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 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])) (def rate-limit-config? (s/keys :req-un [::rate-limit-name ::average-rate ::burst-rate]))
@ -88,8 +101,3 @@
(assoc-in [:spec :tls 0 :hosts] fqdns) (assoc-in [:spec :tls 0 :hosts] fqdns)
(assoc-in [:spec :rules] (assoc-in [:spec :rules]
(mapv (partial generate-host-rule service-name service-port) fqdns))))) (mapv (partial generate-host-rule service-name service-port) fqdns)))))
#?(:cljs
(defmethod yaml/load-resource :ingress [resource-name]
(get (inline-resources "ingress") resource-name)))

View file

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

View file

@ -1,14 +1,39 @@
(ns dda.c4k-common.monitoring.monitoring-internal (ns dda.c4k-common.monitoring.monitoring-internal
(:require (:require
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
#?(:cljs [shadow.resource :as rc])
#?(:clj [orchestra.core :refer [defn-spec]] #?(:clj [orchestra.core :refer [defn-spec]]
:cljs [orchestra.core :refer-macros [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.yaml :as yaml]
[dda.c4k-common.predicate :as cp] [dda.c4k-common.predicate :as cp]
[dda.c4k-common.common :as cm] [dda.c4k-common.common :as cm]
[clojure.string :as str])) [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-user cp/bash-env-string?)
(s/def ::grafana-cloud-password cp/bash-env-string?) (s/def ::grafana-cloud-password cp/bash-env-string?)
(s/def ::grafana-cloud-url string?) (s/def ::grafana-cloud-url string?)
@ -65,7 +90,3 @@
(assoc-in [:stringData :prometheus.yaml] (assoc-in [:stringData :prometheus.yaml]
(yaml/to-string (yaml/to-string
(generate-prometheus-config config auth))))) (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 (ns dda.c4k-common.namespace.namespace-internal
(:require (:require
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
#?(:cljs [shadow.resource :as rc])
#?(:clj [orchestra.core :refer [defn-spec]] #?(:clj [orchestra.core :refer [defn-spec]]
:cljs [orchestra.core :refer-macros [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.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?) (s/def ::namespace string?)
(def config? (s/keys :req-un [::namespace] (def config? (s/keys :req-un [::namespace]
@ -17,7 +25,3 @@
(-> (->
(yaml/load-as-edn "namespace/namespace.yaml") (yaml/load-as-edn "namespace/namespace.yaml")
(assoc-in [:metadata :name] namespace)))) (assoc-in [:metadata :name] namespace))))
#?(:cljs
(defmethod yaml/load-resource :namespace [resource-name]
(get (inline-resources "namespace") resource-name)))

View file

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

View file

@ -4,7 +4,7 @@
[dda.c4k-common.macros :refer [inline-resources]])) [dda.c4k-common.macros :refer [inline-resources]]))
(deftest should-count-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 (deftest should-inline-resources
(let [resource-path (fn [name] (str "dda/c4k_common/inline_resources_test/" name))] (let [resource-path (fn [name] (str "dda/c4k_common/inline_resources_test/" name))]