{{/* Make sure all variables are set properly */}}
{{- include "tc.v1.common.loader.init" . }}

{{/* Render secrets for gitea */}}
{{- $secrets := include "gitea.secrets" . | fromYaml -}}
{{- if $secrets -}}
  {{- $_ := mustMergeOverwrite .Values.secret $secrets -}}
{{- end -}}

{{/* Render configmap for gitea */}}
{{- $configmap := include "gitea.configmap" . | fromYaml -}}
{{- if $configmap -}}
  {{- $_ := set .Values.configmap "gitea-env" $configmap -}}
{{- end -}}

{{/* Append the general secret volumes to the volumes */}}
{{- define "gitea.initvolume" -}}
enabled: true
readOnly: true
type: secret
objectName: init
defaultMode: "0777"
targetSelector:
  main:
    main:
      mountPath: /secrets/ini
    1-init-directories:
      mountPath: "/usr/sbin"
    2-configure-gitea:
      mountPath: "/usr/sbin"
{{- end -}}

{{/* Append the general secret volumes to the volumes */}}
{{- define "gitea.configvolume" -}}
enabled: true
readOnly: true
type: secret
objectName: secret
targetSelector:
  main:
    main:
      mountPath: /secrets/config
    1-init-directories:
      mountPath: /etc/gitea/conf
{{- end -}}

{{- $_ := set .Values.persistence "init" (include "gitea.initvolume" . | fromYaml) -}}
{{- $_ := set .Values.persistence "config" (include "gitea.configvolume" . | fromYaml) -}}


{{/* Render the templates */}}
{{ include "tc.v1.common.loader.apply" . }}
