added easier replacing to core

This commit is contained in:
bom 2021-05-27 12:53:32 +02:00
parent fd74df706d
commit cf5c337b14
2 changed files with 4 additions and 26 deletions

View file

@ -32,11 +32,11 @@
(defn cast-lazy-seq-to-vec (defn cast-lazy-seq-to-vec
[lazy-seq] [lazy-seq]
(clojure.walk/postwalk #(if (instance? clojure.lang.LazySeq %) (clojure.walk/postwalk #(if (instance? clojure.lang.LazySeq %)
(do (println %) (into [] %)) (do (into [] %))
%) lazy-seq)) %) lazy-seq))
(defn replace-all-matching-values-by-new-value (defn replace-all-matching-values-by-new-value
[value-to-match value-to-replace coll] [coll value-to-match value-to-replace]
(clojure.walk/postwalk #(if (and (= (type value-to-match) (type %)) (clojure.walk/postwalk #(if (and (= (type value-to-match) (type %))
(= value-to-match %)) (= value-to-match %))
value-to-replace value-to-replace
@ -78,6 +78,7 @@
(let [{:keys [user-name user-password]} my-auth] (let [{:keys [user-name user-password]} my-auth]
(-> (->
(yaml/from-string (yaml/load-resource "deployment.yaml")) (yaml/from-string (yaml/load-resource "deployment.yaml"))
(cast-lazy-seq-to-vec)
(assoc-in [:spec :template :spec :containers 0 :env 0 :value] user-name) (assoc-in [:spec :template :spec :containers 0 :env 0 :value] user-name)
(assoc-in [:spec :template :spec :containers 0 :env 1 :value] user-password)))) (assoc-in [:spec :template :spec :containers 0 :env 1 :value] user-password))))
@ -98,10 +99,7 @@
(-> (->
(yaml/from-string (yaml/load-resource "ingress.yaml")) (yaml/from-string (yaml/load-resource "ingress.yaml"))
(assoc-in [:metadata :annotations :cert-manager.io/cluster-issuer] letsencrypt-issuer) (assoc-in [:metadata :annotations :cert-manager.io/cluster-issuer] letsencrypt-issuer)
(assoc-in [:spec :tls] [{:hosts [fqdn], :secretName "keycloak-secret"}]) (replace-all-matching-values-by-new-value "fqdn" fqdn))))
(assoc-in [:spec :rules] [{:host fqdn
:http {:paths [{:backend {:serviceName "keycloak"
:servicePort 8080}}]}}]))))

View file

@ -83,23 +83,3 @@
:ports [{:name "http", :containerPort 8080}] :ports [{:name "http", :containerPort 8080}]
:readinessProbe {:httpGet {:path "/auth/realms/master", :port 8080}}}]}}}} :readinessProbe {:httpGet {:path "/auth/realms/master", :port 8080}}}]}}}}
(cut/generate-deployment {:user-name "testuser" :user-password "test1234"})))) (cut/generate-deployment {:user-name "testuser" :user-password "test1234"}))))
<<<<<<< HEAD
=======
(deftest test-vector-replace-fqdn-function
(let [ingress-yaml (yaml/from-string (yaml/load-resource "ingress.yaml"))
fqdn "some_host"
desired-result (-> ingress-yaml
(assoc-in [:spec :rules] [{:host fqdn
:http {:paths [{:backend {:serviceName "keycloak"
:servicePort 8080}}]}}
{:host fqdn
:http {:paths [{:backend {:serviceName "another_keycloak"
:servicePort 8081}}]}}
]))]
(is (= desired-result
(cut/assoc-in-nested (cut/cast-lazy-seq-to-vec ingress-yaml) [:spec :rules :host] fqdn))))
)
>>>>>>> 0379ad882851993440561c5c09c9f813e4357ab1