wip
This commit is contained in:
parent
60156805c3
commit
8989679d57
3 changed files with 66 additions and 30 deletions
|
@ -14,21 +14,27 @@
|
||||||
|
|
||||||
|
|
||||||
(s/def ::issuer pred/letsencrypt-issuer?)
|
(s/def ::issuer pred/letsencrypt-issuer?)
|
||||||
|
(s/def ::service-name string?)
|
||||||
|
(s/def ::service-port pos-int?)
|
||||||
(s/def ::fqdns (s/coll-of pred/fqdn-string?))
|
(s/def ::fqdns (s/coll-of pred/fqdn-string?))
|
||||||
|
|
||||||
(def ingress? (s/keys :req-un [::fqdns ::service-name ::port]
|
(def ingress? (s/keys :req-un [::fqdns ::service-name ::service-port]
|
||||||
:opt-un [::issuer]))
|
:opt-un [::issuer]))
|
||||||
|
|
||||||
; generate a list of host-rules from a list of fqdns
|
(defn-spec generate-rule pred/map-or-seq?
|
||||||
(defn make-host-rules-from-fqdns
|
[service-name ::service-name
|
||||||
[rule fqdns]
|
service-port ::service-port
|
||||||
;function that creates a rule from host names
|
fqdn pred/fqdn-string?]
|
||||||
(mapv #(assoc-in rule [:host] %) fqdns))
|
(->
|
||||||
|
(yaml/load-as-edn "ingress/rule.yaml")
|
||||||
|
(cm/replace-all-matching-values-by-new-value "FQDN" fqdn)
|
||||||
|
(cm/replace-all-matching-values-by-new-value "SERVICE_PORT" service-port)
|
||||||
|
(cm/replace-all-matching-values-by-new-value "SERVICE_NAME" service-name)))
|
||||||
|
|
||||||
(defn generate-http-ingress
|
(defn-spec generate-http-ingress pred/map-or-seq?
|
||||||
[config]
|
[config ingress?]
|
||||||
(let [{:keys [fqdn service-name]} config]
|
(let [{:keys [service-name service-port fqdns]} config]
|
||||||
(->
|
(->
|
||||||
(yaml/load-as-edn "ingress/http-ingress.yaml")
|
(yaml/load-as-edn "ingress/http-ingress.yaml")
|
||||||
(cm/replace-all-matching-values-by-new-value "SERVICENAME" service-name)
|
(assoc-in [:metadata :name] (str service-name "-http-ingress"))
|
||||||
(cm/replace-all-matching-values-by-new-value "FQDN" fqdn))))
|
(assoc-in [:spec :rules] (mapv (partial generate-rule service-name service-port) fqdns)))))
|
10
src/main/resources/ingress/rule.yaml
Normal file
10
src/main/resources/ingress/rule.yaml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
host: FQDN
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- pathType: Prefix
|
||||||
|
path: "/"
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: SERVICE_NAME
|
||||||
|
port:
|
||||||
|
number: SERVICE_PORT
|
|
@ -8,6 +8,21 @@
|
||||||
[dda.c4k-website.ingress :as cut]
|
[dda.c4k-website.ingress :as cut]
|
||||||
[clojure.spec.alpha :as s]))
|
[clojure.spec.alpha :as s]))
|
||||||
|
|
||||||
|
(st/instrument `cut/generate-rule)
|
||||||
|
(st/instrument `cut/generate-http-ingress)
|
||||||
|
|
||||||
|
(deftest should-genereate-rule
|
||||||
|
(is (= {:host "test.com",
|
||||||
|
:http
|
||||||
|
{:paths
|
||||||
|
[{:pathType "Prefix",
|
||||||
|
:path "/",
|
||||||
|
:backend
|
||||||
|
{:service {:name "myservice", :port {:number 3000}}}}]}}
|
||||||
|
|
||||||
|
(cut/generate-rule "myservice" 3000 "test.com"))))
|
||||||
|
|
||||||
|
|
||||||
(deftest should-generate-http-ingress
|
(deftest should-generate-http-ingress
|
||||||
(is (= {:apiVersion "networking.k8s.io/v1",
|
(is (= {:apiVersion "networking.k8s.io/v1",
|
||||||
:kind "Ingress",
|
:kind "Ingress",
|
||||||
|
@ -16,9 +31,13 @@
|
||||||
:namespace "default",
|
:namespace "default",
|
||||||
:annotations
|
:annotations
|
||||||
#:traefik.ingress.kubernetes.io{:router.entrypoints "web",
|
#:traefik.ingress.kubernetes.io{:router.entrypoints "web",
|
||||||
:router.middlewares "default-redirect-https@kubernetescrd"}},
|
:router.middlewares "default-redirect-https@kubernetescrd"}}}
|
||||||
:spec
|
(dissoc (cut/generate-http-ingress
|
||||||
{:rules
|
{:issuer "prod"
|
||||||
|
:service-name "myservice"
|
||||||
|
:service-port 3000
|
||||||
|
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]}) :spec)))
|
||||||
|
(is (= {:rules
|
||||||
[{:host "test.de",
|
[{:host "test.de",
|
||||||
:http
|
:http
|
||||||
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "myservice", :port {:number 3000}}}}]}}
|
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "myservice", :port {:number 3000}}}}]}}
|
||||||
|
@ -30,11 +49,12 @@
|
||||||
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "myservice", :port {:number 3000}}}}]}}
|
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "myservice", :port {:number 3000}}}}]}}
|
||||||
{:host "www.test-it.de",
|
{:host "www.test-it.de",
|
||||||
:http
|
:http
|
||||||
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "myservice", :port {:number 3000}}}}]}}]}}
|
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "myservice", :port {:number 3000}}}}]}}]}
|
||||||
(cut/generate-http-ingress {:issuer "prod"
|
(:spec (cut/generate-http-ingress
|
||||||
:service "myservice"
|
{:issuer "prod"
|
||||||
:port 3000
|
:service-name "myservice"
|
||||||
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]}))))
|
:service-port 3000
|
||||||
|
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]})))))
|
||||||
|
|
||||||
;; (deftest should-generate-https-ingress
|
;; (deftest should-generate-https-ingress
|
||||||
;; (is (= {:apiVersion "networking.k8s.io/v1",
|
;; (is (= {:apiVersion "networking.k8s.io/v1",
|
||||||
|
|
Loading…
Reference in a new issue