Compare commits

...

3 commits

Author SHA1 Message Date
b7a284a2dc Dont hardcode namespace 2024-08-07 14:48:19 +02:00
f64f4f3ab5 Update functions to replace NAMESPACE 2024-08-07 14:48:04 +02:00
1429ff0058 Move default config values to config defaults
Also add spec for namespace
2024-08-07 14:30:11 +02:00
5 changed files with 34 additions and 22 deletions

View file

@ -13,11 +13,18 @@
(def default-storage-class :local-path)
(def config-defaults {:issuer "staging"})
(def config-defaults {:issuer "staging",
:namespace "keycloak"
:postgres-image "postgres:14"
:postgres-size :2gb
:db-name "keycloak"
:pv-storage-size-gb 30
:pvc-storage-class-name default-storage-class})
(def config? (s/keys :req-un [::kc/fqdn]
:opt-un [::kc/issuer
::mon/mon-cfg]))
::mon/mon-cfg
::kc/namespace]))
(def auth? (s/keys :req-un [::kc/keycloak-admin-user ::kc/keycloak-admin-password
::postgres/postgres-db-user ::postgres/postgres-db-password]
@ -30,17 +37,11 @@
(filter
#(not (nil? %))
(cm/concat-vec
(ns/generate (merge {:namespace "keycloak"} config))
(postgres/generate (merge {:postgres-image "postgres:14"
:postgres-size :2gb
:db-name "keycloak"
:pv-storage-size-gb 30
:pvc-storage-class-name default-storage-class
:namespace "keycloak"})
auth)
[(kc/generate-secret auth)
(kc/generate-service)
(ns/generate config)
(postgres/generate config auth)
[(kc/generate-secret config auth)
(kc/generate-service config)
(kc/generate-deployment config)]
(kc/generate-ingress (merge {:namespace "keycloak"} config))
(kc/generate-ingress config)
(when (:contains? config :mon-cfg)
(mon/generate (:mon-cfg config) (:mon-auth auth)))))))

View file

@ -11,12 +11,14 @@
[dda.c4k-common.predicate :as cp]))
(s/def ::fqdn cp/fqdn-string?)
(s/def ::namespace string?)
(s/def ::issuer cp/letsencrypt-issuer?)
(s/def ::keycloak-admin-user cp/bash-env-string?)
(s/def ::keycloak-admin-password cp/bash-env-string?)
(def config? (s/keys :req-un [::fqdn]
:opt-un [::issuer]))
:opt-un [::issuer
::namespace]))
(def auth? (s/keys :req-un [::keycloak-admin-user
::keycloak-admin-password]))
@ -35,20 +37,29 @@
config)))
(defn-spec generate-secret cp/map-or-seq?
[auth auth?]
(let [{:keys [keycloak-admin-user keycloak-admin-password]} auth]
[config config?
auth auth?]
(let [{:keys [namespace]} config
{:keys [keycloak-admin-user keycloak-admin-password]} auth]
(->
(yaml/load-as-edn "keycloak/secret.yaml")
(cm/replace-all-matching "NAMESPACE" namespace)
(cm/replace-key-value :keycloak-user (b64/encode keycloak-admin-user))
(cm/replace-key-value :keycloak-password (b64/encode keycloak-admin-password)))))
(defn-spec generate-service cp/map-or-seq? []
(yaml/load-as-edn "keycloak/service.yaml"))
(defn-spec generate-service cp/map-or-seq?
[config config?]
(let [{:keys [namespace]} config
{:keys [keycloak-admin-user keycloak-admin-password]} auth]
(->
(yaml/load-as-edn "keycloak/service.yaml")
(cm/replace-all-matching "NAMESPACE" namespace))))
(defn-spec generate-deployment cp/map-or-seq?
[config config?]
(let [{:keys [fqdn]} config]
(let [{:keys [fqdn namespace]} config]
(->
(yaml/load-as-edn "keycloak/deployment.yaml")
(cm/replace-all-matching "NAMESPACE" namespace)
(cm/replace-all-matching-values-by-new-value "FQDN" fqdn))))

View file

@ -2,7 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: keycloak
namespace: keycloak
namespace: NAMESPACE
labels:
app: keycloak
spec:

View file

@ -2,7 +2,7 @@ apiVersion: v1
kind: Secret
metadata:
name: keycloak-secret
namespace: keycloak
namespace: NAMESPACE
type: Opaque
data:
keycloak-user: admin

View file

@ -4,7 +4,7 @@ metadata:
name: keycloak
labels:
service: keycloak
namespace: keycloak
namespace: NAMESPACE
spec:
ports:
- name: "http"