Compare commits

..

No commits in common. "73e2ebd12fc48ef0fda4ddd197f7c84ba8d577da" and "fe43c0ec58bde033f3f5c78d8644984e4083de31" have entirely different histories.

5 changed files with 33 additions and 62 deletions

View file

@ -48,7 +48,27 @@
#?(:cljs #?(:cljs
(defmethod yaml/load-resource :monitoring [resource-name] (defmethod yaml/load-resource :monitoring [resource-name]
(get (inline-resources "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!")))))
(defn-spec generate-stateful-set cp/map-or-seq? (defn-spec generate-stateful-set cp/map-or-seq?
[config ::storage] [config ::storage]

View file

@ -1,19 +0,0 @@
(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)]))

View file

@ -1,23 +0,0 @@
(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)))

View file

@ -35,7 +35,17 @@
#?(:cljs #?(:cljs
(defmethod yaml/load-resource :postgres [resource-name] (defmethod yaml/load-resource :postgres [resource-name]
(get (inline-resources "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!")))))
(defn-spec generate-config cp/map-or-seq? (defn-spec generate-config cp/map-or-seq?
[& config (s/? pg-config?)] [& config (s/? pg-config?)]
@ -47,6 +57,7 @@
(str "postgres/config-" (name postgres-size) ".yaml"))) (str "postgres/config-" (name postgres-size) ".yaml")))
(assoc-in [:data :postgres-db] db-name)))) (assoc-in [:data :postgres-db] db-name))))
; TODO: why do we need a sequence of configs?
(defn-spec generate-deployment cp/map-or-seq? (defn-spec generate-deployment cp/map-or-seq?
[& config (s/? pg-config?)] [& config (s/? pg-config?)]
(let [{:keys [postgres-image] (let [{:keys [postgres-image]

View file

@ -1,18 +0,0 @@
(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"}))))