|
|
@ -1,15 +1,31 @@
|
|
|
|
(ns dda.c4k-common.postgres.postgres-internal
|
|
|
|
(ns dda.c4k-common.postgres.postgres-internal
|
|
|
|
(:require
|
|
|
|
(:require
|
|
|
|
[clojure.spec.alpha :as s]
|
|
|
|
[clojure.spec.alpha :as s]
|
|
|
|
|
|
|
|
#?(:cljs [shadow.resource :as rc])
|
|
|
|
#?(: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]])
|
|
|
|
#?(:cljs [dda.c4k-common.macros :refer-macros [inline-resources]])
|
|
|
|
|
|
|
|
[dda.c4k-common.yaml :as yaml]
|
|
|
|
[dda.c4k-common.yaml :as yaml]
|
|
|
|
[dda.c4k-common.base64 :as b64]
|
|
|
|
[dda.c4k-common.base64 :as b64]
|
|
|
|
[dda.c4k-common.predicate :as cp]
|
|
|
|
[dda.c4k-common.predicate :as cp]
|
|
|
|
[dda.c4k-common.common :as cm]
|
|
|
|
[dda.c4k-common.common :as cm]
|
|
|
|
[dda.c4k-common.namespace :as ns]))
|
|
|
|
[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?
|
|
|
|
(defn postgres-size?
|
|
|
|
[input]
|
|
|
|
[input]
|
|
|
|
(contains? #{:2gb :4gb :8gb :16gb} input))
|
|
|
|
(contains? #{:2gb :4gb :8gb :16gb} input))
|
|
|
@ -17,21 +33,22 @@
|
|
|
|
(defn postgres-image?
|
|
|
|
(defn postgres-image?
|
|
|
|
[input]
|
|
|
|
[input]
|
|
|
|
(contains? #{"postgres:13" "postgres:14" "postgres:15" "postgres:16"} input))
|
|
|
|
(contains? #{"postgres:13" "postgres:14" "postgres:15" "postgres:16"} input))
|
|
|
|
|
|
|
|
|
|
|
|
(s/def ::postgres-db-user cp/bash-env-string?)
|
|
|
|
(s/def ::postgres-db-user cp/bash-env-string?)
|
|
|
|
(s/def ::postgres-db-password cp/bash-env-string?)
|
|
|
|
(s/def ::postgres-db-password cp/bash-env-string?)
|
|
|
|
(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 ::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?
|
|
|
|
(def pg-config?
|
|
|
|
(s/keys :req-un [::postgres-size ::db-name ::postgres-data-volume-path
|
|
|
|
(s/keys :req-un [::postgres-size ::db-name ::postgres-data-volume-path
|
|
|
|
::pvc-storage-class-name ::pv-storage-size-gb ::ns/namespace]))
|
|
|
|
::pvc-storage-class-name ::pv-storage-size-gb ::ns/namespace]))
|
|
|
|
|
|
|
|
|
|
|
|
(def pg-auth?
|
|
|
|
(def pg-auth?
|
|
|
|
(s/keys :req-un [::postgres-db-user ::postgres-db-password]))
|
|
|
|
(s/keys :req-un [::postgres-db-user ::postgres-db-password]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(def postgres-function (s/keys :opt-un [::deserializer ::optional]))
|
|
|
|
(def postgres-function (s/keys :opt-un [::deserializer ::optional]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -92,8 +109,3 @@
|
|
|
|
(->
|
|
|
|
(->
|
|
|
|
(yaml/from-string (yaml/load-resource "postgres/service.yaml"))
|
|
|
|
(yaml/from-string (yaml/load-resource "postgres/service.yaml"))
|
|
|
|
(assoc-in [:metadata :namespace] namespace))))
|
|
|
|
(assoc-in [:metadata :namespace] namespace))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#?(:cljs
|
|
|
|
|
|
|
|
(defmethod yaml/load-resource :postgres [resource-name]
|
|
|
|
|
|
|
|
(get (inline-resources "postgres") resource-name)))
|
|
|
|
|
|
|
|