2022-12-26 17:04:53 +00:00
|
|
|
(ns dda.c4k-common.ingress-test
|
2022-10-19 07:25:37 +00:00
|
|
|
(: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]
|
2022-12-26 17:04:53 +00:00
|
|
|
[dda.c4k-common.ingress :as cut]))
|
2022-10-19 07:25:37 +00:00
|
|
|
|
|
|
|
(st/instrument `cut/generate-host-rule)
|
2022-11-11 08:35:42 +00:00
|
|
|
(st/instrument `cut/generate-ingress)
|
2022-10-19 07:25:37 +00:00
|
|
|
(st/instrument `cut/generate-certificate)
|
2022-12-26 17:04:53 +00:00
|
|
|
(st/instrument `cut/generate-ingress-and-cert)
|
2022-10-19 07:25:37 +00:00
|
|
|
|
|
|
|
(deftest should-generate-rule
|
|
|
|
(is (= {:host "test.com",
|
|
|
|
:http
|
|
|
|
{:paths
|
|
|
|
[{:pathType "Prefix",
|
|
|
|
:path "/",
|
|
|
|
:backend
|
|
|
|
{:service {:name "myservice", :port {:number 3000}}}}]}}
|
|
|
|
(cut/generate-host-rule "myservice" 3000 "test.com"))))
|
|
|
|
|
2022-11-11 08:35:42 +00:00
|
|
|
(deftest should-generate-ingress
|
2022-10-19 07:25:37 +00:00
|
|
|
(is (= {:apiVersion "networking.k8s.io/v1",
|
|
|
|
:kind "Ingress",
|
|
|
|
:metadata
|
|
|
|
{:name "test-io-https-ingress",
|
|
|
|
:namespace "default",
|
2022-11-01 14:37:29 +00:00
|
|
|
:labels {:app.kubernetes.part-of "c4k-common-app"},
|
2022-12-26 17:04:53 +00:00
|
|
|
:annotations {:traefik.ingress.kubernetes.io/router.entrypoints
|
|
|
|
"web, websecure"
|
|
|
|
:traefik.ingress.kubernetes.io/router.middlewares
|
|
|
|
"default-redirect-https@kubernetescrd"
|
|
|
|
:metallb.universe.tf/address-pool "public"}}}
|
2022-11-11 08:35:42 +00:00
|
|
|
(dissoc (cut/generate-ingress
|
2022-10-19 07:25:37 +00:00
|
|
|
{:issuer "prod"
|
|
|
|
:service-name "test-io-service"
|
2022-11-01 14:37:29 +00:00
|
|
|
:app-name "c4k-common-app"
|
2022-10-19 07:25:37 +00:00
|
|
|
:service-port 80
|
|
|
|
:ingress-name "test-io-https-ingress"
|
2022-12-26 17:04:53 +00:00
|
|
|
:fqdns ["test.de" "www.test.de" "test-it.de"
|
|
|
|
"www.test-it.de"]}) :spec)))
|
2022-10-19 07:25:37 +00:00
|
|
|
(is (= {: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}}}}]}}]}
|
2022-11-11 08:35:42 +00:00
|
|
|
(:spec (cut/generate-ingress {:issuer "prod"
|
2022-12-26 17:04:53 +00:00
|
|
|
:app-name "c4k-common-app"
|
|
|
|
:service-name "test-io-service"
|
|
|
|
:service-port 80
|
|
|
|
:ingress-name "test-io-https-ingress"
|
|
|
|
:cert-name "test-io-cert"
|
|
|
|
:fqdns ["test.de" "www.test.de"
|
|
|
|
"test-it.de"
|
|
|
|
"www.test-it.de"]})))))
|
2022-10-19 07:25:37 +00:00
|
|
|
|
|
|
|
(deftest should-generate-certificate
|
|
|
|
(is (= {:apiVersion "cert-manager.io/v1",
|
|
|
|
:kind "Certificate",
|
2022-11-01 14:37:29 +00:00
|
|
|
:metadata {:name "test-io-cert",
|
|
|
|
:namespace "default",
|
|
|
|
:labels {:app.kubernetes.part-of "c4k-common-app"}},
|
2022-10-19 07:25:37 +00:00
|
|
|
:spec
|
|
|
|
{:secretName "test-io-cert",
|
|
|
|
:commonName "test.de",
|
|
|
|
:duration "2160h",
|
|
|
|
:renewBefore "360h",
|
|
|
|
:dnsNames ["test.de" "test.org" "www.test.de" "www.test.org"],
|
|
|
|
:issuerRef {:name "prod", :kind "ClusterIssuer"}}}
|
2022-11-01 14:37:29 +00:00
|
|
|
(cut/generate-certificate {:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"]
|
|
|
|
:app-name "c4k-common-app"
|
|
|
|
:cert-name "test-io-cert"
|
2022-12-26 17:04:53 +00:00
|
|
|
:issuer "prod"}))))
|
|
|
|
|
|
|
|
(deftest should-generate-ingress-and-cert
|
|
|
|
(is (= [{:apiVersion "cert-manager.io/v1",
|
|
|
|
:kind "Certificate",
|
|
|
|
:metadata
|
|
|
|
{:name "web",
|
|
|
|
:labels {:app.kubernetes.part-of "web"},
|
|
|
|
:namespace "default"},
|
|
|
|
:spec
|
|
|
|
{:secretName "web",
|
|
|
|
:commonName "test.jit.si",
|
|
|
|
:duration "2160h",
|
|
|
|
:renewBefore "360h",
|
|
|
|
:dnsNames ["test.jit.si"],
|
|
|
|
:issuerRef {:name "staging", :kind "ClusterIssuer"}}}
|
|
|
|
{:apiVersion "networking.k8s.io/v1",
|
|
|
|
:kind "Ingress",
|
|
|
|
:metadata
|
|
|
|
{:name "web",
|
|
|
|
:namespace "default",
|
|
|
|
:labels {:app.kubernetes.part-of "web"},
|
|
|
|
:annotations
|
|
|
|
{:traefik.ingress.kubernetes.io/router.entrypoints "web, websecure",
|
|
|
|
:traefik.ingress.kubernetes.io/router.middlewares
|
|
|
|
"default-redirect-https@kubernetescrd",
|
|
|
|
:metallb.universe.tf/address-pool "public"}},
|
|
|
|
:spec
|
|
|
|
{:tls [{:hosts ["test.jit.si"], :secretName "web"}],
|
|
|
|
:rules
|
|
|
|
[{:host "test.jit.si",
|
|
|
|
:http {:paths [{:path "/",
|
|
|
|
:pathType "Prefix",
|
|
|
|
:backend
|
|
|
|
{:service {:name "web",
|
|
|
|
:port {:number 80}}}}]}}]}}]
|
|
|
|
(cut/generate-ingress-and-cert {:fqdns ["test.jit.si"]
|
|
|
|
:service-name "web"
|
|
|
|
:service-port 80}))))
|