apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "freeleaps-devops-reconciler.fullname" . }}
  labels:
    {{- include "freeleaps-devops-reconciler.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  strategy:
    {{- toYaml .Values.strategy | nindent 4 }}
  selector:
    matchLabels:
      {{- include "freeleaps-devops-reconciler.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      annotations:
        {{- with .Values.podAnnotations }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
        # Force pod restart on secret changes
        checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
      labels:
        {{- include "freeleaps-devops-reconciler.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "freeleaps-devops-reconciler.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: {{ include "freeleaps-devops-reconciler.image" . }}
          imagePullPolicy: {{ .Values.reconciler.image.pullPolicy }}
          ports:
            - name: http
              containerPort: {{ .Values.service.targetPort }}
              protocol: TCP
          env:
            {{- include "freeleaps-devops-reconciler.env" . | nindent 12 }}
          {{- if .Values.healthcheck.livenessProbe.enabled }}
          livenessProbe:
            {{- with .Values.healthcheck.livenessProbe.httpGet }}
            httpGet:
              {{- toYaml . | nindent 14 }}
            {{- end }}
            initialDelaySeconds: {{ .Values.healthcheck.livenessProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.healthcheck.livenessProbe.periodSeconds }}
            timeoutSeconds: {{ .Values.healthcheck.livenessProbe.timeoutSeconds }}
            failureThreshold: {{ .Values.healthcheck.livenessProbe.failureThreshold }}
          {{- end }}
          {{- if .Values.healthcheck.readinessProbe.enabled }}
          readinessProbe:
            {{- with .Values.healthcheck.readinessProbe.httpGet }}
            httpGet:
              {{- toYaml . | nindent 14 }}
            {{- end }}
            initialDelaySeconds: {{ .Values.healthcheck.readinessProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.healthcheck.readinessProbe.periodSeconds }}
            timeoutSeconds: {{ .Values.healthcheck.readinessProbe.timeoutSeconds }}
            failureThreshold: {{ .Values.healthcheck.readinessProbe.failureThreshold }}
          {{- end }}
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          volumeMounts:
            {{- if .Values.securityContext.readOnlyRootFilesystem }}
            - name: tmp
              mountPath: /tmp
            - name: logs
              mountPath: /app/logs
            {{- end }}
      volumes:
        {{- if .Values.securityContext.readOnlyRootFilesystem }}
        - name: tmp
          emptyDir: {}
        - name: logs
          emptyDir: {}
        {{- 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 }}