apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "dashboard-cpms.fullname" . }}
  labels:
    {{- include "dashboard-cpms.labels" . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "dashboard-cpms.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "dashboard-cpms.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "dashboard-cpms.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: 80
              protocol: TCP
          volumeMounts:
            - name: "{{.Values.secret.name }}"
              mountPath: /var/www/html/.env
              subPath: .env
            - mountPath: /tmp
              name: tmpfs-2
            - mountPath: /var/log/supervisord.log
              name: tmpfs-log
            - mountPath: /var/run
              name: tmpfs-1
            - mountPath: /run/apache2
              name: tmpfs-3
            - mountPath: /var/www/html/storage/framework/session
              name: tmpfs-4
            - mountPath: /var/www/html/storage/framework/views
              name: tmpfs-5
            - mountPath: /var/www/html/storage/logs
              name: tmpfs-6
          # livenessProbe:
          #   httpGet:
          #     path: /healthcheck
          #     port: 80
          #   initialDelaySeconds: 20
          #   timeoutSeconds: 1
          #   successThreshold: 1
          #   failureThreshold: 5
          # readinessProbe:
          #   httpGet:
          #     path: /healthcheck
          #     port: 80
          #   initialDelaySeconds: 20
          #   timeoutSeconds: 1
          #   successThreshold: 1
          #   failureThreshold: 5
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
            

      volumes:
        - name:  "{{.Values.secret.name }}"
          secret:
            secretName: "{{ include "dashboard-cpms.fullname" . }}-{{ .Release.Revision}}"
        - name: tmpfs-2
          emptyDir: {}
        - name: tmpfs-log
          emptyDir: {}
        - name: tmpfs-1
          emptyDir: {}
        - name: tmpfs-3
          emptyDir: {}
        - name: tmpfs-4
          emptyDir: {}
        - name: tmpfs-5
          emptyDir: {}
        - name: tmpfs-6
          emptyDir: {}
        # - name: mysql-db
        #   emptyDir: {}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}

