{{- if .Values.defaultBackend.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "nginx-ingress.defaultBackend.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels: {{- include "nginx-ingress.labels" . | nindent 4 }}
    component: {{ .Values.defaultBackend.name }}
    {{- if .Values.commonLabels }}
    {{- include "nginx-ingress.tplValue" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
    {{- end }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "nginx-ingress.annotations" (dict "annotations" .Values.commonAnnotations "context" $) | trim | nindent 4 }}
  {{- end }}
spec:
  selector:
    matchLabels: {{- include "nginx-ingress.matchLabels" . | nindent 6 }}
      component: {{ .Values.defaultBackend.name }}
  replicas: {{ .Values.defaultBackend.replicaCount }}
  revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
  template:
    metadata:
      {{- if .Values.defaultBackend.podAnnotations }}
      annotations: {{- include "nginx-ingress.annotations" (dict "annotations" .Values.defaultBackend.podAnnotations "context" $) | trim | nindent 8 }}
      {{- end }}
      labels: {{- include "nginx-ingress.labels" . | nindent 8 }}
        component: {{ .Values.defaultBackend.name }}
        {{- if .Values.defaultBackend.podLabels }}
        {{- include "nginx-ingress.tplValue" (dict "value" .Values.defaultBackend.podLabels "context" $) | nindent 8 }}
        {{- end }}
    spec:
{{- include "nginx-ingress-controller.imagePullSecrets" . | indent 6 }}
      {{- if .Values.defaultBackend.priorityClassName }}
      priorityClassName: {{ .Values.defaultBackend.priorityClassName | quote }}
      {{- end }}
      {{- if .Values.defaultBackend.affinity }}
      affinity: {{- include "nginx-ingress.tplValue" (dict "value" .Values.defaultBackend.affinity "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.defaultBackend.nodeSelector }}
      nodeSelector: {{- include "nginx-ingress.tplValue" (dict "value" .Values.defaultBackend.nodeSelector "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.defaultBackend.tolerations }}
      tolerations: {{- include "nginx-ingress.tplValue" (dict "value" .Values.defaultBackend.tolerations "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.defaultBackend.podSecurityContext }}
      securityContext: {{- toYaml .Values.defaultBackend.podSecurityContext | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ template "nginx-ingress.serviceAccountName" . }}
      terminationGracePeriodSeconds: 60
      containers:
        - name: {{ template "nginx-ingress.name" . }}-{{ .Values.defaultBackend.name }}
          image: {{ template "nginx-ingress-controller.defaultBackend.image" . }}
          imagePullPolicy: {{ .Values.defaultBackend.image.pullPolicy | quote }}
          args:
          {{- range $key, $value := .Values.defaultBackend.extraArgs }}
            {{- if $value }}
            - --{{ $key }}={{ $value }}
            {{- else }}
            - --{{ $key }}
            {{- end }}
          {{- end }}
          securityContext:
            runAsUser: {{ .Values.securityContext.runAsUser }}
          livenessProbe:
            httpGet:
              path: {{ .Values.defaultBackend.livenessProbe.path }}
              port: {{ .Values.defaultBackend.port }}
              scheme: HTTP
            initialDelaySeconds: {{ .Values.defaultBackend.livenessProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.defaultBackend.livenessProbe.periodSeconds }}
            timeoutSeconds: {{ .Values.defaultBackend.livenessProbe.timeoutSeconds }}
            successThreshold: {{ .Values.defaultBackend.livenessProbe.successThreshold }}
            failureThreshold: {{ .Values.defaultBackend.livenessProbe.failureThreshold }}
          readinessProbe:
            httpGet:
              path: {{ .Values.defaultBackend.readinessProbe.path }}
              port: {{ .Values.defaultBackend.port }}
              scheme: HTTP
            initialDelaySeconds: {{ .Values.defaultBackend.readinessProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.defaultBackend.readinessProbe.periodSeconds }}
            timeoutSeconds: {{ .Values.defaultBackend.readinessProbe.timeoutSeconds }}
            successThreshold: {{ .Values.defaultBackend.readinessProbe.successThreshold }}
            failureThreshold: {{ .Values.defaultBackend.readinessProbe.failureThreshold }}
          ports:
            - name: http
              containerPort: {{ .Values.defaultBackend.port }}
              protocol: TCP
          resources: {{- toYaml .Values.defaultBackend.resources | nindent 12 }}
{{- end }}
