Breaking-Change: generate-pvc now needs a config.
introduced storage-size & storage-class-name
This commit is contained in:
parent
5464c8428a
commit
4cfe791e85
7 changed files with 66 additions and 12 deletions
|
@ -1,4 +1,4 @@
|
||||||
(defproject org.domaindrivenarchitecture/c4k-common-cljs "1.0.1-SNAPSHOT"
|
(defproject org.domaindrivenarchitecture/c4k-common-cljs "1.1.0-SNAPSHOT"
|
||||||
:description "Contains predicates and tools for c4k"
|
:description "Contains predicates and tools for c4k"
|
||||||
:url "https://domaindrivenarchitecture.org"
|
:url "https://domaindrivenarchitecture.org"
|
||||||
:license {:name "Apache License, Version 2.0"
|
:license {:name "Apache License, Version 2.0"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
(defproject org.domaindrivenarchitecture/c4k-common-clj "1.0.1-SNAPSHOT"
|
(defproject org.domaindrivenarchitecture/c4k-common-clj "1.1.0-SNAPSHOT"
|
||||||
:description "Contains predicates and tools for c4k"
|
:description "Contains predicates and tools for c4k"
|
||||||
:url "https://domaindrivenarchitecture.org"
|
:url "https://domaindrivenarchitecture.org"
|
||||||
:license {:name "Apache License, Version 2.0"
|
:license {:name "Apache License, Version 2.0"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
(ns dda.c4k-common.common
|
(ns dda.c4k-common.common
|
||||||
(:require
|
(:require
|
||||||
[clojure.walk]
|
[clojure.walk]
|
||||||
|
[clojure.spec.alpha :as s]
|
||||||
#?(: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]])
|
||||||
[dda.c4k-common.predicate :as cp]))
|
[dda.c4k-common.predicate :as cp]))
|
||||||
|
@ -50,3 +51,8 @@
|
||||||
value-to-replace
|
value-to-replace
|
||||||
%)
|
%)
|
||||||
coll))
|
coll))
|
||||||
|
|
||||||
|
(defn-spec concat-vec vector?
|
||||||
|
[& vs (s/* seq?)]
|
||||||
|
(into []
|
||||||
|
(apply concat vs)))
|
||||||
|
|
|
@ -22,8 +22,11 @@
|
||||||
(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 ::pv-storage-size-gb pos?)
|
||||||
(defn pg-config? [input]
|
(defn pg-config? [input]
|
||||||
(s/keys :opt-un [::postgres-size ::db-name ::postgres-data-volume-path]))
|
(s/keys :opt-un [::postgres-size ::db-name ::postgres-data-volume-path
|
||||||
|
::pvc-storage-class-name ::pv-storage-size-gb]))
|
||||||
(defn pg-auth? [input]
|
(defn pg-auth? [input]
|
||||||
(s/keys :opt-un [::postgres-db-user ::postgres-db-password]))
|
(s/keys :opt-un [::postgres-db-user ::postgres-db-password]))
|
||||||
|
|
||||||
|
@ -53,7 +56,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]
|
||||||
|
@ -64,14 +67,23 @@
|
||||||
|
|
||||||
(defn-spec generate-persistent-volume cp/map-or-seq?
|
(defn-spec generate-persistent-volume cp/map-or-seq?
|
||||||
[config pg-config?]
|
[config pg-config?]
|
||||||
(let [{:keys [postgres-data-volume-path]} config]
|
(let [{:keys [postgres-data-volume-path pv-storage-size-gb]
|
||||||
|
:or {postgres-data-volume-path "/var/postgres"
|
||||||
|
pv-storage-size-gb 10}} config]
|
||||||
(->
|
(->
|
||||||
(yaml/from-string (yaml/load-resource "postgres/persistent-volume.yaml"))
|
(yaml/from-string (yaml/load-resource "postgres/persistent-volume.yaml"))
|
||||||
(assoc-in [:spec :hostPath :path] postgres-data-volume-path))))
|
(assoc-in [:spec :hostPath :path] postgres-data-volume-path)
|
||||||
|
(assoc-in [:spec :capacity :storage] (str pv-storage-size-gb "Gi")))))
|
||||||
|
|
||||||
(defn-spec generate-pvc cp/map-or-seq?
|
(defn-spec generate-pvc cp/map-or-seq?
|
||||||
[]
|
[config pg-config?]
|
||||||
(yaml/from-string (yaml/load-resource "postgres/pvc.yaml")))
|
(let [{:keys [pv-storage-size-gb pvc-storage-class-name]
|
||||||
|
:or {pv-storage-size-gb 10
|
||||||
|
pvc-storage-class-name :manual}} config]
|
||||||
|
(->
|
||||||
|
(yaml/from-string (yaml/load-resource "postgres/pvc.yaml"))
|
||||||
|
(assoc-in [:spec :resources :requests :storage] (str pv-storage-size-gb "Gi"))
|
||||||
|
(assoc-in [:spec :storageClassName] (name pvc-storage-class-name)))))
|
||||||
|
|
||||||
(defn-spec generate-secret cp/map-or-seq?
|
(defn-spec generate-secret cp/map-or-seq?
|
||||||
[my-auth any?]
|
[my-auth any?]
|
||||||
|
|
|
@ -16,4 +16,8 @@
|
||||||
|
|
||||||
(defn map-or-seq?
|
(defn map-or-seq?
|
||||||
[input]
|
[input]
|
||||||
(or (map? input) (seq? input)))
|
(or (map? input) (seq? input)))
|
||||||
|
|
||||||
|
(defn pvc-storage-class-name?
|
||||||
|
[input]
|
||||||
|
(contains? #{:manual :local-path} input))
|
|
@ -5,9 +5,9 @@ metadata:
|
||||||
labels:
|
labels:
|
||||||
app: postgres
|
app: postgres
|
||||||
spec:
|
spec:
|
||||||
storageClassName: manual
|
storageClassName: REPLACEME
|
||||||
accessModes:
|
accessModes:
|
||||||
- ReadWriteOnce
|
- ReadWriteOnce
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
storage: 10Gi
|
storage: REPLACEME
|
|
@ -37,7 +37,39 @@
|
||||||
:accessModes ["ReadWriteOnce"]
|
:accessModes ["ReadWriteOnce"]
|
||||||
:capacity {:storage "10Gi"}
|
:capacity {:storage "10Gi"}
|
||||||
:hostPath {:path "xx"}}}
|
:hostPath {:path "xx"}}}
|
||||||
(cut/generate-persistent-volume {:postgres-data-volume-path "xx"}))))
|
(cut/generate-persistent-volume {:postgres-data-volume-path "xx"})))
|
||||||
|
(is (= {:kind "PersistentVolume"
|
||||||
|
:apiVersion "v1"
|
||||||
|
:metadata
|
||||||
|
{:name "postgres-pv-volume", :labels {:type "local"}}
|
||||||
|
:spec
|
||||||
|
{:storageClassName "manual"
|
||||||
|
:accessModes ["ReadWriteOnce"]
|
||||||
|
:capacity {:storage "20Gi"}
|
||||||
|
:hostPath {:path "xx"}}}
|
||||||
|
(cut/generate-persistent-volume {:postgres-data-volume-path "xx"
|
||||||
|
:pv-storage-size-gb 20}))))
|
||||||
|
|
||||||
|
(deftest should-generate-persistent-volume-claim
|
||||||
|
(is (= {:apiVersion "v1"
|
||||||
|
:kind "PersistentVolumeClaim"
|
||||||
|
:metadata
|
||||||
|
{:name "postgres-claim", :labels {:app "postgres"}}
|
||||||
|
:spec
|
||||||
|
{:storageClassName "manual"
|
||||||
|
:accessModes ["ReadWriteOnce"]
|
||||||
|
:resources {:requests {:storage "10Gi"}}}}
|
||||||
|
(cut/generate-pvc {})))
|
||||||
|
(is (= {:apiVersion "v1"
|
||||||
|
:kind "PersistentVolumeClaim"
|
||||||
|
:metadata
|
||||||
|
{:name "postgres-claim", :labels {:app "postgres"}}
|
||||||
|
:spec
|
||||||
|
{:storageClassName "local-path"
|
||||||
|
:accessModes ["ReadWriteOnce"]
|
||||||
|
:resources {:requests {:storage "20Gi"}}}}
|
||||||
|
(cut/generate-pvc {:pv-storage-size-gb 20
|
||||||
|
:pvc-storage-class-name :local-path}))))
|
||||||
|
|
||||||
(deftest should-generate-secret
|
(deftest should-generate-secret
|
||||||
(is (= {:apiVersion "v1"
|
(is (= {:apiVersion "v1"
|
||||||
|
|
Loading…
Reference in a new issue