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

{{- if not .Values.core.existingEnvVarsSecret }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "harbor.core.envvars.secretName" . }}
  namespace: {{ include "common.names.namespace" . | quote }}
  {{- $versionLabel := dict "app.kubernetes.io/version" ( include "common.images.version" ( dict "imageRoot" .Values.core.image "chart" .Chart ) ) }}
  {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list .Values.commonLabels $versionLabel ) "context" . ) }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" . ) | nindent 4 }}
    app.kubernetes.io/component: core
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" . ) | nindent 4 }}
  {{- end }}
type: Opaque
data:
  _REDIS_URL_CORE: {{ include "harbor.redisForCore" . | b64enc | quote }}
  _REDIS_URL_REG: {{ include "harbor.redisForGC" . | b64enc | quote }}
  REGISTRY_CREDENTIAL_USERNAME: {{ .Values.registry.credentials.username | b64enc | quote }}
  REGISTRY_CREDENTIAL_PASSWORD: {{ .Values.registry.credentials.password | b64enc | quote }}
  CSRF_KEY: {{ include "common.secrets.passwords.manage" (dict "secret" (include "harbor.core.envvars.secretName" .) "key" "CSRF_KEY" "length" 32 "providedValues" (list "core.csrfKey") "context" .) }}
  {{- if not .Values.existingSecret }}
  HARBOR_ADMIN_PASSWORD: {{ include "common.secrets.passwords.manage" (dict "secret" (include "harbor.core.envvars.secretName" .) "key" "HARBOR_ADMIN_PASSWORD" "length" 22 "providedValues" (list "adminPassword") "context" .) }}
  {{- end }}
  {{- if or .Values.postgresql.enabled (not .Values.externalDatabase.existingSecret) }}
  POSTGRESQL_PASSWORD: {{ include "harbor.database.rawPassword" . | b64enc | quote }}
  {{- end }}
{{- end }}
