finished all generate functions

This commit is contained in:
bom 2022-01-21 15:04:03 +01:00
parent 194b87467c
commit 8c0bf1243e
9 changed files with 106 additions and 95 deletions

View file

@ -18,7 +18,14 @@
(defn k8s-objects [config] (defn k8s-objects [config]
(into (into
[] []
(concat []))) (concat
[(yaml/to-string (matomo/generate-webserver-deployment))
(yaml/to-string (matomo/generate-celeryworker-deployment))
(yaml/to-string (matomo/generate-ingress config))
(yaml/to-string (matomo/generate-certificate config))
(yaml/to-string (matomo/generate-service-redis))
(yaml/to-string (matomo/generate-service-webserver))
(yaml/to-string (matomo/generate-statefulset))])))
(defn-spec generate any? (defn-spec generate any?
[my-config config? [my-config config?

View file

@ -13,10 +13,11 @@
(defmethod yaml/load-resource :matomo [resource-name] (defmethod yaml/load-resource :matomo [resource-name]
(case resource-name (case resource-name
"matomo/certificate.yaml" (rc/inline "matomo/certificate.yaml") "matomo/certificate.yaml" (rc/inline "matomo/certificate.yaml")
;"matomo/deployments.yaml" (rc/inline "matomo/deployments.yaml") "matomo/deployments.yaml" (rc/inline "matomo/deployments.yaml")
;"matomo/ingress.yaml" (rc/inline "matomo/ingress.yaml") "matomo/ingress.yaml" (rc/inline "matomo/ingress.yaml")
;"matomo/services.yaml" (rc/inline "matomo/services.yaml") "matomo/service-redis.yaml" (rc/inline "matomo/service-redis.yaml")
;"matomo/statefulset.yaml" (rc/inline "matomo/statefulset.yaml") "matomo/service-webserver.yaml" (rc/inline "matomo/service-webserver.yaml")
"matomo/statefulset.yaml" (rc/inline "matomo/statefulset.yaml")
(throw (js/Error. "Undefined Resource!"))))) (throw (js/Error. "Undefined Resource!")))))
(defn generate-certificate [config] (defn generate-certificate [config]
@ -30,10 +31,15 @@
(defn generate-webserver-deployment [] (defn generate-webserver-deployment []
(let [shynet-application "shynet-webserver"] (let [shynet-application "shynet-webserver"]
(-> (yaml/from-string (yaml/load-resource "matomo/deployments-template.yaml")) (-> (yaml/from-string (yaml/load-resource "matomo/deployments.yaml"))
(cm/replace-all-matching-values-by-new-value "shynet-application" shynet-application) (cm/replace-all-matching-values-by-new-value "shynet-application" shynet-application)
(update-in [:spec :template :spec :containers 0] dissoc :command)))) (update-in [:spec :template :spec :containers 0] dissoc :command))))
(defn generate-celeryworker-deployment []
(let [shynet-application "shynet-celeryworker"]
(-> (yaml/from-string (yaml/load-resource "matomo/deployments.yaml"))
(cm/replace-all-matching-values-by-new-value "shynet-application" shynet-application))))
(defn generate-ingress [config] (defn generate-ingress [config]
(let [{:keys [fqdn issuer] (let [{:keys [fqdn issuer]
:or {issuer :staging}} config :or {issuer :staging}} config
@ -43,14 +49,11 @@
(assoc-in [:metadata :annotations :cert-manager.io/cluster-issuer] letsencrypt-issuer) (assoc-in [:metadata :annotations :cert-manager.io/cluster-issuer] letsencrypt-issuer)
(cm/replace-all-matching-values-by-new-value "fqdn" fqdn)))) (cm/replace-all-matching-values-by-new-value "fqdn" fqdn))))
(defn generate-persistent-volume [config] (defn generate-statefulset []
(let [{:keys [matomo-data-volume-path]} config] (yaml/from-string (yaml/load-resource "matomo/statefulset.yaml")))
(->
(yaml/from-string (yaml/load-resource "matomo/persistent-volume.yaml"))
(assoc-in [:spec :hostPath :path] matomo-data-volume-path))))
(defn generate-pvc [] (defn generate-service-redis []
(yaml/from-string (yaml/load-resource "matomo/pvc.yaml"))) (yaml/from-string (yaml/load-resource "matomo/service-redis.yaml")))
(defn generate-service [] (defn generate-service-webserver []
(yaml/from-string (yaml/load-resource "matomo/service.yaml"))) (yaml/from-string (yaml/load-resource "matomo/service-webserver.yaml")))

View file

@ -1,27 +0,0 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: shynet-application
namespace: default
labels:
app: shynet-application
spec:
selector:
matchLabels:
app: shynet-application
strategy:
type: Recreate
replicas: 1
template:
metadata:
labels:
app: shynet-application
spec:
containers:
- name: shynet-application
image: milesmcc/shynet:edge
imagePullPolicy: IfNotPresent
command: ["./celeryworker.sh"]
envFrom:
- secretRef:
name: shynet-settings

View file

@ -1,52 +1,27 @@
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: shynet-webserver name: shynet-application
namespace: default namespace: default
labels: labels:
app: shynet-webserver app: shynet-application
spec: spec:
selector: selector:
matchLabels: matchLabels:
app: shynet-webserver app: shynet-application
strategy: strategy:
type: Recreate type: Recreate
replicas: 1 replicas: 1
template: template:
metadata: metadata:
labels: labels:
app: shynet-webserver app: shynet-application
spec: spec:
containers: containers:
- name: shynet-webserver - name: shynet-application
image: milesmcc/shynet:edge image: milesmcc/shynet:edge
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
envFrom:
- secretRef:
name: shynet-settings
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: shynet-celeryworker
namespace: default
labels:
app: shynet-celeryworker
spec:
selector:
matchLabels:
app: shynet-celeryworker
replicas: 1
template:
metadata:
labels:
app: shynet-celeryworker
spec:
containers:
- name: shynet-celeryworker
image: milesmcc/shynet:edge
command: ["./celeryworker.sh"] command: ["./celeryworker.sh"]
imagePullPolicy: IfNotPresent
envFrom: envFrom:
- secretRef: - secretRef:
name: shynet-settings name: shynet-settings

View file

@ -3,6 +3,7 @@ kind: Ingress
metadata: metadata:
name: shynet-webserver-ingress name: shynet-webserver-ingress
annotations: annotations:
cert-manager.io/cluster-issuer: letsencrypt-staging-issuer
kubernetes.io/ingress.class: addon-http-application-routing kubernetes.io/ingress.class: addon-http-application-routing
nginx.ingress.kubernetes.io/proxy-body-size: "256m" nginx.ingress.kubernetes.io/proxy-body-size: "256m"
nginx.ingress.kubernetes.io/ssl-redirect: "true" nginx.ingress.kubernetes.io/ssl-redirect: "true"
@ -14,7 +15,7 @@ spec:
tls: tls:
- hosts: - hosts:
- fqdn - fqdn
secretName: jira-secret secretName: shynet-secret
rules: rules:
- host: fqdn - host: fqdn
http: http:

View file

@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: shynet-redis
spec:
ports:
- port: 6379
name: redis
clusterIP: None
selector:
app: shynet-redis

View file

@ -0,0 +1,10 @@
apiVersion: v1
kind: Service
metadata:
name: shynet-webserver-service
spec:
type: ClusterIP
ports:
- port: 8080
selector:
app: shynet-webserver

View file

@ -1,22 +0,0 @@
apiVersion: v1
kind: Service
metadata:
name: shynet-redis
spec:
ports:
- port: 6379
name: redis
clusterIP: None
selector:
app: shynet-redis
---
apiVersion: v1
kind: Service
metadata:
name: shynet-webserver-service
spec:
type: ClusterIP
ports:
- port: 8080
selector:
app: shynet-webserver

View file

@ -26,3 +26,56 @@
:envFrom [{:secretRef {:name "shynet-settings"}}]}]}}}} :envFrom [{:secretRef {:name "shynet-settings"}}]}]}}}}
(cut/generate-webserver-deployment)))) (cut/generate-webserver-deployment))))
(deftest should-generate-celeryworker-deployment
(is (= {:apiVersion "apps/v1"
:kind "Deployment"
:metadata
{:name "shynet-celeryworker"
:namespace "default"
:labels {:app "shynet-celeryworker"}}
:spec
{:selector {:matchLabels {:app "shynet-celeryworker"}}
:strategy {:type "Recreate"}
:replicas 1
:template
{:metadata {:labels {:app "shynet-celeryworker"}}
:spec
{:containers
[{:name "shynet-celeryworker"
:image "milesmcc/shynet:edge"
:imagePullPolicy "IfNotPresent"
:command ["./celeryworker.sh"]
:envFrom [{:secretRef {:name "shynet-settings"}}]}]}}}}
(cut/generate-celeryworker-deployment))))
(deftest should-generate-certificate
(is (= {:apiVersion "cert-manager.io/v1"
:kind "Certificate"
:metadata {:name "shynet-cert", :namespace "default"}
:spec
{:secretName "shynet-secret"
:commonName "test.com"
:dnsNames ["test.com"]
:issuerRef {:name "letsencrypt-staging-issuer", :kind "ClusterIssuer"}}}
(cut/generate-certificate {:fqdn "test.com" :issuer :staging}))))
(deftest should-generate-ingress
(is (= {:apiVersion "networking.k8s.io/v1"
:kind "Ingress"
:metadata
{:name "shynet-webserver-ingress"
:annotations
{:cert-manager.io/cluster-issuer "letsencrypt-staging-issuer"
:kubernetes.io/ingress.class "addon-http-application-routing"
:nginx.ingress.kubernetes.io/proxy-body-size "256m"
:nginx.ingress.kubernetes.io/ssl-redirect "true"
:nginx.ingress.kubernetes.io/rewrite-target "/"
:nginx.ingress.kubernetes.io/proxy-connect-timeout "300"
:nginx.ingress.kubernetes.io/proxy-send-timeout "300"
:nginx.ingress.kubernetes.io/proxy-read-timeout "300"}}
:spec
{:tls [{:hosts ["test.com"], :secretName "shynet-secret"}]
:rules
[{:host "test.com"
:http {:paths [{:backend {:serviceName "shynet-webserver-service", :servicePort 8080}, :path "/"}]}}]}}
(cut/generate-ingress {:fqdn "test.com" :issuer :staging}))))