remove unused PV

This commit is contained in:
jerger 2022-05-20 18:18:04 +02:00
parent 44589b787b
commit 16ab44be95
5 changed files with 22 additions and 71 deletions

View file

@ -9,32 +9,34 @@
[dda.c4k-nextcloud.nextcloud :as nextcloud] [dda.c4k-nextcloud.nextcloud :as nextcloud]
[dda.c4k-nextcloud.backup :as backup])) [dda.c4k-nextcloud.backup :as backup]))
(def default-storage-class :local-path)
(def config-defaults {:issuer "staging"}) (def config-defaults {:issuer "staging"})
(def config? (s/keys :req-un [::nextcloud/fqdn]
:opt-un [::nextcloud/issuer
::nextcloud/restic-repository
::nextcloud/pv-storage-size-gb
::nextcloud/pvc-storage-class-name]))
(def auth? (s/keys :req-un [::postgres/postgres-db-user ::postgres/postgres-db-password (def auth? (s/keys :req-un [::postgres/postgres-db-user ::postgres/postgres-db-password
::nextcloud/nextcloud-admin-user ::nextcloud/nextcloud-admin-password ::nextcloud/nextcloud-admin-user ::nextcloud/nextcloud-admin-password
::aws-access-key-id ::aws-secret-access-key ::aws-access-key-id ::aws-secret-access-key
::restic-password])) ::restic-password]))
(defn-spec k8s-objects any? (defn-spec k8s-objects any?
[config (s/merge nextcloud/config? auth?)] [config (s/merge config? auth?)]
(let [postgres-storage-class (if (contains? config :postgres-data-volume-path) :manual :local-path) (let [nextcloud-default-storage-config {:pvc-storage-class-name default-storage-class
nextcloud-storage-class (if (contains? config :nextcloud-data-volume-path) :manual :local-path) :pv-storage-size-gb 200}]
nextcloud-default-storage-config {:pvc-storage-class-name nextcloud-storage-class :pv-storage-size-gb 200}]
(into (into
[] []
(concat [(yaml/to-string (postgres/generate-config {:postgres-size :8gb})) (concat [(yaml/to-string (postgres/generate-config {:postgres-size :8gb}))
(yaml/to-string (postgres/generate-secret config))] (yaml/to-string (postgres/generate-secret config))
(when (contains? config :postgres-data-volume-path) (yaml/to-string (postgres/generate-pvc {:pv-storage-size-gb 50
[(yaml/to-string (postgres/generate-persistent-volume config))]) :pvc-storage-class-name default-storage-class}))
[(yaml/to-string (postgres/generate-pvc {:pv-storage-size-gb 50
:pvc-storage-class-name postgres-storage-class}))
(yaml/to-string (postgres/generate-deployment)) (yaml/to-string (postgres/generate-deployment))
(yaml/to-string (postgres/generate-service))] (yaml/to-string (postgres/generate-service))
(when (contains? config :nextcloud-data-volume-path) (yaml/to-string (nextcloud/generate-secret config))
[(yaml/to-string (nextcloud/generate-persistent-volume (merge nextcloud-default-storage-config config)))])
[(yaml/to-string (nextcloud/generate-secret config))
(yaml/to-string (nextcloud/generate-pvc (merge nextcloud-default-storage-config config))) (yaml/to-string (nextcloud/generate-pvc (merge nextcloud-default-storage-config config)))
(yaml/to-string (nextcloud/generate-deployment config)) (yaml/to-string (nextcloud/generate-deployment config))
(yaml/to-string (nextcloud/generate-service)) (yaml/to-string (nextcloud/generate-service))
@ -47,7 +49,7 @@
(yaml/to-string (backup/generate-backup-restore-deployment config))]))))) (yaml/to-string (backup/generate-backup-restore-deployment config))])))))
(defn-spec generate any? (defn-spec generate any?
[my-config nextcloud/config? [my-config config?
my-auth auth?] my-auth auth?]
(let [resulting-config (merge config-defaults my-config my-auth)] (let [resulting-config (merge config-defaults my-config my-auth)]
(cs/join (cs/join

View file

@ -7,22 +7,19 @@
[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.postgres :as postgres]))
(s/def ::fqdn cp/fqdn-string?) (s/def ::fqdn cp/fqdn-string?)
(s/def ::issuer cp/letsencrypt-issuer?) (s/def ::issuer cp/letsencrypt-issuer?)
(s/def ::restic-repository string?) (s/def ::restic-repository string?)
(s/def ::nextcloud-data-volume-path string?)
(s/def ::nextcloud-admin-user cp/bash-env-string?) (s/def ::nextcloud-admin-user cp/bash-env-string?)
(s/def ::nextcloud-admin-password cp/bash-env-string?) (s/def ::nextcloud-admin-password 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 config? (s/keys :req-un [::fqdn] (def strong-config? (s/keys :req-un [::fqdn ::issuer ::pv-storage-size-gb
:opt-un [::issuer ::nextcloud-data-volume-path ::pvc-storage-class-name]
::postgres/postgres-data-volume-path ::restic-repository :opt-un [::restic-repository]))
::pv-storage-size-gb ::pvc-storage-class-name]))
#?(:cljs #?(:cljs
(defmethod yaml/load-resource :nextcloud [resource-name] (defmethod yaml/load-resource :nextcloud [resource-name]
@ -30,7 +27,6 @@
"nextcloud/certificate.yaml" (rc/inline "nextcloud/certificate.yaml") "nextcloud/certificate.yaml" (rc/inline "nextcloud/certificate.yaml")
"nextcloud/deployment.yaml" (rc/inline "nextcloud/deployment.yaml") "nextcloud/deployment.yaml" (rc/inline "nextcloud/deployment.yaml")
"nextcloud/ingress.yaml" (rc/inline "nextcloud/ingress.yaml") "nextcloud/ingress.yaml" (rc/inline "nextcloud/ingress.yaml")
"nextcloud/persistent-volume.yaml" (rc/inline "nextcloud/persistent-volume.yaml")
"nextcloud/pvc.yaml" (rc/inline "nextcloud/pvc.yaml") "nextcloud/pvc.yaml" (rc/inline "nextcloud/pvc.yaml")
"nextcloud/service.yaml" (rc/inline "nextcloud/service.yaml") "nextcloud/service.yaml" (rc/inline "nextcloud/service.yaml")
"nextcloud/secret.yaml" (rc/inline "nextcloud/secret.yaml") "nextcloud/secret.yaml" (rc/inline "nextcloud/secret.yaml")
@ -59,16 +55,8 @@
(assoc-in [:metadata :annotations :cert-manager.io/cluster-issuer] letsencrypt-issuer) (assoc-in [:metadata :annotations :cert-manager.io/cluster-issuer] letsencrypt-issuer)
(cm/replace-all-matching-values-by-new-value "fqdn" fqdn)))) (cm/replace-all-matching-values-by-new-value "fqdn" fqdn))))
(defn generate-persistent-volume [config]
(let [{:keys [nextcloud-data-volume-path storage-size]} config]
(->
(yaml/from-string (yaml/load-resource "nextcloud/persistent-volume.yaml"))
(assoc-in [:spec :hostPath :path] nextcloud-data-volume-path)
;(assoc-in [:spec :capacity :storage] (str storage-size "Gi"))
)))
(defn-spec generate-pvc cp/map-or-seq? (defn-spec generate-pvc cp/map-or-seq?
[config config?] [config (s/keys :req-un [::pv-storage-size-gb ::pvc-storage-class-name])]
(let [{:keys [pv-storage-size-gb pvc-storage-class-name]} config] (let [{:keys [pv-storage-size-gb pvc-storage-class-name]} config]
(-> (->
(yaml/from-string (yaml/load-resource "nextcloud/pvc.yaml")) (yaml/from-string (yaml/load-resource "nextcloud/pvc.yaml"))

View file

@ -1,15 +0,0 @@
kind: PersistentVolume
apiVersion: v1
metadata:
name: cloud-pv-volume
labels:
type: local
app.kubernetes.io/application: cloud
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
capacity:
storage: 200Gi
hostPath:
path: "/var/cloud"

View file

@ -7,19 +7,6 @@
)) ))
(deftest should-k8s-objects (deftest should-k8s-objects
(is (= 17
(count (cut/k8s-objects {:fqdn "nextcloud-neu.prod.meissa-gmbh.de"
:postgres-db-user "nextcloud"
:postgres-db-password "nextcloud-db-password"
:nextcloud-admin-user "cloudadmin"
:nextcloud-admin-password "cloudpassword"
:issuer "prod"
:nextcloud-data-volume-path "/var/nextcloud"
:postgres-data-volume-path "/var/postgres"
:aws-access-key-id "aws-id"
:aws-secret-access-key "aws-secret"
:restic-password "restic-pw"
:restic-repository "restic-repository"}))))
(is (= 15 (is (= 15
(count (cut/k8s-objects {:fqdn "nextcloud-neu.prod.meissa-gmbh.de" (count (cut/k8s-objects {:fqdn "nextcloud-neu.prod.meissa-gmbh.de"
:postgres-db-user "nextcloud" :postgres-db-user "nextcloud"

View file

@ -54,17 +54,6 @@
{:name "cloud-service", :port {:number 80}}}}]}}]}} {:name "cloud-service", :port {:number 80}}}}]}}]}}
(cut/generate-ingress {:fqdn "xx"})))) (cut/generate-ingress {:fqdn "xx"}))))
(deftest should-generate-persistent-volume
(is (= {:kind "PersistentVolume"
:apiVersion "v1"
:metadata {:name "cloud-pv-volume"
:labels {:type "local", :app.kubernetes.io/application "cloud"}}
:spec {:storageClassName "manual"
:accessModes ["ReadWriteOnce"]
:capacity {:storage "200Gi"}
:hostPath {:path "xx"}}}
(cut/generate-persistent-volume {:nextcloud-data-volume-path "xx"}))))
(deftest should-generate-pvc (deftest should-generate-pvc
(is (= {:apiVersion "v1" (is (= {:apiVersion "v1"
:kind "PersistentVolumeClaim" :kind "PersistentVolumeClaim"