[Skip-ci] WIP Refactor
This commit is contained in:
parent
616d61c2a9
commit
7cecbacf63
5 changed files with 54 additions and 74 deletions
|
@ -12,3 +12,23 @@
|
|||
[dda.c4k-common.predicate :as pred]
|
||||
[clojure.string :as str]))
|
||||
|
||||
|
||||
(s/def ::issuer pred/letsencrypt-issuer?)
|
||||
(s/def ::fqdns (s/coll-of pred/fqdn-string?))
|
||||
|
||||
(def ingress? (s/keys :req-un [::fqdns ::service-name ::port]
|
||||
:opt-un [::issuer]))
|
||||
|
||||
; generate a list of host-rules from a list of fqdns
|
||||
(defn make-host-rules-from-fqdns
|
||||
[rule fqdns]
|
||||
;function that creates a rule from host names
|
||||
(mapv #(assoc-in rule [:host] %) fqdns))
|
||||
|
||||
(defn generate-http-ingress
|
||||
[config]
|
||||
(let [{:keys [fqdn service-name]} config]
|
||||
(->
|
||||
(yaml/load-as-edn "ingress/http-ingress.yaml")
|
||||
(cm/replace-all-matching-values-by-new-value "SERVICENAME" service-name)
|
||||
(cm/replace-all-matching-values-by-new-value "FQDN" fqdn))))
|
|
@ -76,6 +76,12 @@
|
|||
(str/replace % value-to-partly-match value-to-inplace) %)
|
||||
col))
|
||||
|
||||
; generate a list of host-rules from a list of fqdns
|
||||
(defn make-host-rules-from-fqdns
|
||||
[rule fqdns]
|
||||
;function that creates a rule from host names
|
||||
(mapv #(assoc-in rule [:host] %) fqdns))
|
||||
|
||||
#?(:cljs
|
||||
(defmethod yaml/load-resource :website [resource-name]
|
||||
(case resource-name
|
||||
|
@ -116,8 +122,6 @@
|
|||
(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))
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: c4k-common-http-ingress
|
||||
namespace: default
|
||||
annotations:
|
||||
traefik.ingress.kubernetes.io/router.entrypoints: web
|
||||
traefik.ingress.kubernetes.io/router.middlewares: default-redirect-https@kubernetescrd
|
||||
spec:
|
||||
rules:
|
||||
- host: FQDN
|
||||
http:
|
||||
paths:
|
||||
- pathType: Prefix
|
||||
path: "/"
|
||||
backend:
|
||||
service:
|
||||
name: SERVICENAME
|
||||
port:
|
||||
number: 80
|
|
@ -1,24 +0,0 @@
|
|||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: c4k-common-https-ingress
|
||||
namespace: default
|
||||
annotations:
|
||||
traefik.ingress.kubernetes.io/router.entrypoints: websecure
|
||||
traefik.ingress.kubernetes.io/router.tls: "true"
|
||||
spec:
|
||||
tls:
|
||||
- hosts:
|
||||
- FQDN
|
||||
secretName: c4k-common-cert
|
||||
rules:
|
||||
- host: FQDN
|
||||
http:
|
||||
paths:
|
||||
- pathType: Prefix
|
||||
path: "/"
|
||||
backend:
|
||||
service:
|
||||
name: SERVICENAME
|
||||
port:
|
||||
number: 80
|
|
@ -36,31 +36,31 @@
|
|||
: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"]}))))
|
||||
;; (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-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"]}))))
|
Loading…
Reference in a new issue