apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ printf "%s-env-vars" (include "common.names.fullname" .) }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: keycloak
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
data:
  KEYCLOAK_ADMIN: {{ .Values.auth.adminUser | quote }}
  KEYCLOAK_HTTP_PORT: {{ .Values.containerPorts.http | quote }}
  KEYCLOAK_PROXY: {{ .Values.proxy | quote }}
  KEYCLOAK_ENABLE_STATISTICS: {{ ternary "true" "false" .Values.metrics.enabled | quote }}
  KEYCLOAK_DATABASE_HOST: {{ include "keycloak.databaseHost" . | quote }}
  KEYCLOAK_DATABASE_PORT: {{ include "keycloak.databasePort" . }}
  KEYCLOAK_DATABASE_NAME: {{ include "keycloak.databaseName" . | quote }}
  KEYCLOAK_DATABASE_USER: {{ include "keycloak.databaseUser" . | quote }}
  KEYCLOAK_PRODUCTION:  {{ ternary "true" "false" .Values.production | quote }}
  KEYCLOAK_ENABLE_HTTPS: {{ ternary "true" "false" .Values.tls.enabled | quote }}
  {{- if .Values.tls.enabled }}
  KEYCLOAK_HTTPS_PORT: {{ .Values.containerPorts.https | quote }}
  KEYCLOAK_HTTPS_USE_PEM: {{ ternary "true" "false" (or .Values.tls.usePem .Values.tls.autoGenerated) | quote }}
  {{- if or .Values.tls.usePem .Values.tls.autoGenerated }}
  KEYCLOAK_HTTPS_CERTIFICATE_FILE: "/opt/bitnami/keycloak/certs/tls.crt"
  KEYCLOAK_HTTPS_CERTIFICATE_KEY_FILE: "/opt/bitnami/keycloak/certs/tls.key"
  {{- else }}
  KEYCLOAK_HTTPS_KEY_STORE_FILE: {{ printf "/opt/bitnami/keycloak/certs/%s" .Values.tls.keystoreFilename | quote }}
  KEYCLOAK_HTTPS_TRUST_STORE_FILE: {{ printf "/opt/bitnami/keycloak/certs/%s" .Values.tls.truststoreFilename | quote }}
  {{- end }}
  {{- end }}
  {{- if .Values.spi.existingSecret }}
  {{- if .Values.spi.hostnameVerificationPolicy }}
  KEYCLOAK_SPI_TRUSTSTORE_FILE_HOSTNAME_VERIFICATION_POLICY: {{ .Values.spi.hostnameVerificationPolicy | quote }}
  {{- end }}
  KEYCLOAK_SPI_TRUSTSTORE_FILE: {{ printf "/opt/bitnami/keycloak/spi-certs/%s" .Values.spi.truststoreFilename }}
  {{- end }}
  {{- if .Values.cache.enabled }}
  KEYCLOAK_CACHE_TYPE: "ispn"
  {{- if .Values.cache.stackName }}
  KEYCLOAK_CACHE_STACK: {{ .Values.cache.stackName | quote }} 
  {{- end }}
  {{- if .Values.cache.stackFile }}
  KEYCLOAK_CACHE_CONFIG_FILE: {{ .Values.cache.stackFile | quote }} 
  {{- end }}
  JAVA_OPTS_APPEND: {{ printf "-Djgroups.dns.query=%s-headless.%s.svc.%s" (include "common.names.fullname" .) (include "common.names.namespace" .) .Values.clusterDomain | quote }}
  {{- else }}
  KEYCLOAK_CACHE_TYPE: "local"
  {{- end }}
  {{- if .Values.logging }}
  KEYCLOAK_LOG_OUTPUT: {{ .Values.logging.output | quote }}
  KC_LOG_LEVEL: {{ .Values.logging.level | quote }}
  {{- end }}

