---
{{- if not (or .Values.postgresql.enabled .Values.postgresql.existingSecret .Values.jdbcOverwrite.jdbcSecretName)}}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "sonarqube.fullname" . }}
  labels:
    app: {{ template "sonarqube.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
type: Opaque
data:
  {{ template "jdbc.secretPasswordKey" . }}: {{ template "jdbc.internalSecretPasswd" . }}
{{- end }}
---
{{- if .Values.monitoringPasscode}}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "sonarqube.fullname" . }}-monitoring-passcode
  labels:
    app: {{ template "sonarqube.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
type: Opaque
data:
  SONAR_WEB_SYSTEMPASSCODE: {{ .Values.monitoringPasscode | b64enc | quote }}
{{- end }}
---
{{- if and .Values.monitoringPasscode .Values.prometheusMonitoring.podMonitor.enabled}}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "sonarqube.fullname" . }}-monitoring-passcode
  namespace: {{.Values.prometheusMonitoring.podMonitor.namespace}}
  labels:
    app: {{ template "sonarqube.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
type: Opaque
data:
  SONAR_WEB_SYSTEMPASSCODE: {{ .Values.monitoringPasscode | b64enc | quote }}
{{- end }}
---
{{- if .Values.account }}
{{- if .Values.account.adminPassword }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "sonarqube.fullname" . }}-admin-password
  labels:
    app: {{ template "sonarqube.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
type: Opaque
stringData:
  password: {{ .Values.account.adminPassword | urlquery | quote }}
  currentPassword: {{ default "admin" .Values.account.currentAdminPassword | urlquery | quote }}
{{- end }}
{{- end }}
