From 16dd0c58283b0863378d63302439d718440a37aa Mon Sep 17 00:00:00 2001 From: bom Date: Fri, 3 Feb 2023 10:32:04 +0100 Subject: [PATCH] Spec and instrument generate functions --- .../cljc/dda/c4k_nextcloud/nextcloud.cljc | 12 ++++++++---- .../dda/c4k_nextcloud/nextcloud_test.cljc | 19 ++++++++++--------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc b/src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc index 9566430..40d11ce 100644 --- a/src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc +++ b/src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc @@ -44,7 +44,8 @@ "nextcloud/secret.yaml" (rc/inline "nextcloud/secret.yaml") (throw (js/Error. "Undefined Resource!"))))) -(defn generate-certificate [config] +(defn-spec generate-certificate cp/map-or-seq? + [config config?] (let [{:keys [fqdn issuer]} config letsencrypt-issuer issuer] (-> @@ -53,12 +54,14 @@ (assoc-in [:spec :dnsNames] [fqdn]) (assoc-in [:spec :issuerRef :name] letsencrypt-issuer)))) -(defn generate-deployment [config] +(defn-spec generate-deployment cp/map-or-seq? + [config config?] (let [{:keys [fqdn]} config] (-> (yaml/load-as-edn "nextcloud/deployment.yaml") (cm/replace-all-matching-values-by-new-value "fqdn" fqdn)))) -(defn generate-ingress [config] +(defn-spec generate-ingress cp/map-or-seq? + [config config?] (let [{:keys [fqdn issuer] :or {issuer "staging"}} config letsencrypt-issuer issuer] @@ -78,7 +81,8 @@ (defn generate-service [] (yaml/load-as-edn "nextcloud/service.yaml")) -(defn generate-secret [config] +(defn-spec generate-secret cp/map-or-seq? + [config config?] (let [{:keys [nextcloud-admin-user nextcloud-admin-password]} config] (-> (yaml/load-as-edn "nextcloud/secret.yaml") diff --git a/src/test/cljc/dda/c4k_nextcloud/nextcloud_test.cljc b/src/test/cljc/dda/c4k_nextcloud/nextcloud_test.cljc index 26ee033..2cbd51c 100644 --- a/src/test/cljc/dda/c4k_nextcloud/nextcloud_test.cljc +++ b/src/test/cljc/dda/c4k_nextcloud/nextcloud_test.cljc @@ -32,7 +32,8 @@ :data {:nextcloud-admin-user "Y2xvdWRhZG1pbg==" :nextcloud-admin-password "Y2xvdWRwYXNzd29yZA=="}} - (cut/generate-secret {:nextcloud-admin-user "cloudadmin" + (cut/generate-secret {:fqdn "somefqdn.de" + :nextcloud-admin-user "cloudadmin" :nextcloud-admin-password "cloudpassword"})))) (deftest should-generate-certificate @@ -43,11 +44,11 @@ {:secretName "cloud-cert" :duration "2160h" :renewBefore "360h", - :commonName "xx", - :dnsNames ["xx"] + :commonName "somefqdn.de", + :dnsNames ["somefqdn.de"] :issuerRef {:name "prod", :kind "ClusterIssuer"}}} - (cut/generate-certificate {:fqdn "xx" :issuer "prod"})))) + (cut/generate-certificate {:fqdn "somefqdn.de" :issuer "prod"})))) (deftest should-generate-ingress (is (= {:apiVersion "networking.k8s.io/v1" @@ -64,9 +65,9 @@ :ingress.kubernetes.io/proxy-read-timeout "300"} :namespace "default"} :spec - {:tls [{:hosts ["xx"], :secretName "cloud-cert"}] + {:tls [{:hosts ["somefqdn.de"], :secretName "cloud-cert"}] :rules - [{:host "xx" + [{:host "somefqdn.de" :http {:paths [{:path "/" @@ -74,7 +75,7 @@ :backend {:service {:name "cloud-service", :port {:number 80}}}}]}}]}} - (cut/generate-ingress {:fqdn "xx"})))) + (cut/generate-ingress {:fqdn "somefqdn.de"})))) (deftest should-generate-pvc (is (= {:apiVersion "v1" @@ -113,11 +114,11 @@ [{:name "NEXTCLOUD_ADMIN_USER", :valueFrom {:secretKeyRef {:name "cloud-secret", :key "nextcloud-admin-user"}}} {:name "NEXTCLOUD_ADMIN_PASSWORD" :valueFrom {:secretKeyRef {:name "cloud-secret", :key "nextcloud-admin-password"}}} - {:name "NEXTCLOUD_TRUSTED_DOMAINS", :value "xx"} + {:name "NEXTCLOUD_TRUSTED_DOMAINS", :value "somefqdn.de"} {:name "POSTGRES_USER", :valueFrom {:secretKeyRef {:name "postgres-secret", :key "postgres-user"}}} {:name "POSTGRES_PASSWORD", :valueFrom {:secretKeyRef {:name "postgres-secret", :key "postgres-password"}}} {:name "POSTGRES_DB", :valueFrom {:configMapKeyRef {:name "postgres-config", :key "postgres-db"}}} {:name "POSTGRES_HOST", :value "postgresql-service:5432"}] :volumeMounts [{:name "cloud-data-volume", :mountPath "/var/www/html"}]}] :volumes [{:name "cloud-data-volume", :persistentVolumeClaim {:claimName "cloud-pvc"}}]}}}} - (cut/generate-deployment {:fqdn "xx"})))) + (cut/generate-deployment {:fqdn "somefqdn.de"}))))