diff --git a/src/main/cljc/dda/k8s_keycloak/core.cljc b/src/main/cljc/dda/k8s_keycloak/core.cljc index 1eb6cef..32ce0ff 100644 --- a/src/main/cljc/dda/k8s_keycloak/core.cljc +++ b/src/main/cljc/dda/k8s_keycloak/core.cljc @@ -26,6 +26,11 @@ (def auth? (s/keys :req-un [::user-name ::user-password])) + +(defn replace-values-in-vector + [map keys value] +) + (defn generate-config [my-config my-auth] (-> (yaml/from-string (yaml/load-resource "config.yaml")) @@ -68,6 +73,8 @@ :http {:paths [{:backend {:serviceName "keycloak" :servicePort 8080}}]}}])))) + + (defn generate-service [] (yaml/from-string (yaml/load-resource "service.yaml"))) @@ -84,3 +91,5 @@ (yaml/to-string (generate-service)) "---" (yaml/to-string (generate-deployment my-auth))])) + + diff --git a/src/test/cljc/dda/k8s_keycloak/core_test.cljc b/src/test/cljc/dda/k8s_keycloak/core_test.cljc index bb73f45..2f0c543 100644 --- a/src/test/cljc/dda/k8s_keycloak/core_test.cljc +++ b/src/test/cljc/dda/k8s_keycloak/core_test.cljc @@ -2,7 +2,8 @@ (:require #?(:clj [clojure.test :refer [deftest is are testing run-tests]] :cljs [cljs.test :refer-macros [deftest is are testing run-tests]]) - [dda.k8s-keycloak.core :as cut])) + [dda.k8s-keycloak.core :as cut] + [dda.k8s-keycloak.yaml :as yaml])) (deftest should-generate-yaml (is (= {:apiVersion "v1", :kind "ConfigMap" @@ -81,4 +82,19 @@ {:name "PROXY_ADDRESS_FORWARDING", :value "true"}] :ports [{:name "http", :containerPort 8080}] :readinessProbe {:httpGet {:path "/auth/realms/master", :port 8080}}}]}}}} - (cut/generate-deployment {:user-name "testuser" :user-password "test1234"})))) \ No newline at end of file + (cut/generate-deployment {:user-name "testuser" :user-password "test1234"})))) + +(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/replace-values-in-vector ingress-yaml [:spec :rules :host] fqdn)))) + ) + + diff --git a/src/test/resources/ingress_test.yaml b/src/test/resources/ingress_test.yaml new file mode 100644 index 0000000..ed5d4b0 --- /dev/null +++ b/src/test/resources/ingress_test.yaml @@ -0,0 +1,31 @@ +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 \ No newline at end of file