diff --git a/src/main/cljc/dda/c4k_website/ingress.cljc b/src/main/cljc/dda/c4k_website/ingress.cljc new file mode 100644 index 0000000..475502a --- /dev/null +++ b/src/main/cljc/dda/c4k_website/ingress.cljc @@ -0,0 +1,14 @@ +(ns dda.c4k-website.ingress + (:require + [clojure.spec.alpha :as s] + #?(:cljs [shadow.resource :as rc]) + #?(:clj [orchestra.core :refer [defn-spec]] + :cljs [orchestra.core :refer-macros [defn-spec]]) + #?(:clj [clojure.edn :as edn] + :cljs [cljs.reader :as edn]) + [dda.c4k-common.yaml :as yaml] + [dda.c4k-common.common :as cm] + [dda.c4k-common.base64 :as b64] + [dda.c4k-common.predicate :as pred] + [clojure.string :as str])) + diff --git a/src/main/cljc/dda/c4k_website/website.cljc b/src/main/cljc/dda/c4k_website/website.cljc index bd7b74b..22370d9 100644 --- a/src/main/cljc/dda/c4k_website/website.cljc +++ b/src/main/cljc/dda/c4k_website/website.cljc @@ -116,6 +116,8 @@ (let [{:keys [unique-name fqdns]} config spec-rules [:spec :rules]] (-> + (generate-http-ingress (merge {:service "xy" :port 80 :issuer issuer} + config)) (generate-common-http-ingress {:fqdn (first fqdns) :service-name (generate-service-name unique-name)}) (cm/replace-all-matching-values-by-new-value "c4k-common-http-ingress" (generate-http-ingress-name unique-name)) diff --git a/src/test/cljc/dda/c4k_website/ingress_test.cljc b/src/test/cljc/dda/c4k_website/ingress_test.cljc new file mode 100644 index 0000000..4c80caf --- /dev/null +++ b/src/test/cljc/dda/c4k_website/ingress_test.cljc @@ -0,0 +1,66 @@ +(ns dda.c4k-website.ingress-test + (:require + #?(:clj [clojure.test :refer [deftest is are testing run-tests]] + :cljs [cljs.test :refer-macros [deftest is are testing run-tests]]) + [clojure.spec.test.alpha :as st] + [dda.c4k-common.test-helper :as th] + [dda.c4k-common.base64 :as b64] + [dda.c4k-website.ingress :as cut] + [clojure.spec.alpha :as s])) + +(deftest should-generate-http-ingress + (is (= {:apiVersion "networking.k8s.io/v1", + :kind "Ingress", + :metadata + {:name "myservice-http-ingress", + :namespace "default", + :annotations + #:traefik.ingress.kubernetes.io{:router.entrypoints "web", + :router.middlewares "default-redirect-https@kubernetescrd"}}, + :spec + {:rules + [{:host "test.de", + :http + {:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "myservice", :port {:number 3000}}}}]}} + {:host "www.test.de", + :http + {:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "myservice", :port {:number 3000}}}}]}} + {:host "test-it.de", + :http + {:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "myservice", :port {:number 3000}}}}]}} + {:host "www.test-it.de", + :http + {:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "myservice", :port {:number 3000}}}}]}}]}} + (cut/generate-http-ingress {:issuer "prod" + :service "myservice" + :port 3000 + :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]})))) + +(deftest should-generate-https-ingress + (is (= {:apiVersion "networking.k8s.io/v1", + :kind "Ingress", + :metadata + {:name "test-io-https-ingress", + :namespace "default", + :annotations #:traefik.ingress.kubernetes.io{:router.entrypoints "websecure", :router.tls "true"}}, + :spec + {:tls [{:hosts ["test.de" "www.test.de" "test-it.de" "www.test-it.de"], :secretName "test-io-cert"}], + :rules + [{:host "test.de", + :http + {:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}} + {:host "www.test.de", + :http + {:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}} + {:host "test-it.de", + :http + {:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}} + {:host "www.test-it.de", + :http + {:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}}]}} + (cut/generate-website-https-ingress {:unique-name "test.io" + :gitea-host "gitea.evilorg" + :gitea-repo "none" + :branchname "mablain" + :issuer "prod" + :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]})))) \ No newline at end of file diff --git a/src/test/cljc/dda/c4k_website/website_test.cljc b/src/test/cljc/dda/c4k_website/website_test.cljc index 4d04741..fa21076 100644 --- a/src/test/cljc/dda/c4k_website/website_test.cljc +++ b/src/test/cljc/dda/c4k_website/website_test.cljc @@ -42,64 +42,7 @@ :gitea-repo "repo" :branchname "main"}]})))) -(deftest should-generate-http-ingress - (is (= {:apiVersion "networking.k8s.io/v1", - :kind "Ingress", - :metadata - {:name "test-io-http-ingress", - :namespace "default", - :annotations - #:traefik.ingress.kubernetes.io{:router.entrypoints "web", - :router.middlewares "default-redirect-https@kubernetescrd"}}, - :spec - {:rules - [{:host "test.de", - :http - {:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}} - {:host "www.test.de", - :http - {:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}} - {:host "test-it.de", - :http - {:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}} - {:host "www.test-it.de", - :http - {:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}}]}} - (cut/generate-website-http-ingress {:unique-name "test.io" - :gitea-host "gitea.evilorg" - :gitea-repo "none" - :branchname "mablain" - :issuer "prod" - :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]})))) -(deftest should-generate-https-ingress - (is (= {:apiVersion "networking.k8s.io/v1", - :kind "Ingress", - :metadata - {:name "test-io-https-ingress", - :namespace "default", - :annotations #:traefik.ingress.kubernetes.io{:router.entrypoints "websecure", :router.tls "true"}}, - :spec - {:tls [{:hosts ["test.de" "www.test.de" "test-it.de" "www.test-it.de"], :secretName "test-io-cert"}], - :rules - [{:host "test.de", - :http - {:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}} - {:host "www.test.de", - :http - {:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}} - {:host "test-it.de", - :http - {:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}} - {:host "www.test-it.de", - :http - {:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}}]}} - (cut/generate-website-https-ingress {:unique-name "test.io" - :gitea-host "gitea.evilorg" - :gitea-repo "none" - :branchname "mablain" - :issuer "prod" - :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]})))) (deftest should-generate-website-certificate (is (= {:name-c1 "prod", :name-c2 "staging"}