apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "cups-airprint.fullname" . }}
  labels:
    {{- include "cups-airprint.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
{{- end }}
  selector:
    matchLabels:
      {{- include "cups-airprint.selectorLabels" . | nindent 6 }}
  template:
    metadata:
    {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      labels:
        {{- include "cups-airprint.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "cups-airprint.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 631
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          volumeMounts:
            - name: config
              mountPath: /config
            - name: spool
              mountPath: /var/spool/cups-pdf
            - name: avahi
              mountPath: /services
      volumes:
        - name: avahi
        {{- if .Values.avahi }}
          hostPath:
            path: "/etc/avahi/services"
            type: Directory
        {{- else }}
          emptyDir: {}
        {{- end }}
        - name: config
        {{- if .Values.persistence.enabled }}
          persistentVolumeClaim:
            claimName: {{ include "cups-airprint.fullname" . }}-config
        {{- else }}
          emptyDir: {}
        {{- end }}
        - name: spool
        {{- if .Values.persistence.enabled }}
          persistentVolumeClaim:
            claimName: {{ include "cups-airprint.fullname" . }}-spool
        {{- else }}
          emptyDir: {}
        {{- end }}
      {{- if .Values.hostNetwork }}
      hostNetwork: {{ .Values.hostNetwork }}
      {{- end }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
