diff --git a/src/main/cljc/dda/c4k_common/ingress/ingress_internal.cljc b/src/main/cljc/dda/c4k_common/ingress/ingress_internal.cljc index e725029..606cfb6 100644 --- a/src/main/cljc/dda/c4k_common/ingress/ingress_internal.cljc +++ b/src/main/cljc/dda/c4k_common/ingress/ingress_internal.cljc @@ -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))))) \ No newline at end of file diff --git a/src/main/cljc/dda/c4k_common/macros.clj b/src/main/cljc/dda/c4k_common/macros.cljc similarity index 86% rename from src/main/cljc/dda/c4k_common/macros.clj rename to src/main/cljc/dda/c4k_common/macros.cljc index 22133b1..f53459a 100644 --- a/src/main/cljc/dda/c4k_common/macros.clj +++ b/src/main/cljc/dda/c4k_common/macros.cljc @@ -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)) + ) 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 023e027..365cb7a 100644 --- a/src/main/cljc/dda/c4k_common/monitoring/monitoring_internal.cljc +++ b/src/main/cljc/dda/c4k_common/monitoring/monitoring_internal.cljc @@ -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))) diff --git a/src/main/cljc/dda/c4k_common/namespace/namespace_internal.cljc b/src/main/cljc/dda/c4k_common/namespace/namespace_internal.cljc index 5476596..284a643 100644 --- a/src/main/cljc/dda/c4k_common/namespace/namespace_internal.cljc +++ b/src/main/cljc/dda/c4k_common/namespace/namespace_internal.cljc @@ -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))) \ No newline at end of file + (assoc-in [:metadata :name] namespace)))) \ No newline at end of file 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 7fa3442..ad4c253 100644 --- a/src/main/cljc/dda/c4k_common/postgres/postgres_internal.cljc +++ b/src/main/cljc/dda/c4k_common/postgres/postgres_internal.cljc @@ -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))) diff --git a/src/main/cljs/dda/c4k_common/yaml.cljs b/src/main/cljs/dda/c4k_common/yaml.cljs index 14e1408..db05f63 100644 --- a/src/main/cljs/dda/c4k_common/yaml.cljs +++ b/src/main/cljs/dda/c4k_common/yaml.cljs @@ -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] diff --git a/src/test/clj/dda/c4k_common/macros_test.clj b/src/test/clj/dda/c4k_common/macros_test.clj index 1f02711..f6f205e 100644 --- a/src/test/clj/dda/c4k_common/macros_test.clj +++ b/src/test/clj/dda/c4k_common/macros_test.clj @@ -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")))))) \ No newline at end of file + (is (= "3" (get (inline-resources "dda/c4k_common/inline_resources_test") (resource-path "inline_resource_3.yaml"))))))