{{- if (include "kafka.createJaasSecret" .) }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ printf "%s-jaas" (include "common.names.fullname" .) }}
  namespace: {{ .Release.Namespace | quote }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    {{- 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 }}
type: Opaque
data:
  {{- if (include "kafka.client.saslAuthentication" .) }}
  {{- $clientUsers := .Values.auth.sasl.jaas.clientUsers }}
  {{- $clientPasswords := .Values.auth.sasl.jaas.clientPasswords }}
  {{- if $clientPasswords }}
  client-passwords: {{ join "," $clientPasswords | b64enc | quote }}
  system-user-password: {{ index $clientPasswords 0 | b64enc | quote }}
  {{- else }}
  {{- $passwords := list }}
  {{- range $clientUsers }}
  {{- $passwords = append $passwords (randAlphaNum 10) }}
  {{- end }}
  client-passwords: {{ join "," $passwords | b64enc | quote }}
  system-user-password: {{ index $passwords 0 | b64enc | quote }}
  {{- end }}
  {{- end }}
  {{- $zookeeperUser := .Values.auth.sasl.jaas.zookeeperUser }}
  {{- if and .Values.zookeeper.auth.client.enabled $zookeeperUser }}
  {{- $zookeeperPassword := .Values.auth.sasl.jaas.zookeeperPassword }}
  zookeeper-password: {{ default (randAlphaNum 10) $zookeeperPassword | b64enc | quote }}
  {{- end }}
  {{- if (include "kafka.interBroker.saslAuthentication" .) }}
  {{- $interBrokerPassword := .Values.auth.sasl.jaas.interBrokerPassword }}
  inter-broker-password: {{ default (randAlphaNum 10) $interBrokerPassword | b64enc | quote }}
  {{- end }}
{{- end }}
