{{- $defaultName := printf "%s-%s" "frontend" .Chart.AppVersion -}}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "imghost-helm.fullname" . }}-frontend
  labels:
    component: frontend
    {{- include "imghost-helm.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      component: frontend
      {{- include "imghost-helm.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        component: frontend
        {{- include "imghost-helm.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      volumes:
        - name: data
          {{- .Values.volumes.data | nindent 10 }}
        - name: cache
          {{- .Values.volumes.cache | nindent 10 }}
        - name: config
          secret:
            secretName: {{ include "imghost-helm.fullname" . }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.frontend.repository }}:{{ .Values.frontend.tag | default $defaultName }}"
          imagePullPolicy: {{ .Values.frontend.pullPolicy }}
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
          startupProbe:
            httpGet:
              path: /healthz
              port: http
          livenessProbe:
            httpGet:
              path: /healthz
              port: http
          readinessProbe:
            httpGet:
              path: /healthz
              port: http
          resources:
            {{- toYaml .Values.frontend.resources | nindent 12 }}
          volumeMounts:
            - mountPath: "/config.yaml"
              name: config
              subPath: "config"
            - mountPath: "/data"
              name: data
            - mountPath: "/cache"
              name: cache
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}