Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: keycloak PVC customization #341

Merged
merged 11 commits into from
Apr 17, 2024
2 changes: 1 addition & 1 deletion src/keycloak/chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ For more information on Keycloak and its capabilities, see its [documentation](h

### Dev Mode

When `devMode: true` is set, the chart will deploy a single Keycloak Pod with an in-memory database and scaling turned off.
When `devMode: true` is set, the chart will deploy a single Keycloak Pod with an in-memory database and scaling turned off. Devmode also leverages PVCs by default for `data` and `themes`.

### Autoscaling

Expand Down
61 changes: 56 additions & 5 deletions src/keycloak/chart/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
{{- if .Values.devMode }}
{{- if .Values.persistence.providers.enabled }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ include "keycloak.fullname" . }}-providers
namespace: {{ .Release.Namespace }}
labels:
{{- include "keycloak.labels" . | nindent 4 }}
spec:
accessModes:
- {{ .Values.persistence.accessMode | quote }}
resources:
requests:
storage: {{ .Values.persistence.providers.size | quote }}
{{- if .Values.persistence.storageClassName }}
storageClassName: "{{ .Values.persistence.storageClassName }}"
{{- end }}
---
{{- end }}

{{- if .Values.persistence.conf.enabled }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ include "keycloak.fullname" . }}-conf
namespace: {{ .Release.Namespace }}
labels:
{{- include "keycloak.labels" . | nindent 4 }}
spec:
accessModes:
- {{ .Values.persistence.accessMode | quote }}
resources:
requests:
storage: {{ .Values.persistence.conf.size | quote }}
{{- if .Values.persistence.storageClassName }}
storageClassName: "{{ .Values.persistence.storageClassName }}"
{{- end }}
---
{{- end }}

{{- if or .Values.persistence.data.enabled .Values.devMode }}
# devMode enables this PVC by default to preserve legacy behavior
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
Expand All @@ -8,11 +49,18 @@ metadata:
{{- include "keycloak.labels" . | nindent 4 }}
spec:
accessModes:
- ReadWriteOnce
- {{ .Values.persistence.accessMode | quote }}
resources:
requests:
storage: 512Mi
storage: {{ .Values.persistence.data.size | quote }}
{{- if .Values.persistence.storageClassName }}
storageClassName: "{{ .Values.persistence.storageClassName }}"
{{- end }}
---
{{- end }}

{{- if or .Values.persistence.themes.enabled .Values.devMode }}
# devMode enables this PVC by default to preserve legacy behavior
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
Expand All @@ -22,8 +70,11 @@ metadata:
{{- include "keycloak.labels" . | nindent 4 }}
spec:
accessModes:
- ReadWriteOnce
- {{ .Values.persistence.accessMode | quote }}
resources:
requests:
storage: 512Mi
storage: {{ .Values.persistence.themes.size | quote }}
{{- if .Values.persistence.storageClassName }}
storageClassName: "{{ .Values.persistence.storageClassName }}"
{{- end }}
{{- end }}
25 changes: 19 additions & 6 deletions src/keycloak/chart/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,32 @@ spec:
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
volumes:
- name: providers
{{- if .Values.persistence.providers.enabled }}
persistentVolumeClaim:
claimName: {{ include "keycloak.fullname" . }}-providers
{{- else }}
emptyDir: {}
{{- end }}
- name: conf
{{- if .Values.persistence.conf.enabled }}
persistentVolumeClaim:
claimName: {{ include "keycloak.fullname" . }}-conf
{{- else }}
emptyDir: {}
{{- if .Values.devMode }}
{{- end }}
- name: data
{{- if or .Values.persistence.data.enabled .Values.devMode }}
# devMode enables this PVC by default to preserve legacy behavior
persistentVolumeClaim:
claimName: {{ include "keycloak.fullname" . }}-data
{{- else }}
emptyDir: {}
{{- end }}
- name: themes
{{- if or .Values.persistence.themes.enabled .Values.devMode }}
# devMode enables this PVC by default to preserve legacy behavior
persistentVolumeClaim:
claimName: {{ include "keycloak.fullname" . }}-themes
{{- else }}
- name: data
emptyDir: {}
- name: themes
{{- else }}
emptyDir: {}
{{- end }}
{{- end }}
23 changes: 23 additions & 0 deletions src/keycloak/chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,29 @@ resources:
cpu: "1"
memory: "1Gi"

# Persistence settings for PVC management (when enabled=false, an emptyDir will be used)
# `devMode` overrides the enabled flag for `data` and `themes` to allow hot-reloads of the theme/plugin in k3d
#
# NOTE:
# Default persistence settings should be sufficient for *nearly all use cases*, especially when used in conjunction with
# the [uds-identity-config](https://github.com/defenseunicorns/uds-identity-config) image which is included by default.
# Unique situations may require changes, but care should be taken to account for an appropriate accessMode for your environment.
persistence:
accessMode: ReadWriteOnce
storageClassName: ""
providers:
enabled: false
size: "512Mi"
conf:
enabled: false
size: "512Mi"
data:
enabled: false
size: "512Mi"
themes:
enabled: false
size: "512Mi"

# Pod disruption budget
podDisruptionBudget: {}

Expand Down