Spec and instrument generate functions

This commit is contained in:
bom 2023-02-03 10:32:04 +01:00
parent 19682eec36
commit 16dd0c5828
2 changed files with 18 additions and 13 deletions

View file

@ -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")

View file

@ -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"}))))