From f124f7d23deddf4ce3572df0f7331ee66f8e1f7e Mon Sep 17 00:00:00 2001 From: jerger Date: Fri, 20 May 2022 18:02:51 +0200 Subject: [PATCH] no more pv needed --- src/main/cljc/dda/c4k_jira/jira.cljc | 30 +++++++++++-------- src/main/cljs/dda/c4k_jira/browser.cljs | 7 +---- .../resources/jira/persistent-volume.yaml | 14 --------- src/main/resources/jira/pvc.yaml | 4 +-- src/test/cljc/dda/c4k_jira/core_test.cljc | 11 ------- src/test/cljc/dda/c4k_jira/jira_test.cljc | 21 +++++++------ 6 files changed, 31 insertions(+), 56 deletions(-) delete mode 100644 src/main/resources/jira/persistent-volume.yaml diff --git a/src/main/cljc/dda/c4k_jira/jira.cljc b/src/main/cljc/dda/c4k_jira/jira.cljc index bd52990..4b2d2cd 100644 --- a/src/main/cljc/dda/c4k_jira/jira.cljc +++ b/src/main/cljc/dda/c4k_jira/jira.cljc @@ -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"))) diff --git a/src/main/cljs/dda/c4k_jira/browser.cljs b/src/main/cljs/dda/c4k_jira/browser.cljs index aaa84cd..859dd21 100644 --- a/src/main/cljs/dda/c4k_jira/browser.cljs +++ b/src/main/cljs/dda/c4k_jira/browser.cljs @@ -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")) \ No newline at end of file diff --git a/src/main/resources/jira/persistent-volume.yaml b/src/main/resources/jira/persistent-volume.yaml deleted file mode 100644 index b5e9b37..0000000 --- a/src/main/resources/jira/persistent-volume.yaml +++ /dev/null @@ -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" diff --git a/src/main/resources/jira/pvc.yaml b/src/main/resources/jira/pvc.yaml index c89e620..0faf011 100644 --- a/src/main/resources/jira/pvc.yaml +++ b/src/main/resources/jira/pvc.yaml @@ -5,9 +5,9 @@ metadata: labels: app: jira spec: - storageClassName: manual + storageClassName: REPLACEME accessModes: - ReadWriteOnce resources: requests: - storage: 30Gi \ No newline at end of file + storage: REPLACEME \ No newline at end of file diff --git a/src/test/cljc/dda/c4k_jira/core_test.cljc b/src/test/cljc/dda/c4k_jira/core_test.cljc index 8e62dea..b51885e 100644 --- a/src/test/cljc/dda/c4k_jira/core_test.cljc +++ b/src/test/cljc/dda/c4k_jira/core_test.cljc @@ -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" diff --git a/src/test/cljc/dda/c4k_jira/jira_test.cljc b/src/test/cljc/dda/c4k_jira/jira_test.cljc index 231ad13..b000ac1 100644 --- a/src/test/cljc/dda/c4k_jira/jira_test.cljc +++ b/src/test/cljc/dda/c4k_jira/jira_test.cljc @@ -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"