Consolidate http and https ingress
The two ingresses were used to enable http to https redirects which can also be done by specifying a middleware in the annotations.
This commit is contained in:
parent
e194fcaffc
commit
948b7d92e7
4 changed files with 11 additions and 83 deletions
|
@ -29,8 +29,7 @@
|
|||
(case resource-name
|
||||
"ingress/host-rule.yaml" (rc/inline "ingress/host-rule.yaml")
|
||||
"ingress/certificate.yaml" (rc/inline "ingress/certificate.yaml")
|
||||
"ingress/http-ingress.yaml" (rc/inline "ingress/http-ingress.yaml")
|
||||
"ingress/https-ingress.yaml" (rc/inline "ingress/https-ingress.yaml")
|
||||
"ingress/ingress.yaml" (rc/inline "ingress/ingress.yaml")
|
||||
(throw (js/Error. "Undefined Resource!")))))
|
||||
|
||||
(defn-spec generate-host-rule pred/map-or-seq?
|
||||
|
@ -43,20 +42,11 @@
|
|||
(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-spec generate-http-ingress pred/map-or-seq?
|
||||
[config ingress?]
|
||||
(let [{:keys [ingress-name service-name service-port fqdns app-name]} config]
|
||||
(->
|
||||
(yaml/load-as-edn "ingress/http-ingress.yaml")
|
||||
(assoc-in [:metadata :name] ingress-name)
|
||||
(assoc-in [:metadata :labels :app.kubernetes.part-of] app-name)
|
||||
(assoc-in [:spec :rules] (mapv (partial generate-host-rule service-name service-port) fqdns)))))
|
||||
|
||||
(defn-spec generate-https-ingress pred/map-or-seq?
|
||||
(defn-spec generate-ingress pred/map-or-seq?
|
||||
[config ingress?]
|
||||
(let [{:keys [ingress-name cert-name service-name service-port fqdns app-name]} config]
|
||||
(->
|
||||
(yaml/load-as-edn "ingress/https-ingress.yaml")
|
||||
(yaml/load-as-edn "ingress/ingress.yaml")
|
||||
(assoc-in [:metadata :name] ingress-name)
|
||||
(assoc-in [:metadata :labels :app.kubernetes.part-of] app-name)
|
||||
(assoc-in [:spec :tls 0 :secretName] cert-name)
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: c4k-common-http-ingress
|
||||
namespace: default
|
||||
labels:
|
||||
app.kubernetes.part-of: c4k-common-app
|
||||
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: SERVICE_NAME
|
||||
port:
|
||||
number: 80
|
|
@ -6,8 +6,9 @@ metadata:
|
|||
labels:
|
||||
app.kubernetes.part-of: c4k-common-app
|
||||
annotations:
|
||||
traefik.ingress.kubernetes.io/router.entrypoints: websecure
|
||||
traefik.ingress.kubernetes.io/router.tls: "true"
|
||||
traefik.ingress.kubernetes.io/router.entrypoints: web, websecure
|
||||
traefik.ingress.kubernetes.io/router.tls: "true"
|
||||
traefik.ingress.kubernetes.io/router.middlewares: default-redirect-https@kubernetescrd
|
||||
spec:
|
||||
tls:
|
||||
- hosts:
|
|
@ -6,11 +6,9 @@
|
|||
[dda.c4k-common.ingress-cert :as cut]))
|
||||
|
||||
(st/instrument `cut/generate-host-rule)
|
||||
(st/instrument `cut/generate-http-ingress)
|
||||
(st/instrument `cut/generate-https-ingress)
|
||||
(st/instrument `cut/generate-ingress)
|
||||
(st/instrument `cut/generate-certificate)
|
||||
|
||||
|
||||
(deftest should-generate-rule
|
||||
(is (= {:host "test.com",
|
||||
:http
|
||||
|
@ -21,54 +19,15 @@
|
|||
{:service {:name "myservice", :port {:number 3000}}}}]}}
|
||||
(cut/generate-host-rule "myservice" 3000 "test.com"))))
|
||||
|
||||
|
||||
(deftest should-generate-http-ingress
|
||||
(is (= {:apiVersion "networking.k8s.io/v1",
|
||||
:kind "Ingress",
|
||||
:metadata
|
||||
{:name "test-io-http-ingress",
|
||||
:namespace "default",
|
||||
:labels {:app.kubernetes.part-of "c4k-common-app"},
|
||||
:annotations
|
||||
#:traefik.ingress.kubernetes.io{:router.entrypoints "web",
|
||||
:router.middlewares "default-redirect-https@kubernetescrd"}}}
|
||||
(dissoc (cut/generate-http-ingress
|
||||
{:issuer "prod"
|
||||
:app-name "c4k-common-app"
|
||||
:service-name "myservice"
|
||||
:service-port 3000
|
||||
:ingress-name "test-io-http-ingress"
|
||||
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]}) :spec)))
|
||||
(is (= {: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}}}}]}}]}
|
||||
(:spec (cut/generate-http-ingress
|
||||
{:issuer "prod"
|
||||
:service-name "myservice"
|
||||
:app-name "c4k-common-app"
|
||||
:service-port 3000
|
||||
:ingress-name "test-io-http-ingress"
|
||||
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]})))))
|
||||
|
||||
(deftest should-generate-https-ingress
|
||||
(deftest should-generate-ingress
|
||||
(is (= {:apiVersion "networking.k8s.io/v1",
|
||||
:kind "Ingress",
|
||||
:metadata
|
||||
{:name "test-io-https-ingress",
|
||||
:namespace "default",
|
||||
:labels {:app.kubernetes.part-of "c4k-common-app"},
|
||||
:annotations #:traefik.ingress.kubernetes.io{:router.entrypoints "websecure", :router.tls "true"}}}
|
||||
(dissoc (cut/generate-https-ingress
|
||||
:annotations #:traefik.ingress.kubernetes.io{:router.entrypoints "web, websecure", :router.tls "true", :router.middlewares "default-redirect-https@kubernetescrd"}}}
|
||||
(dissoc (cut/generate-ingress
|
||||
{:issuer "prod"
|
||||
:service-name "test-io-service"
|
||||
:app-name "c4k-common-app"
|
||||
|
@ -92,7 +51,7 @@
|
|||
{:host "www.test-it.de",
|
||||
:http
|
||||
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}}]}
|
||||
(:spec (cut/generate-https-ingress {:issuer "prod"
|
||||
(:spec (cut/generate-ingress {:issuer "prod"
|
||||
:app-name "c4k-common-app"
|
||||
:service-name "test-io-service"
|
||||
:service-port 80
|
||||
|
|
Loading…
Reference in a new issue