Compare commits
2 commits
fe43c0ec58
...
73e2ebd12f
Author | SHA1 | Date | |
---|---|---|---|
73e2ebd12f | |||
866ef84f12 |
5 changed files with 62 additions and 33 deletions
|
@ -48,27 +48,7 @@
|
|||
|
||||
#?(:cljs
|
||||
(defmethod yaml/load-resource :monitoring [resource-name]
|
||||
(case resource-name
|
||||
"monitoring/namespace.yaml" (rc/inline "monitoring/namespace.yaml")
|
||||
|
||||
"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/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. "Undefined Resource!")))))
|
||||
(get (inline-resources "monitoring") resource-name)))
|
||||
|
||||
(defn-spec generate-stateful-set cp/map-or-seq?
|
||||
[config ::storage]
|
||||
|
|
19
src/main/cljc/dda/c4k_common/namespace.cljc
Normal file
19
src/main/cljc/dda/c4k_common/namespace.cljc
Normal file
|
@ -0,0 +1,19 @@
|
|||
(ns dda.c4k-common.namespace
|
||||
(:require
|
||||
#?(:clj [orchestra.core :refer [defn-spec]]
|
||||
:cljs [orchestra.core :refer-macros [defn-spec]])
|
||||
[clojure.spec.alpha :as s]
|
||||
[dda.c4k-common.namespace.namespace-internal :as int]))
|
||||
|
||||
(s/def ::namespace ::int/namespace)
|
||||
|
||||
(def config? (s/keys :req-un []
|
||||
:opt-un [::namespace]))
|
||||
|
||||
(def default-config {:namespace "default"})
|
||||
|
||||
(defn-spec generate seq?
|
||||
[config config?]
|
||||
(let [final-config (merge default-config
|
||||
config)]
|
||||
[(int/generate-namespace final-config)]))
|
|
@ -0,0 +1,23 @@
|
|||
(ns dda.c4k-common.namespace.namespace-internal
|
||||
(:require
|
||||
[clojure.spec.alpha :as s]
|
||||
#?(: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]))
|
||||
|
||||
(s/def ::namespace string?)
|
||||
|
||||
(def config? (s/keys :req-un [::namespace]
|
||||
:opt-un []))
|
||||
|
||||
(defn-spec generate-namespace map?
|
||||
[config config?]
|
||||
(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)))
|
|
@ -35,17 +35,7 @@
|
|||
|
||||
#?(: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. "Undefined Resource!")))))
|
||||
(get (inline-resources "postgres") resource-name)))
|
||||
|
||||
(defn-spec generate-config cp/map-or-seq?
|
||||
[& config (s/? pg-config?)]
|
||||
|
@ -57,7 +47,6 @@
|
|||
(str "postgres/config-" (name postgres-size) ".yaml")))
|
||||
(assoc-in [:data :postgres-db] db-name))))
|
||||
|
||||
; TODO: why do we need a sequence of configs?
|
||||
(defn-spec generate-deployment cp/map-or-seq?
|
||||
[& config (s/? pg-config?)]
|
||||
(let [{:keys [postgres-image]
|
||||
|
|
18
src/test/cljc/dda/c4k_common/namespace_test.cljc
Normal file
18
src/test/cljc/dda/c4k_common/namespace_test.cljc
Normal file
|
@ -0,0 +1,18 @@
|
|||
(ns dda.c4k-common.namespace-test
|
||||
(:require
|
||||
#?(:clj [clojure.test :refer [deftest is are testing run-tests]]
|
||||
:cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
|
||||
[clojure.spec.test.alpha :as st]
|
||||
[dda.c4k-common.namespace :as cut]))
|
||||
|
||||
(st/instrument `cut/generate)
|
||||
|
||||
(deftest should-generate-simple-ingress
|
||||
(is (= [{:apiVersion "v1"
|
||||
:kind "Namespace"
|
||||
:metadata {:name "default"}}]
|
||||
(cut/generate {})))
|
||||
(is (= [{:apiVersion "v1"
|
||||
:kind "Namespace"
|
||||
:metadata {:name "myapp"}}]
|
||||
(cut/generate {:namespace "myapp"}))))
|
Loading…
Reference in a new issue