mob
This commit is contained in:
parent
8e3b007e06
commit
67631747ae
7 changed files with 78 additions and 15 deletions
|
@ -19,6 +19,9 @@ Our convention 4 kubernetes c4k-* tools combine the advantages of both approache
|
|||
* yaml / edn as input and output, no more magic
|
||||
* good validation, integration as api, cli or in the browser
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Copyright © 2021 meissa GmbH
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
"src/main/cljs"
|
||||
"src/main/resources"
|
||||
"src/test/cljc"
|
||||
"src/test/cljs"
|
||||
"src/test/resources"]
|
||||
:dependencies [[aero "1.1.6"]
|
||||
[orchestra "2021.01.01-1"]
|
||||
|
|
|
@ -10,9 +10,6 @@
|
|||
(into [] %)
|
||||
%) lazy-seq))
|
||||
|
||||
(defmethod load-resource :clj [resource-name]
|
||||
(slurp (io/resource resource-name)))
|
||||
|
||||
(defn from-string [input]
|
||||
(cast-lazy-seq-to-vec (yaml/parse-string input)))
|
||||
|
||||
|
@ -20,6 +17,10 @@
|
|||
(yaml/generate-string edn :dumper-options {:flow-style :block}))
|
||||
|
||||
(defn dispatch-by-resource-name
|
||||
[resource])
|
||||
[resource]
|
||||
:clj)
|
||||
|
||||
(defmulti load-resource dispatch-by-resource-name)
|
||||
|
||||
(defmethod load-resource :clj [resource-name]
|
||||
(slurp (io/resource resource-name)))
|
|
@ -1,12 +1,8 @@
|
|||
(ns dda.c4k-common.yaml
|
||||
(:require
|
||||
["js-yaml" :as yaml]
|
||||
[shadow.resource :as rc]))
|
||||
|
||||
(defn load-resource [resource-name]
|
||||
(case resource-name
|
||||
"ingress_test.yaml" (rc/inline "ingress_test.yaml")
|
||||
(throw (js/Error. "Undefined Resource!"))))
|
||||
[shadow.resource :as rc]
|
||||
[clojure.string :as st]))
|
||||
|
||||
(defn from-string [input]
|
||||
(js->clj (yaml/load input)
|
||||
|
@ -14,3 +10,14 @@
|
|||
|
||||
(defn to-string [edn]
|
||||
(yaml/dump (clj->js edn)))
|
||||
|
||||
(defn dispatch-by-resource-name
|
||||
[resource]
|
||||
(keyword (first (st/split resource #"/"))))
|
||||
|
||||
(defmulti load-resource dispatch-by-resource-name)
|
||||
|
||||
(defmethod load-resource :test [resource-name]
|
||||
(case resource-name
|
||||
"test/ingress_test.yaml" (rc/inline "test/ingress_test.yaml")
|
||||
(throw (js/Error. "Undefined Resource!"))))
|
|
@ -1,9 +1,12 @@
|
|||
(ns dda.c4k-common.yaml-test
|
||||
(:require
|
||||
#?(:clj [clojure.test :refer [deftest is are testing run-tests]]
|
||||
:cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
|
||||
[clojure.test :refer [deftest is are testing run-tests]]
|
||||
[dda.c4k-common.yaml :as cut]))
|
||||
|
||||
(deftest should-dispatch-by-resource-name
|
||||
(is (= :clj
|
||||
(cut/dispatch-by-resource-name "postgres/etc"))))
|
||||
|
||||
(deftest should-parse-yaml-string
|
||||
(is (= {:hallo "welt"}
|
||||
(cut/from-string "hallo: welt"))))
|
||||
|
@ -42,4 +45,4 @@
|
|||
[{:backend
|
||||
{:serviceName "another_keycloak"
|
||||
:servicePort 8081}}]}}]}}
|
||||
(cut/from-string (cut/load-resource "ingress_test.yaml")))))
|
||||
(cut/from-string (cut/load-resource "test/ingress_test.yaml")))))
|
48
src/test/cljs/dda/c4k_common/yaml_test.cljs
Normal file
48
src/test/cljs/dda/c4k_common/yaml_test.cljs
Normal file
|
@ -0,0 +1,48 @@
|
|||
(ns dda.c4k-common.yaml-test
|
||||
(:require
|
||||
[cljs.test :refer-macros [deftest is are testing run-tests]]
|
||||
[dda.c4k-common.yaml :as cut]))
|
||||
|
||||
(deftest should-dispatch-by-resource-name
|
||||
(is (= :postgres
|
||||
(cut/dispatch-by-resource-name "postgres/etc"))))
|
||||
|
||||
(deftest should-parse-yaml-string
|
||||
(is (= {:hallo "welt"}
|
||||
(cut/from-string "hallo: welt"))))
|
||||
|
||||
(deftest should-generate-yaml-string
|
||||
(is (= "hallo: welt
|
||||
"
|
||||
(cut/to-string {:hallo "welt"}))))
|
||||
|
||||
(deftest should-convert-config-yml-to-map
|
||||
(is (= {:apiVersion "networking.k8s.io/v1beta1"
|
||||
:kind "Ingress"
|
||||
:metadata
|
||||
{:name "ingress-cloud"
|
||||
:annotations
|
||||
{:cert-manager.io/cluster-issuer
|
||||
"letsencrypt-staging-issuer"
|
||||
: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"}
|
||||
:namespace "default"}
|
||||
:spec
|
||||
{:tls [{:hosts ["fqdn"], :secretName "keycloak-secret"}]
|
||||
:rules
|
||||
[{:host "fqdn"
|
||||
:http
|
||||
{:paths
|
||||
[{:backend
|
||||
{:serviceName "keycloak", :servicePort 8080}}]}}
|
||||
{:host "fqdn"
|
||||
:http
|
||||
{:paths
|
||||
[{:backend
|
||||
{:serviceName "another_keycloak"
|
||||
:servicePort 8081}}]}}]}}
|
||||
(cut/from-string (cut/load-resource "test/ingress_test.yaml")))))
|
Loading…
Reference in a new issue