From de9eb9ae74337958f3c71091b7508a982658770f Mon Sep 17 00:00:00 2001
From: Sheogorath <sheogorath@shivering-isles.com>
Date: Sun, 25 Sep 2022 21:42:15 +0200
Subject: [PATCH] feat(keycloak): Add kubernetes as cache-stack

This should allow to run Keycloak in HA mode. This is done by deploying
an additional headless service, providing its dns name to the keycloak
container and explicitly configuring keycloak to use kubernetes
discovery for cache-stack discovery.
---
 charts/keycloak/Chart.yaml                |  2 +-
 charts/keycloak/README.md                 |  2 +-
 charts/keycloak/templates/deployment.yaml |  3 +++
 charts/keycloak/templates/service.yaml    | 11 +++++++++++
 4 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/charts/keycloak/Chart.yaml b/charts/keycloak/Chart.yaml
index 910a621ab..54bf51267 100644
--- a/charts/keycloak/Chart.yaml
+++ b/charts/keycloak/Chart.yaml
@@ -7,5 +7,5 @@ icon: https://www.keycloak.org/resources/images/keycloak_icon_512px.svg
 sources:
   - https://git.shivering-isles.com/shivering-isles/infrastructure-gitops
   - https://github.com/keycloak/keycloak
-version: 0.1.6
+version: 0.2.0
 appVersion: "19.0.2"
diff --git a/charts/keycloak/README.md b/charts/keycloak/README.md
index 8d72029ba..5af81c6e7 100644
--- a/charts/keycloak/README.md
+++ b/charts/keycloak/README.md
@@ -1,6 +1,6 @@
 # keycloak
 
-![Version: 0.1.6](https://img.shields.io/badge/Version-0.1.6-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 19.0.2](https://img.shields.io/badge/AppVersion-19.0.2-informational?style=flat-square)
+![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 19.0.2](https://img.shields.io/badge/AppVersion-19.0.2-informational?style=flat-square)
 
 (Alpha) A Helm chart for Keycloak on Kubernetes
 
diff --git a/charts/keycloak/templates/deployment.yaml b/charts/keycloak/templates/deployment.yaml
index e7cf34037..ffd455621 100644
--- a/charts/keycloak/templates/deployment.yaml
+++ b/charts/keycloak/templates/deployment.yaml
@@ -38,6 +38,7 @@ spec:
           imagePullPolicy: {{ .Values.image.pullPolicy }}
           args:
             - start
+            - --cache-stack=kubernetes
             - --proxy
             - '{{ .Values.keycloak.proxy }}'
             {{- if gt (len .Values.keycloak.features) 0 }}
@@ -53,6 +54,8 @@ spec:
             {{- end }}
             - name: KC_HOSTNAME
               value: "{{ required "Setting a hostname is required" .Values.keycloak.hostname }}"
+            - name: JAVA_OPTS_APPEND
+              value: '-Djgroups.dns.query={{ include "keycloak.fullname" . }}-headless.{{ .Release.Namespace }}.svc.cluster.local'
             {{- if .Values.keycloak.database.type}}
             - name: KC_DB
               value: "{{ .Values.keycloak.database.type }}"
diff --git a/charts/keycloak/templates/service.yaml b/charts/keycloak/templates/service.yaml
index 14ce8c7c6..20916f6a5 100644
--- a/charts/keycloak/templates/service.yaml
+++ b/charts/keycloak/templates/service.yaml
@@ -13,3 +13,14 @@ spec:
       name: http
   selector:
     {{- include "keycloak.selectorLabels" . | nindent 4 }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ include "keycloak.fullname" . }}-headless
+  labels:
+    {{- include "keycloak.labels" . | nindent 4 }}
+spec:
+  type: None
+  selector:
+    {{- include "keycloak.selectorLabels" . | nindent 4 }}
-- 
GitLab