Refactor spec definitions as spec keywords.
This commit is contained in:
parent
e827b6113d
commit
dc23ef15cc
2 changed files with 19 additions and 20 deletions
|
@ -18,16 +18,15 @@
|
||||||
(s/def ::node-regex string?)
|
(s/def ::node-regex string?)
|
||||||
(s/def ::traefik-regex string?)
|
(s/def ::traefik-regex string?)
|
||||||
(s/def ::kube-state-regex string?)
|
(s/def ::kube-state-regex string?)
|
||||||
|
(s/def ::config (s/keys :req-un [::grafana-cloud-url
|
||||||
(def config? (s/keys :req-un [::grafana-cloud-url
|
|
||||||
::cluster-name
|
::cluster-name
|
||||||
::cluster-stage]))
|
::cluster-stage]))
|
||||||
|
(s/def ::auth (s/keys :req-un [::grafana-cloud-user
|
||||||
(def auth? (s/keys :req-un [::grafana-cloud-user ::grafana-cloud-password]))
|
::grafana-cloud-password]))
|
||||||
|
(s/def ::storage (s/keys :opt-un [::pvc-storage-class-name]))
|
||||||
(def storage? (s/keys :opt-un [::pvc-storage-class-name]))
|
(s/def ::filter-regex (s/keys :req-un [::node-regex
|
||||||
|
::traefik-regex
|
||||||
(def filter-regex? (s/keys :req-un [::node-regex ::traefik-regex ::kube-state-regex]))
|
::kube-state-regex]))
|
||||||
|
|
||||||
(def metric-regex {:node-regex
|
(def metric-regex {:node-regex
|
||||||
(str "node_cpu_sec.+|node_load[0-9]+|node_memory_Buf.*|node_memory_Mem.*|"
|
(str "node_cpu_sec.+|node_load[0-9]+|node_memory_Buf.*|node_memory_Mem.*|"
|
||||||
|
@ -72,7 +71,7 @@
|
||||||
(throw (js/Error. "Undefined Resource!")))))
|
(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]
|
||||||
(let [{:keys [pvc-storage-class-name]
|
(let [{:keys [pvc-storage-class-name]
|
||||||
:or {pvc-storage-class-name :manual}} config]
|
:or {pvc-storage-class-name :manual}} config]
|
||||||
(->
|
(->
|
||||||
|
@ -80,8 +79,8 @@
|
||||||
(assoc-in [:spec :volumeClaimTemplates 0 :spec :storageClassName] (name pvc-storage-class-name)))))
|
(assoc-in [:spec :volumeClaimTemplates 0 :spec :storageClassName] (name pvc-storage-class-name)))))
|
||||||
|
|
||||||
(defn-spec generate-prometheus-config cp/map-or-seq?
|
(defn-spec generate-prometheus-config cp/map-or-seq?
|
||||||
[config config?
|
[config ::config
|
||||||
auth auth?]
|
auth ::auth]
|
||||||
(let [{:keys [grafana-cloud-url cluster-name cluster-stage]} config
|
(let [{:keys [grafana-cloud-url cluster-name cluster-stage]} config
|
||||||
{:keys [grafana-cloud-user grafana-cloud-password]} auth]
|
{:keys [grafana-cloud-user grafana-cloud-password]} auth]
|
||||||
(->
|
(->
|
||||||
|
@ -99,8 +98,8 @@
|
||||||
(cm/replace-all-matching-values-by-new-value "FILTER_REGEX" filter-regex-string))))
|
(cm/replace-all-matching-values-by-new-value "FILTER_REGEX" filter-regex-string))))
|
||||||
|
|
||||||
(defn-spec generate-config cp/map-or-seq?
|
(defn-spec generate-config cp/map-or-seq?
|
||||||
[config config?
|
[config ::config
|
||||||
auth auth?]
|
auth ::auth]
|
||||||
(->
|
(->
|
||||||
(yaml/load-as-edn "monitoring/prometheus/config.yaml")
|
(yaml/load-as-edn "monitoring/prometheus/config.yaml")
|
||||||
(assoc-in [:stringData :prometheus.yaml]
|
(assoc-in [:stringData :prometheus.yaml]
|
||||||
|
@ -108,8 +107,8 @@
|
||||||
(generate-prometheus-config config auth)))))
|
(generate-prometheus-config config auth)))))
|
||||||
|
|
||||||
(defn-spec generate cp/map-or-seq?
|
(defn-spec generate cp/map-or-seq?
|
||||||
[config config?
|
[config ::config
|
||||||
auth auth?]
|
auth ::auth]
|
||||||
[(yaml/load-as-edn "monitoring/namespace.yaml")
|
[(yaml/load-as-edn "monitoring/namespace.yaml")
|
||||||
(yaml/load-as-edn "monitoring/prometheus/cluster-role.yaml")
|
(yaml/load-as-edn "monitoring/prometheus/cluster-role.yaml")
|
||||||
(yaml/load-as-edn "monitoring/prometheus/cluster-role-binding.yaml")
|
(yaml/load-as-edn "monitoring/prometheus/cluster-role-binding.yaml")
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
(st/instrument `cut/generate-config)
|
(st/instrument `cut/generate-config)
|
||||||
|
|
||||||
(def conf {:cluster-name "clustername"
|
(def conf {:cluster-name "clustername"
|
||||||
:cluster-stage :test
|
:cluster-stage "test"
|
||||||
:grafana-cloud-url "https://some.url/with/path"})
|
:grafana-cloud-url "https://some.url/with/path"})
|
||||||
|
|
||||||
(def auth {:grafana-cloud-user "user"
|
(def auth {:grafana-cloud-user "user"
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
:hetzner-cloud-ro-token "ro-token"})
|
:hetzner-cloud-ro-token "ro-token"})
|
||||||
|
|
||||||
(def invalid-conf {:cluster-name "clustername"
|
(def invalid-conf {:cluster-name "clustername"
|
||||||
:cluster-stage :test
|
:cluster-stage "test"
|
||||||
:grafana-clud-url "https://some.url/with/path"})
|
:grafana-clud-url "https://some.url/with/path"})
|
||||||
|
|
||||||
(def invalid-auth {:grafana-cloud-user "user"
|
(def invalid-auth {:grafana-cloud-user "user"
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
|
|
||||||
(deftest should-generate-prometheus-external-labels
|
(deftest should-generate-prometheus-external-labels
|
||||||
(is (= {:cluster "clustername",
|
(is (= {:cluster "clustername",
|
||||||
:stage :test}
|
:stage "test"}
|
||||||
(get-in
|
(get-in
|
||||||
(cut/generate-prometheus-config conf auth)
|
(cut/generate-prometheus-config conf auth)
|
||||||
[:global :external_labels]))))
|
[:global :external_labels]))))
|
||||||
|
|
Loading…
Reference in a new issue