{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}
{{- if .Values.dremio.auth.enabled }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "common.names.fullname" . }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: dremio
    {{- /* We need an extra label that applies to both master and non-master coordinators. Taken from upstream dremio chart */}}
    app: dremio-coordinator
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
type: Opaque
data:
  dremio-password: {{ include "common.secrets.passwords.manage" (dict "secret" ( include "common.names.fullname" .) "key" "dremio-password" "providedValues" (list "dremio.auth.password") "context" $) }}
{{- end }}
{{- if and (or .Values.dremio.tls.autoGenerated.enabled .Values.dremio.tls.existingSecret) (not .Values.dremio.tls.passwordSecret) }}
---
apiVersion: v1
kind: Secret
metadata:
  name: {{ printf "%s-tls-pass" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: dremio
    {{- /* We need an extra label that applies to both master and non-master coordinators. Taken from upstream dremio chart */}}
    app: dremio-coordinator
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
type: Opaque
data:
  {{- if .Values.dremio.tls.existingSecret }}
  {{- $pass := required "If 'dremio.tls.existingSecret' is provided, providing a JKS password is mandatory" .Values.dremio.tls.password }}
  {{- end }}
  keystore-password: {{ include "common.secrets.passwords.manage" (dict "secret" ( printf "%s-tls-pass" (include "common.names.fullname" .)) "key" "keystore-password" "providedValues" (list "dremio.tls.password") "context" $) }}
{{- end }}
