{{- if (include "kibana.createSecret" .) -}}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "common.names.fullname" . }}
  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 and .Values.elasticsearch.security.auth.enabled (not .Values.elasticsearch.security.auth.existingSecret) }}
  kibana-password: {{ required "A Kibana password is required!" .Values.elasticsearch.security.auth.kibanaPassword | b64enc }}
  {{- end }}
  {{- if and .Values.tls.enabled (not .Values.tls.passwordsSecret) }}
  {{- if .Values.tls.keyPassword }}
  kibana-key-password: {{ .Values.tls.keyPassword | b64enc | quote }}
  {{- end }}
  {{- if .Values.tls.keystorePassword }}
  kibana-keystore-password: {{.Values.tls.keystorePassword | b64enc | quote }}
  {{- end }}
  {{- end }}
  {{- if and .Values.elasticsearch.security.tls.enabled .Values.elasticsearch.security.tls.truststorePassword (not .Values.elasticsearch.security.tls.passwordsSecret) }}
  elasticsearch-truststore-password: {{ .Values.elasticsearch.security.tls.truststorePassword | b64enc | quote }}
  {{- end }}
{{- end }}
