{{/*
Create helm partial for gitea server
*/}}
{{- define "gitea" }}
- name: gitea
  image: {{ .Values.images.gitea }}
  imagePullPolicy: {{ .Values.images.pullPolicy }}
  env:
  {{- if .Values.env }}
  {{- toYaml .Values.env | nindent 2 }}
  {{- end }}
  {{- if .Values.externalDB.existingSecret.enabled }}
  - name: EXTERNALDB_USER
    valueFrom:
      secretKeyRef:
        name: {{ .Values.externalDB.existingSecret.secretName | default (printf "%s-%s" .Release.Name "db") }}
        key: {{ .Values.externalDB.existingSecret.usernameKey | default "db-username" }}
  - name: EXTERNALDB_PASS
    valueFrom:
      secretKeyRef:
        name: {{ .Values.externalDB.existingSecret.secretName | default (printf "%s-%s" .Release.Name "db") }}
        key: {{ .Values.externalDB.existingSecret.passwordKey | default "db-password" }}
  {{- end }}
  {{- if .Values.mariadb.enabled }}
  - name: DATABASE_PASSWORD
    valueFrom:
      secretKeyRef:
        name: {{ template "mariadb.fullname" . }}
        key: mariadb-password
  {{- end }}
  ports:
  - name: ssh
    containerPort: 22
  - name: http
    containerPort: 3000
  livenessProbe:
    tcpSocket:
      port: http
    initialDelaySeconds: 200
    timeoutSeconds: 1
    periodSeconds: 10
    successThreshold: 1
    failureThreshold: 10
  readinessProbe:
    tcpSocket:
      port: http
    initialDelaySeconds: 5
    periodSeconds: 10
    successThreshold: 1
    failureThreshold: 3
  resources:
{{ toYaml .Values.resources.gitea | indent 4 }}
  volumeMounts:
  - name: gitea-data
    mountPath: /data
  - name: gitea-lfs
    mountPath: /app/gitea/data/lfs
  - name: gitea-config
    mountPath: /etc/gitea
{{- end }}
