{{- if .Values.frontend.enabled -}}
{{- $fullName := include "gitdata.fullname" . -}}
{{- $ns := include "gitdata.namespace" . -}}
{{- $svc := .Values.frontend -}}

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ $fullName }}-frontend
  namespace: {{ $ns }}
  labels:
    app.kubernetes.io/name: {{ $fullName }}-frontend
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/version: {{ .Chart.AppVersion }}
spec:
  replicas: {{ $svc.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ $fullName }}-frontend
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ $fullName }}-frontend
        app.kubernetes.io/instance: {{ .Release.Name }}
    spec:
      {{- if $.Values.image.pullSecrets }}
      imagePullSecrets:
        {{- range $.Values.image.pullSecrets }}
        - name: {{ . }}
        {{- end }}
      {{- end }}
      containers:
        - name: frontend
          image: "{{ $.Values.image.registry }}/{{ $svc.image.repository }}:{{ $svc.image.tag }}"
          imagePullPolicy: {{ $svc.image.pullPolicy | default $.Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: {{ $svc.livenessProbe.initialDelaySeconds }}
            periodSeconds: {{ $svc.livenessProbe.periodSeconds }}
          readinessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: {{ $svc.readinessProbe.initialDelaySeconds }}
            periodSeconds: {{ $svc.readinessProbe.periodSeconds }}
      {{- with $svc.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with $svc.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with $svc.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}

---
apiVersion: v1
kind: Service
metadata:
  name: {{ $fullName }}-frontend
  namespace: {{ $ns }}
  labels:
    app.kubernetes.io/name: {{ $fullName }}-frontend
    app.kubernetes.io/instance: {{ .Release.Name }}
spec:
  type: {{ $svc.service.type }}
  ports:
    - name: http
      port: 80
      targetPort: 80
      protocol: TCP
  selector:
    app.kubernetes.io/name: {{ $fullName }}-frontend
    app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
