Remove storage logic

This commit is contained in:
erik 2022-09-30 10:14:10 +02:00
parent 915b97b63f
commit 03d4f4f7ca
6 changed files with 17 additions and 52 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 41 KiB

View file

@ -7,4 +7,4 @@
(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))

View file

@ -13,9 +13,6 @@
(def auth? (s/keys :req-un [::website/authtoken
::website/gitrepourl]))
(def vol? (s/keys :req-un [::website/volume-total-storage-size
::website/number-of-websites]))
(defn k8s-objects [config]
(cm/concat-vec
(map yaml/to-string

View file

@ -1,8 +1,6 @@
(ns dda.c4k-website.website
(:require
[clojure.spec.alpha :as s]
#?(:clj [clojure.math.numeric-tower :as m]
:cljs [cljs.math :as m])
[clojure.spec.alpha :as s]
[clojure.string :as st]
#?(:cljs [shadow.resource :as rc])
#?(:clj [orchestra.core :refer [defn-spec]]
@ -16,24 +14,15 @@
(s/def ::fqdn pred/fqdn-string?)
(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 ::gitrepourl pred/bash-env-string?)
(def config-defaults {:issuer "staging"})
(def config? (s/keys :req-un [::fqdn]
:opt-un [::issuer]))
(def auth? (s/keys :req-un [::authtoken ::gitrepourl]))
(def vol? (s/keys :req-un [::volume-total-storage-size
::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
(def volume-size 3)
(defn unique-name-from-fqdn
[fqdn]
@ -41,7 +30,7 @@
; ToDo: Move to common?
(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-inplace string?]
(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)))))
(defn-spec generate-website-content-volume pred/map-or-seq?
[config vol?]
(let [{:keys [volume-total-storage-size number-of-websites fqdn]} config
data-storage-size (volume-size-by-total-available-space volume-total-storage-size number-of-websites)]
[config config?]
(let [{:keys [fqdn]} config]
(->
(yaml/load-as-edn "website/website-content-volume.yaml")
(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?
[config config?]

View file

@ -30,12 +30,7 @@
"domain"
(cm/concat-vec
(br/generate-input-field "fqdn" "Your fqdn:" "deineWebsite.de")
(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")))
(br/generate-input-field "issuer" "(Optional) Your issuer prod/staging:" "")))
(generate-group
"credentials"
(br/generate-text-area
@ -46,7 +41,7 @@
"3"))
[(br/generate-br)]
(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
[]
@ -58,18 +53,13 @@
(defn config-from-document []
(let [issuer (br/get-content-from-element "issuer" :optional true)]
(merge
{: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)}
{:fqdn (br/get-content-from-element "fqdn")}
(when (not (st/blank? issuer))
{:issuer issuer})
)))
{:issuer issuer}))))
(defn validate-all! []
(br/validate! "fqdn" ::website/fqdn)
(br/validate! "fqdn" ::website/fqdn)
(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/set-form-validated!))
@ -87,11 +77,9 @@
(-> (cm/generate-common
(config-from-document)
(br/get-content-from-element "auth" :deserializer edn/read-string)
website/config-defaults
core/config-defaults
core/k8s-objects)
(br/set-output!)))))
(add-validate-listener "fqdn")
(add-validate-listener "volume-total-storage-size")
(add-validate-listener "issuer")
(add-validate-listener "number-of-websites")
(add-validate-listener "auth"))
(add-validate-listener "auth"))

View file

@ -7,7 +7,6 @@
[dda.c4k-common.base64 :as b64]
[dda.c4k-website.website :as cut]))
(st/instrument `cut/generate-certificate)
(st/instrument `cut/generate-ingress)
(st/instrument `cut/generate-nginx-configmap)
@ -148,17 +147,10 @@
:authtoken "token2"
:gitrepourl "test.com/user/repo.git"})))))
(deftest should-generate-website-content-volume
(is (= {:storage-c1 "2Gi",
:storage-c2 "10Gi",
:name-c1 "test-de-content-volume",
(is (= {:name-c1 "test-de-content-volume",
:name-c2 "test-com-content-volume",
:app-c1 "test-de-nginx",
:app-c2 "test-com-nginx"}
(th/map-diff (cut/generate-website-content-volume {:fqdn "test.de"
:volume-total-storage-size 10
:number-of-websites 5})
(cut/generate-website-content-volume {:fqdn "test.com"
:volume-total-storage-size 50
:number-of-websites 5})))))
(th/map-diff (cut/generate-website-content-volume {:fqdn "test.de"})
(cut/generate-website-content-volume {:fqdn "test.com"})))))