{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if (include "elasticsearch.createSecret" . ) }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "common.names.fullname" . }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
type: Opaque
data:
  elasticsearch-password: {{ include "common.secrets.passwords.manage" (dict "secret" (include "common.names.fullname" .) "key" "elasticsearch-password" "length" 16 "providedValues" (list "security.elasticPassword") "context" $) }}
{{- end }}
{{- if (include "elasticsearch.createTlsPasswordsSecret" . ) }}
---
apiVersion: v1
kind: Secret
metadata:
  name: {{ printf "%s-tls-pass" (include "common.names.fullname" .) }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
type: Opaque
data:
  {{- if .Values.security.tls.keystorePassword }}
  keystore-password: {{ default "" .Values.security.tls.keystorePassword | b64enc | quote }}
  {{- end }}
  {{- if .Values.security.tls.truststorePassword }}
  truststore-password: {{ default "" .Values.security.tls.truststorePassword | b64enc | quote }}
  {{- end }}
  {{- if .Values.security.tls.keyPassword }}
  key-password: {{ default "" .Values.security.tls.keyPassword | b64enc | quote }}
  {{- end }}
{{- end }}
