{{- if .Values.varnish.enabled -}}
{{- $name := "varnish" -}}
{{- $data := dict "name" $name "Chart" .Chart "Release" .Release "Values" .Values -}}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "api.fullname" . }}-{{ $name }}
  labels:
    {{- include "api.labels" $data | nindent 4 }}
spec:
  replicas: {{ .Values.varnish.replicaCount }}
  selector:
    matchLabels:
      {{- include "api.selectorLabels" $data | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "api.selectorLabels" $data | nindent 8 }}
    spec:
    {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      serviceAccountName: {{ include "api.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}-{{ $name }}
          image: "{{ .Values.varnish.image.repository }}:{{ .Values.varnish.image.tag }}"
          imagePullPolicy: {{ .Values.varnish.image.pullPolicy }}
          command: ["varnishd"]
          args: ["-F", "-f", "/etc/varnish/default.vcl", "-p", "http_resp_hdr_len=65536", "-p", "http_resp_size=98304"]
          ports:
            - containerPort: 80
          livenessProbe:
            httpGet:
              path: /healthz
              port: 80
          readinessProbe:
            httpGet:
              path: /healthz
              port: 80
          resources:
{{ toYaml .Values.resources | indent 12 }}
    {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
    {{- end }}
{{- end -}}
