no more pv needed

This commit is contained in:
jerger 2022-05-20 18:02:51 +02:00
parent f255f9ad75
commit f124f7d23d
6 changed files with 31 additions and 56 deletions

View file

@ -2,13 +2,21 @@
(:require
[clojure.spec.alpha :as s]
#?(:cljs [shadow.resource :as rc])
#?(:clj [orchestra.core :refer [defn-spec]]
:cljs [orchestra.core :refer-macros [defn-spec]])
[dda.c4k-common.yaml :as yaml]
[dda.c4k-common.predicate :as cp]
[dda.c4k-common.common :as cm]))
(s/def ::fqdn cm/fqdn-string?)
(s/def ::issuer cm/letsencrypt-issuer?)
(s/def ::fqdn cp/fqdn-string?)
(s/def ::issuer cp/letsencrypt-issuer?)
(s/def ::restic-repository string?)
(s/def ::jira-data-volume-path string?)
(s/def ::pvc-storage-class-name cp/pvc-storage-class-name?)
(s/def ::pv-storage-size-gb pos?)
(def strong-config? (s/keys :req-un [::fqdn ::issuer ::pv-storage-size-gb
::pvc-storage-class-name]
:opt-un [::restic-repository]))
#?(:cljs
(defmethod yaml/load-resource :jira [resource-name]
@ -16,7 +24,6 @@
"jira/certificate.yaml" (rc/inline "jira/certificate.yaml")
"jira/deployment.yaml" (rc/inline "jira/deployment.yaml")
"jira/ingress.yaml" (rc/inline "jira/ingress.yaml")
"jira/persistent-volume.yaml" (rc/inline "jira/persistent-volume.yaml")
"jira/pvc.yaml" (rc/inline "jira/pvc.yaml")
"jira/service.yaml" (rc/inline "jira/service.yaml")
(throw (js/Error. "Undefined Resource!")))))
@ -44,14 +51,13 @@
(assoc-in [:metadata :annotations :cert-manager.io/cluster-issuer] letsencrypt-issuer)
(cm/replace-all-matching-values-by-new-value "fqdn" fqdn))))
(defn generate-persistent-volume [config]
(let [{:keys [jira-data-volume-path]} config]
(->
(yaml/from-string (yaml/load-resource "jira/persistent-volume.yaml"))
(assoc-in [:spec :hostPath :path] jira-data-volume-path))))
(defn generate-pvc []
(yaml/from-string (yaml/load-resource "jira/pvc.yaml")))
(defn-spec generate-pvc cp/map-or-seq?
[config (s/keys :req-un [::pv-storage-size-gb ::pvc-storage-class-name])]
(let [{:keys [pv-storage-size-gb pvc-storage-class-name]} config]
(->
(yaml/from-string (yaml/load-resource "jira/pvc.yaml"))
(assoc-in [:spec :resources :requests :storage] (str pv-storage-size-gb "Gi"))
(assoc-in [:spec :storageClassName] (name pvc-storage-class-name)))))
(defn generate-service []
(yaml/from-string (yaml/load-resource "jira/service.yaml")))

View file

@ -3,8 +3,7 @@
[clojure.tools.reader.edn :as edn]
[dda.c4k-jira.core :as core]
[dda.c4k-jira.jira :as jira]
[dda.c4k-common.browser :as br]
[dda.c4k-common.postgres :as pgc]))
[dda.c4k-common.browser :as br]))
(defn generate-content
[]
@ -51,8 +50,6 @@
(defn validate-all! []
(br/validate! "fqdn" ::jira/fqdn)
(br/validate! "jira-data-volume-path" ::jira/jira-data-volume-path :optional true)
(br/validate! "postgres-data-volume-path" ::pgc/postgres-data-volume-path :optional true)
(br/validate! "restic-repository" ::jira/restic-repository :optional true)
(br/validate! "issuer" ::jira/issuer :optional true :deserializer keyword)
(br/validate! "auth" core/auth? :deserializer edn/read-string)
@ -74,8 +71,6 @@
(br/get-content-from-element "auth" :deserializer edn/read-string))
(br/set-output!)))))
(add-validate-listener "fqdn")
(add-validate-listener "jira-data-volume-path")
(add-validate-listener "postgres-data-volume-path")
(add-validate-listener "restic-repository")
(add-validate-listener "issuer")
(add-validate-listener "auth"))

View file

@ -1,14 +0,0 @@
kind: PersistentVolume
apiVersion: v1
metadata:
name: jira-pv-volume
labels:
type: local
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
capacity:
storage: 30Gi
hostPath:
path: "/var/jira"

View file

@ -5,9 +5,9 @@ metadata:
labels:
app: jira
spec:
storageClassName: manual
storageClassName: REPLACEME
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 30Gi
storage: REPLACEME

View file

@ -5,17 +5,6 @@
[dda.c4k-jira.core :as cut]))
(deftest should-k8s-objects
(is (= 16
(count (cut/k8s-objects {:fqdn "jira-neu.prod.meissa-gmbh.de"
:postgres-db-user "jira"
:postgres-db-password "jira-db-password"
:issuer :prod
:jira-data-volume-path "/var/jira"
: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 (= 14
(count (cut/k8s-objects {:fqdn "jira-neu.prod.meissa-gmbh.de"
:postgres-db-user "jira"

View file

@ -16,6 +16,16 @@
{:name "letsencrypt-prod-issuer", :kind "ClusterIssuer"}}}
(cut/generate-certificate {:fqdn "xx" :issuer :prod}))))
(deftest should-generate-pvc
(is (= {:apiVersion "v1",
:kind "PersistentVolumeClaim",
:metadata {:name "jira-pvc", :labels {:app "jira"}},
:spec
{:storageClassName "manual",
:accessModes ["ReadWriteOnce"],
:resources {:requests {:storage "12Gi"}}}}
(cut/generate-pvc {:pv-storage-size-gb 12 :pvc-storage-class-name :manual}))))
(deftest should-generate-ingress
(is (= {:apiVersion "networking.k8s.io/v1"
:kind "Ingress"
@ -45,17 +55,6 @@
:port {:number 8080}}}}]}}]}}
(cut/generate-ingress {:fqdn "xx"}))))
(deftest should-generate-persistent-volume
(is (= {:kind "PersistentVolume"
:apiVersion "v1"
:metadata {:name "jira-pv-volume", :labels {:type "local"}}
:spec
{:storageClassName "manual"
:accessModes ["ReadWriteOnce"]
:capacity {:storage "30Gi"}
:hostPath {:path "xx"}}}
(cut/generate-persistent-volume {:jira-data-volume-path "xx"}))))
(deftest should-generate-deployment
(is (= {:containers
[{:image "domaindrivenarchitecture/c4k-jira"