Remove storage logic
This commit is contained in:
parent
915b97b63f
commit
03d4f4f7ca
6 changed files with 17 additions and 52 deletions
BIN
doc/tryItOut.png
BIN
doc/tryItOut.png
Binary file not shown.
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 41 KiB |
|
@ -7,4 +7,4 @@
|
||||||
|
|
||||||
|
|
||||||
(defn -main [& cmd-args]
|
(defn -main [& cmd-args]
|
||||||
(uberjar/main-common "c4k-website" website/config? website/auth? website/config-defaults core/k8s-objects cmd-args))
|
(uberjar/main-common "c4k-website" website/config? website/auth? core/config-defaults core/k8s-objects cmd-args))
|
||||||
|
|
|
@ -13,9 +13,6 @@
|
||||||
(def auth? (s/keys :req-un [::website/authtoken
|
(def auth? (s/keys :req-un [::website/authtoken
|
||||||
::website/gitrepourl]))
|
::website/gitrepourl]))
|
||||||
|
|
||||||
(def vol? (s/keys :req-un [::website/volume-total-storage-size
|
|
||||||
::website/number-of-websites]))
|
|
||||||
|
|
||||||
(defn k8s-objects [config]
|
(defn k8s-objects [config]
|
||||||
(cm/concat-vec
|
(cm/concat-vec
|
||||||
(map yaml/to-string
|
(map yaml/to-string
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
(ns dda.c4k-website.website
|
(ns dda.c4k-website.website
|
||||||
(:require
|
(:require
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
#?(:clj [clojure.math.numeric-tower :as m]
|
|
||||||
:cljs [cljs.math :as m])
|
|
||||||
[clojure.string :as st]
|
[clojure.string :as st]
|
||||||
#?(:cljs [shadow.resource :as rc])
|
#?(:cljs [shadow.resource :as rc])
|
||||||
#?(:clj [orchestra.core :refer [defn-spec]]
|
#?(:clj [orchestra.core :refer [defn-spec]]
|
||||||
|
@ -16,24 +14,15 @@
|
||||||
|
|
||||||
(s/def ::fqdn pred/fqdn-string?)
|
(s/def ::fqdn pred/fqdn-string?)
|
||||||
(s/def ::issuer pred/letsencrypt-issuer?)
|
(s/def ::issuer pred/letsencrypt-issuer?)
|
||||||
(s/def ::volume-total-storage-size int?)
|
|
||||||
(s/def ::number-of-websites int?)
|
|
||||||
(s/def ::authtoken pred/bash-env-string?)
|
(s/def ::authtoken pred/bash-env-string?)
|
||||||
(s/def ::gitrepourl pred/bash-env-string?)
|
(s/def ::gitrepourl pred/bash-env-string?)
|
||||||
|
|
||||||
(def config-defaults {:issuer "staging"})
|
|
||||||
|
|
||||||
(def config? (s/keys :req-un [::fqdn]
|
(def config? (s/keys :req-un [::fqdn]
|
||||||
:opt-un [::issuer]))
|
:opt-un [::issuer]))
|
||||||
|
|
||||||
(def auth? (s/keys :req-un [::authtoken ::gitrepourl]))
|
(def auth? (s/keys :req-un [::authtoken ::gitrepourl]))
|
||||||
|
|
||||||
(def vol? (s/keys :req-un [::volume-total-storage-size
|
(def volume-size 3)
|
||||||
::number-of-websites]))
|
|
||||||
|
|
||||||
(defn volume-size-by-total-available-space
|
|
||||||
[total number-of-websites-on-node]
|
|
||||||
(m/floor (/ total number-of-websites-on-node))) ; ToDo: This might be a terrible idea
|
|
||||||
|
|
||||||
(defn unique-name-from-fqdn
|
(defn unique-name-from-fqdn
|
||||||
[fqdn]
|
[fqdn]
|
||||||
|
@ -41,7 +30,7 @@
|
||||||
|
|
||||||
; ToDo: Move to common?
|
; ToDo: Move to common?
|
||||||
(defn-spec replace-all-matching-subvalues-in-string-start pred/map-or-seq?
|
(defn-spec replace-all-matching-subvalues-in-string-start pred/map-or-seq?
|
||||||
[col string?
|
[col string? ;ToDo richtig spec-en
|
||||||
value-to-partly-match string?
|
value-to-partly-match string?
|
||||||
value-to-inplace string?]
|
value-to-inplace string?]
|
||||||
(clojure.walk/postwalk #(if (and (= (type value-to-partly-match) (type %))
|
(clojure.walk/postwalk #(if (and (= (type value-to-partly-match) (type %))
|
||||||
|
@ -110,13 +99,12 @@
|
||||||
(replace-all-matching-subvalues-in-string-start "NAME" (unique-name-from-fqdn fqdn)))))
|
(replace-all-matching-subvalues-in-string-start "NAME" (unique-name-from-fqdn fqdn)))))
|
||||||
|
|
||||||
(defn-spec generate-website-content-volume pred/map-or-seq?
|
(defn-spec generate-website-content-volume pred/map-or-seq?
|
||||||
[config vol?]
|
[config config?]
|
||||||
(let [{:keys [volume-total-storage-size number-of-websites fqdn]} config
|
(let [{:keys [fqdn]} config]
|
||||||
data-storage-size (volume-size-by-total-available-space volume-total-storage-size number-of-websites)]
|
|
||||||
(->
|
(->
|
||||||
(yaml/load-as-edn "website/website-content-volume.yaml")
|
(yaml/load-as-edn "website/website-content-volume.yaml")
|
||||||
(replace-all-matching-subvalues-in-string-start "NAME" (unique-name-from-fqdn fqdn))
|
(replace-all-matching-subvalues-in-string-start "NAME" (unique-name-from-fqdn fqdn))
|
||||||
(cm/replace-all-matching-values-by-new-value "WEBSITESTORAGESIZE" (str (str data-storage-size) "Gi")))))
|
(cm/replace-all-matching-values-by-new-value "WEBSITESTORAGESIZE" (str (str volume-size) "Gi")))))
|
||||||
|
|
||||||
(defn-spec generate-website-build-cron pred/map-or-seq?
|
(defn-spec generate-website-build-cron pred/map-or-seq?
|
||||||
[config config?]
|
[config config?]
|
||||||
|
|
|
@ -30,12 +30,7 @@
|
||||||
"domain"
|
"domain"
|
||||||
(cm/concat-vec
|
(cm/concat-vec
|
||||||
(br/generate-input-field "fqdn" "Your fqdn:" "deineWebsite.de")
|
(br/generate-input-field "fqdn" "Your fqdn:" "deineWebsite.de")
|
||||||
(br/generate-input-field "issuer" "(Optional) Your issuer prod/staging:" "")))
|
(br/generate-input-field "issuer" "(Optional) Your issuer prod/staging:" "")))
|
||||||
(generate-group
|
|
||||||
"provider"
|
|
||||||
(cm/concat-vec
|
|
||||||
(br/generate-input-field "volume-total-storage-size" "Your website volume-total-storage-size:" "20")
|
|
||||||
(br/generate-input-field "number-of-websites" "The Number of websites running on your cluster" "5")))
|
|
||||||
(generate-group
|
(generate-group
|
||||||
"credentials"
|
"credentials"
|
||||||
(br/generate-text-area
|
(br/generate-text-area
|
||||||
|
@ -46,7 +41,7 @@
|
||||||
"3"))
|
"3"))
|
||||||
[(br/generate-br)]
|
[(br/generate-br)]
|
||||||
(br/generate-button "generate-button" "Generate c4k yaml")))]
|
(br/generate-button "generate-button" "Generate c4k yaml")))]
|
||||||
(br/generate-output "c4k-website-output" "Your c4k deployment.yaml:" "25")))
|
(br/generate-output "c4k-website-output" "Your c4k deployment.yaml:" "15")))
|
||||||
|
|
||||||
(defn generate-content-div
|
(defn generate-content-div
|
||||||
[]
|
[]
|
||||||
|
@ -58,18 +53,13 @@
|
||||||
(defn config-from-document []
|
(defn config-from-document []
|
||||||
(let [issuer (br/get-content-from-element "issuer" :optional true)]
|
(let [issuer (br/get-content-from-element "issuer" :optional true)]
|
||||||
(merge
|
(merge
|
||||||
{:fqdn (br/get-content-from-element "fqdn")
|
{:fqdn (br/get-content-from-element "fqdn")}
|
||||||
:volume-total-storage-size (br/get-content-from-element "volume-total-storage-size" :deserializer js/parseInt)
|
|
||||||
:number-of-websites (br/get-content-from-element "number-of-websites" :deserializer js/parseInt)}
|
|
||||||
(when (not (st/blank? issuer))
|
(when (not (st/blank? issuer))
|
||||||
{:issuer issuer})
|
{:issuer issuer}))))
|
||||||
)))
|
|
||||||
|
|
||||||
(defn validate-all! []
|
(defn validate-all! []
|
||||||
(br/validate! "fqdn" ::website/fqdn)
|
(br/validate! "fqdn" ::website/fqdn)
|
||||||
(br/validate! "issuer" ::website/issuer :optional true)
|
(br/validate! "issuer" ::website/issuer :optional true)
|
||||||
(br/validate! "volume-total-storage-size" ::website/volume-total-storage-size :deserializer js/parseInt)
|
|
||||||
(br/validate! "number-of-websites" ::website/number-of-websites :deserializer js/parseInt)
|
|
||||||
(br/validate! "auth" core/auth? :deserializer edn/read-string)
|
(br/validate! "auth" core/auth? :deserializer edn/read-string)
|
||||||
(br/set-form-validated!))
|
(br/set-form-validated!))
|
||||||
|
|
||||||
|
@ -87,11 +77,9 @@
|
||||||
(-> (cm/generate-common
|
(-> (cm/generate-common
|
||||||
(config-from-document)
|
(config-from-document)
|
||||||
(br/get-content-from-element "auth" :deserializer edn/read-string)
|
(br/get-content-from-element "auth" :deserializer edn/read-string)
|
||||||
website/config-defaults
|
core/config-defaults
|
||||||
core/k8s-objects)
|
core/k8s-objects)
|
||||||
(br/set-output!)))))
|
(br/set-output!)))))
|
||||||
(add-validate-listener "fqdn")
|
(add-validate-listener "fqdn")
|
||||||
(add-validate-listener "volume-total-storage-size")
|
|
||||||
(add-validate-listener "issuer")
|
(add-validate-listener "issuer")
|
||||||
(add-validate-listener "number-of-websites")
|
(add-validate-listener "auth"))
|
||||||
(add-validate-listener "auth"))
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
[dda.c4k-common.base64 :as b64]
|
[dda.c4k-common.base64 :as b64]
|
||||||
[dda.c4k-website.website :as cut]))
|
[dda.c4k-website.website :as cut]))
|
||||||
|
|
||||||
|
|
||||||
(st/instrument `cut/generate-certificate)
|
(st/instrument `cut/generate-certificate)
|
||||||
(st/instrument `cut/generate-ingress)
|
(st/instrument `cut/generate-ingress)
|
||||||
(st/instrument `cut/generate-nginx-configmap)
|
(st/instrument `cut/generate-nginx-configmap)
|
||||||
|
@ -148,17 +147,10 @@
|
||||||
:authtoken "token2"
|
:authtoken "token2"
|
||||||
:gitrepourl "test.com/user/repo.git"})))))
|
:gitrepourl "test.com/user/repo.git"})))))
|
||||||
|
|
||||||
|
|
||||||
(deftest should-generate-website-content-volume
|
(deftest should-generate-website-content-volume
|
||||||
(is (= {:storage-c1 "2Gi",
|
(is (= {:name-c1 "test-de-content-volume",
|
||||||
:storage-c2 "10Gi",
|
|
||||||
:name-c1 "test-de-content-volume",
|
|
||||||
:name-c2 "test-com-content-volume",
|
:name-c2 "test-com-content-volume",
|
||||||
:app-c1 "test-de-nginx",
|
:app-c1 "test-de-nginx",
|
||||||
:app-c2 "test-com-nginx"}
|
:app-c2 "test-com-nginx"}
|
||||||
(th/map-diff (cut/generate-website-content-volume {:fqdn "test.de"
|
(th/map-diff (cut/generate-website-content-volume {:fqdn "test.de"})
|
||||||
:volume-total-storage-size 10
|
(cut/generate-website-content-volume {:fqdn "test.com"})))))
|
||||||
:number-of-websites 5})
|
|
||||||
(cut/generate-website-content-volume {:fqdn "test.com"
|
|
||||||
:volume-total-storage-size 50
|
|
||||||
:number-of-websites 5})))))
|
|
||||||
|
|
Loading…
Reference in a new issue