{{ include "common.storage.hostPathValidate" .Values }}
apiVersion: {{ template "common.capabilities.deployment.apiVersion" . }}
kind: Deployment
metadata:
  name: {{ template "common.names.fullname" . }}
  labels:
    app: {{ template "common.names.name" . }}
    chart: {{ template "common.names.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
  annotations:
    rollme: {{ randAlphaNum 5 | quote }}
spec:
  replicas: {{ (default 1 .Values.replicas) }}
  strategy:
    type: "Recreate"
  selector:
    matchLabels:
      app: {{ template "common.names.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      name: {{ template "common.names.fullname" . }}
      labels:
        app: {{ template "common.names.name" . }}
        release: {{ .Release.Name }}
        {{- include "common.labels.selectorLabels" . | nindent 8 }}
      annotations: {{ include "common.annotations" . | nindent 8 }}
    spec:
      hostNetwork: false
      containers:
        - name: {{ .Chart.Name }}
          {{ include "common.resources.limitation" . | nindent 10 }}
          {{ include "common.containers.imageConfig" .Values.image | nindent 10 }}
          volumeMounts: {{ include "common.storage.configureAppVolumeMountsInContainer" .Values | nindent 12 }}
          {{ range $index, $hostPathConfiguration := .Values.extraAppVolumeMounts }}
            - name: extrappvolume-{{ $index }}
              mountPath: {{ $hostPathConfiguration.mountPath }}
          {{ end }}
          ports:
            - name: web
              containerPort: 2342
          readinessProbe:
            httpGet:
              path: /
              port: 2342
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 5
            successThreshold: 2
          livenessProbe:
            httpGet:
              path: /
              port: 2342
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 5
            successThreshold: 1
          startupProbe:
            httpGet:
              path: /
              port: 2342
            initialDelaySeconds: 10
            periodSeconds: 5
            timeoutSeconds: 2
            failureThreshold: 60
            successThreshold: 1
          env:
            {{ $secretName := (include "common.names.fullname" .) }}
            {{ $envList := (default list .Values.environmentVariables) }}
            {{ $envList = mustAppend $envList (dict "name" "PHOTOPRISM_ADMIN_PASSWORD" "valueFromSecret" true "secretName" $secretName "secretKey" "password") }}
            {{ if .Values.public }}
            {{ $envList = mustAppend $envList (dict "name" "PHOTOPRISM_PUBLIC" "value" "true") }}
            {{ end }}
            {{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) | nindent 12 }}
{{ include "common.networking.dnsConfiguration" .Values | nindent 6 }}
      volumes: {{ include "common.storage.configureAppVolumes" .Values | nindent 8 }}
      {{ range $index, $hostPathConfiguration := .Values.extraAppVolumeMounts }}
        - name: extrappvolume-{{ $index }}
          hostPath:
            path: {{ $hostPathConfiguration.hostPath }}
      {{ end }}
