apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "homeassistant.fullname" . }}
  labels:
    {{- include "homeassistant.labels" . | nindent 4 }}
spec:
  selector:
    matchLabels:
      {{- include "homeassistant.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "homeassistant.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        # livenessProbe:
        #   httpGet:
        #     path: /
        #     port: http
        #     scheme: HTTP
        ports:
        - name: http
          containerPort: 8123
          protocol: TCP
        readinessProbe:
          httpGet:
            port: http
            path: /
            scheme: HTTP
        # startupProbe:
        #   httpGet:
        #     port: http
        #     path: /
        #     scheme: HTTP
        resources:
          {{- toYaml .Values.resources | nindent 12 }}
        securityContext:
          {{- toYaml .Values.securityContext | nindent 12 }}
        {{- if .Values.persistentStorage.enabled }}
        volumeMounts:
        - name: config
          mountPath: /config
        {{- end }}
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- if .Values.podPriorityClassName }}
      priorityClassName: {{ .Values.podPriorityClassName }}
      {{- end }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- if .Values.persistentStorage.enabled }}
      volumes:
      {{- if .Values.persistentStorage.existingClaim }}
      - name: config
        persistentVolumeClaim:
          claimName: {{ .Values.persistentStorage.existingClaim }}
      {{- else }}
      - name: config
        persistentVolumeClaim:
          claimName: {{ include "homeassistant.fullname" . }}
      {{- end }}
      {{- end }}