From 8c0bf1243eb6bf9de7841df2e25f8a8e46a78769 Mon Sep 17 00:00:00 2001 From: bom Date: Fri, 21 Jan 2022 15:04:03 +0100 Subject: [PATCH] finished all generate functions --- src/main/cljc/dda/c4k_matomo/core.cljc | 9 +++- src/main/cljc/dda/c4k_matomo/matomo.cljc | 31 ++++++----- .../matomo/deployments-template.yaml | 27 ---------- src/main/resources/matomo/deployments.yaml | 35 ++---------- src/main/resources/matomo/ingress.yaml | 3 +- src/main/resources/matomo/service-redis.yaml | 11 ++++ .../resources/matomo/service-webserver.yaml | 10 ++++ src/main/resources/matomo/services.yaml | 22 -------- src/test/cljc/dda/c4k_matomo/matomo_test.cljc | 53 +++++++++++++++++++ 9 files changed, 106 insertions(+), 95 deletions(-) delete mode 100644 src/main/resources/matomo/deployments-template.yaml create mode 100644 src/main/resources/matomo/service-redis.yaml create mode 100644 src/main/resources/matomo/service-webserver.yaml delete mode 100644 src/main/resources/matomo/services.yaml diff --git a/src/main/cljc/dda/c4k_matomo/core.cljc b/src/main/cljc/dda/c4k_matomo/core.cljc index 4a1a539..caee14b 100644 --- a/src/main/cljc/dda/c4k_matomo/core.cljc +++ b/src/main/cljc/dda/c4k_matomo/core.cljc @@ -18,7 +18,14 @@ (defn k8s-objects [config] (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? [my-config config? diff --git a/src/main/cljc/dda/c4k_matomo/matomo.cljc b/src/main/cljc/dda/c4k_matomo/matomo.cljc index 06fe237..9b05c85 100644 --- a/src/main/cljc/dda/c4k_matomo/matomo.cljc +++ b/src/main/cljc/dda/c4k_matomo/matomo.cljc @@ -13,10 +13,11 @@ (defmethod yaml/load-resource :matomo [resource-name] (case resource-name "matomo/certificate.yaml" (rc/inline "matomo/certificate.yaml") - ;"matomo/deployments.yaml" (rc/inline "matomo/deployments.yaml") - ;"matomo/ingress.yaml" (rc/inline "matomo/ingress.yaml") - ;"matomo/services.yaml" (rc/inline "matomo/services.yaml") - ;"matomo/statefulset.yaml" (rc/inline "matomo/statefulset.yaml") + "matomo/deployments.yaml" (rc/inline "matomo/deployments.yaml") + "matomo/ingress.yaml" (rc/inline "matomo/ingress.yaml") + "matomo/service-redis.yaml" (rc/inline "matomo/service-redis.yaml") + "matomo/service-webserver.yaml" (rc/inline "matomo/service-webserver.yaml") + "matomo/statefulset.yaml" (rc/inline "matomo/statefulset.yaml") (throw (js/Error. "Undefined Resource!"))))) (defn generate-certificate [config] @@ -30,10 +31,15 @@ (defn generate-webserver-deployment [] (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) (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] (let [{:keys [fqdn issuer] :or {issuer :staging}} config @@ -43,14 +49,11 @@ (assoc-in [:metadata :annotations :cert-manager.io/cluster-issuer] letsencrypt-issuer) (cm/replace-all-matching-values-by-new-value "fqdn" fqdn)))) -(defn generate-persistent-volume [config] - (let [{:keys [matomo-data-volume-path]} config] - (-> - (yaml/from-string (yaml/load-resource "matomo/persistent-volume.yaml")) - (assoc-in [:spec :hostPath :path] matomo-data-volume-path)))) +(defn generate-statefulset [] + (yaml/from-string (yaml/load-resource "matomo/statefulset.yaml"))) -(defn generate-pvc [] - (yaml/from-string (yaml/load-resource "matomo/pvc.yaml"))) +(defn generate-service-redis [] + (yaml/from-string (yaml/load-resource "matomo/service-redis.yaml"))) -(defn generate-service [] - (yaml/from-string (yaml/load-resource "matomo/service.yaml"))) +(defn generate-service-webserver [] + (yaml/from-string (yaml/load-resource "matomo/service-webserver.yaml"))) diff --git a/src/main/resources/matomo/deployments-template.yaml b/src/main/resources/matomo/deployments-template.yaml deleted file mode 100644 index 388843e..0000000 --- a/src/main/resources/matomo/deployments-template.yaml +++ /dev/null @@ -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 diff --git a/src/main/resources/matomo/deployments.yaml b/src/main/resources/matomo/deployments.yaml index 5d1d776..388843e 100644 --- a/src/main/resources/matomo/deployments.yaml +++ b/src/main/resources/matomo/deployments.yaml @@ -1,52 +1,27 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: shynet-webserver + name: shynet-application namespace: default labels: - app: shynet-webserver + app: shynet-application spec: selector: matchLabels: - app: shynet-webserver + app: shynet-application strategy: type: Recreate replicas: 1 template: metadata: labels: - app: shynet-webserver + app: shynet-application spec: containers: - - name: shynet-webserver + - name: shynet-application image: milesmcc/shynet:edge 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"] - imagePullPolicy: IfNotPresent envFrom: - secretRef: name: shynet-settings diff --git a/src/main/resources/matomo/ingress.yaml b/src/main/resources/matomo/ingress.yaml index 724485a..5253c2c 100644 --- a/src/main/resources/matomo/ingress.yaml +++ b/src/main/resources/matomo/ingress.yaml @@ -3,6 +3,7 @@ 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" @@ -14,7 +15,7 @@ spec: tls: - hosts: - fqdn - secretName: jira-secret + secretName: shynet-secret rules: - host: fqdn http: diff --git a/src/main/resources/matomo/service-redis.yaml b/src/main/resources/matomo/service-redis.yaml new file mode 100644 index 0000000..34402fa --- /dev/null +++ b/src/main/resources/matomo/service-redis.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: shynet-redis +spec: + ports: + - port: 6379 + name: redis + clusterIP: None + selector: + app: shynet-redis \ No newline at end of file diff --git a/src/main/resources/matomo/service-webserver.yaml b/src/main/resources/matomo/service-webserver.yaml new file mode 100644 index 0000000..8c6e44a --- /dev/null +++ b/src/main/resources/matomo/service-webserver.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Service +metadata: + name: shynet-webserver-service +spec: + type: ClusterIP + ports: + - port: 8080 + selector: + app: shynet-webserver \ No newline at end of file diff --git a/src/main/resources/matomo/services.yaml b/src/main/resources/matomo/services.yaml deleted file mode 100644 index f88db12..0000000 --- a/src/main/resources/matomo/services.yaml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/src/test/cljc/dda/c4k_matomo/matomo_test.cljc b/src/test/cljc/dda/c4k_matomo/matomo_test.cljc index 337688f..2f42d82 100644 --- a/src/test/cljc/dda/c4k_matomo/matomo_test.cljc +++ b/src/test/cljc/dda/c4k_matomo/matomo_test.cljc @@ -26,3 +26,56 @@ :envFrom [{:secretRef {:name "shynet-settings"}}]}]}}}} (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})))) \ No newline at end of file