From 997ecf53053ce2ce14665d32a192f04a2793ec13 Mon Sep 17 00:00:00 2001 From: jerger Date: Wed, 6 Jul 2022 08:21:27 +0200 Subject: [PATCH] do not create cert twice --- src/main/cljc/dda/c4k_gitea/gitea.cljc | 9 +++------ src/main/resources/gitea/ingress.yaml | 3 +-- src/test/cljc/dda/c4k_gitea/gitea_test.cljc | 12 ++++++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/cljc/dda/c4k_gitea/gitea.cljc b/src/main/cljc/dda/c4k_gitea/gitea.cljc index eaee24c..dd8160e 100644 --- a/src/main/cljc/dda/c4k_gitea/gitea.cljc +++ b/src/main/cljc/dda/c4k_gitea/gitea.cljc @@ -25,10 +25,10 @@ "gitea/appini-configmap.yaml" (rc/inline "gitea/appini-configmap.yaml") "gitea/appini-env-configmap.yaml" (rc/inline "gitea/appini-env-configmap.yaml") "gitea/deployment.yaml" (rc/inline "gitea/deployment.yaml") + "gitea/certificate.yaml" (rc/inline "gitea/certificate.yaml") "gitea/ingress.yaml" (rc/inline "gitea/ingress.yaml") "gitea/services.yaml" (rc/inline "gitea/services.yaml") - "gitea/volumes.yaml" (rc/inline "gitea/volumes.yaml") - "gitea/certificate.yaml" (rc/inline "gitea/certificate.yaml") + "gitea/volumes.yaml" (rc/inline "gitea/volumes.yaml") (throw (js/Error. "Undefined Resource!"))))) #?(:cljs @@ -48,12 +48,9 @@ (defn-spec generate-ingress pred/map-or-seq? [config config?] - (let [{:keys [fqdn issuer] - :or {issuer "staging"}} config - letsencrypt-issuer (name issuer)] + (let [{:keys [fqdn issuer]} config] (-> (yaml/load-as-edn "gitea/ingress.yaml") - (assoc-in [:metadata :annotations :cert-manager.io/cluster-issuer] letsencrypt-issuer) (cm/replace-all-matching-values-by-new-value "FQDN" fqdn)))) (defn-spec generate-certificate pred/map-or-seq? diff --git a/src/main/resources/gitea/ingress.yaml b/src/main/resources/gitea/ingress.yaml index 6560fce..1e59913 100644 --- a/src/main/resources/gitea/ingress.yaml +++ b/src/main/resources/gitea/ingress.yaml @@ -4,8 +4,7 @@ metadata: name: ingress-gitea namespace: default annotations: - kubernetes.io/ingress.class: "traefik" - cert-manager.io/cluster-issuer: ISSUER + ingress.kubernetes.io/ssl-redirect: "true" spec: tls: - hosts: diff --git a/src/test/cljc/dda/c4k_gitea/gitea_test.cljc b/src/test/cljc/dda/c4k_gitea/gitea_test.cljc index 3fe95fb..072c227 100644 --- a/src/test/cljc/dda/c4k_gitea/gitea_test.cljc +++ b/src/test/cljc/dda/c4k_gitea/gitea_test.cljc @@ -19,8 +19,12 @@ :GITEA__server__ROOT_URL-c1 "https://", :GITEA__server__ROOT_URL-c2 "https://test.com"} (ct/map-diff (cut/generate-appini-env {}) - (cut/generate-appini-env {:fqdn "test.com" :issuer "staging" :postgres-db-user "pg-user" :postgres-db-password "pg-pw"}))))) + (cut/generate-appini-env {:fqdn "test.com" + :issuer "staging" + :postgres-db-user "pg-user" + :postgres-db-password "pg-pw"}))))) -(deftest should-generate-ingress - (is (= {:hosts-c1 "abc.de", :hosts-c2 "test.com", :host-c1 "abc.de", :host-c2 "test.com"} - (ct/map-diff (cut/generate-ingress {:fqdn "abc.de"}) (cut/generate-ingress {:fqdn "test.com" :issuer "staging"}))))) +(deftest should-generate-certificate + (is (= {:name-c2 "prod", :name-c1 "staging"} + (ct/map-diff (cut/generate-certificate {}) + (cut/generate-certificate {:issuer "prod"})))))