{{- if (include "kafka.createJaasSecret" .) }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "kafka.fullname" . }}-jaas
  labels: {{- include "kafka.labels" . | nindent 4 }}
    {{- if .Values.commonLabels }}
    {{- include "kafka.tplValue" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "kafka.tplValue" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
type: Opaque
data:
  {{- if (include "kafka.client.saslAuthentication" .) }}
  {{- if .Values.auth.jaas.clientPasswords }}
  client-passwords: {{ join "," .Values.auth.jaas.clientPasswords | b64enc | quote }}
  {{- else }}
  {{- $passwords := list }}
  {{- range .Values.auth.jaas.clientUsers }}
  {{- $passwords = append $passwords (randAlphaNum 10) }}
  {{- end }}
  client-passwords: {{ join "," $passwords | b64enc | quote }}
  {{- end }}
  {{- end }}
  {{- if .Values.auth.jaas.zookeeperUser }}
  zookeeper-password: {{ ternary (randAlphaNum 10) .Values.auth.jaas.zookeeperPassword (empty .Values.auth.jaas.zookeeperPassword) | b64enc | quote }}
  {{- end }}
  {{- if (include "kafka.interBroker.saslAuthentication" .) }}
  inter-broker-password: {{ ternary (randAlphaNum 10) .Values.auth.jaas.interBrokerPassword (empty .Values.auth.jaas.interBrokerPassword) | b64enc | quote }}
  {{- end }}
{{- end }}
