apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "casdoor.fullname" . }}
  labels:
    {{- include "casdoor.labels" . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "casdoor.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      annotations:
        checksum/config: {{ tpl .Values.config . | toYaml | sha256sum }}
        {{- with .Values.podAnnotations }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      labels:
        {{- include "casdoor.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "casdoor.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}/{{ .Values.image.name }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          # command: ["sleep", "100000000"]
          env:
            - name: RUNNING_IN_DOCKER
              value: "true"
          ports:
            - name: http
              containerPort: {{ .Values.service.port }}
              protocol: TCP
          {{ if .Values.probe.liveness.enabled }}
          livenessProbe:
            httpGet:
              path: /
              port: http
          {{ end }}
          {{ if .Values.probe.readiness.enabled }}
          readinessProbe:
            httpGet:
              path: /
              port: http
          {{ end }}
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          volumeMounts:
          - name: config-volume
            mountPath: /conf
      volumes:
       - name: config-volume
         projected:
           defaultMode: 420
           sources:
           - configMap:
               items:
               - key: app.conf
                 path: app.conf
               name: {{ printf "%s-config" (include "casdoor.fullname" .) }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
