apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Chart.Name }}
  labels:
    app: {{ .Chart.Name }}
spec:
  selector:
    matchLabels:
      app: {{ .Chart.Name }}
  {{- if not .Values.global.registry.userProcessManagement.hpa.enabled }}
  replicas: {{ .Values.global.registry.userProcessManagement.replicas }}
  {{- end }}
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      {{- if or .Values.podAnnotations .Values.global.registry.userProcessManagement.istio.sidecar.enabled }}
      annotations:
        {{- range $key, $value := .Values.podAnnotations }}
        {{ $key }}: {{ $value | quote }}
        {{- end }}
        {{- if .Values.global.registry.userProcessManagement.istio.sidecar.enabled }}
        traffic.sidecar.istio.io/excludeOutboundPorts: '6379'
        sidecar.istio.io/inject: 'true'
        {{- include "userProcessManagement.istioResources" . | nindent 8 }}
        {{- end }}
      {{- end }}
      labels:
        app: {{ .Chart.Name }}
        collect.logs: "json"
    spec:
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.name }}:{{ .Values.image.version }}"
        ports:
          - containerPort: {{ .Values.port }}
            name: ui
        livenessProbe:
          httpGet:
            path: {{ .Values.livenessPath }}
            port: {{ .Values.port }}
          failureThreshold: 10
          initialDelaySeconds: 70
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 5
        readinessProbe:
          httpGet:
            path: {{ .Values.readinessPath }}
            port: {{ .Values.port }}
          failureThreshold: 10
          initialDelaySeconds: 70
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 5
        {{- if or .Values.global.registry.userProcessManagement.container.resources.requests .Values.global.registry.userProcessManagement.container.resources.limits }}
        resources:
          {{- toYaml .Values.global.registry.userProcessManagement.container.resources | nindent 10 }}
        {{- end }}
        env:
          {{- range $name, $value := .Values.global.registry.userProcessManagement.container.envVars }}
          - name: {{ $name }}
            value: {{ $value | quote}}
          {{- end }}
          - name: REDIS_PASSWORD
            valueFrom:
              secretKeyRef:
                name: {{ .Values.redis.secretName }}
                key: password
        volumeMounts:
          - name: {{ .Chart.Name }}
            mountPath: {{ .Values.appConfigMountPath }}
          - name: {{ .Chart.Name }}-redis-credentials
            mountPath: {{ .Values.redisSecretsMountPath }}
          - name: {{ .Values.bpGrouping.configName }}
            mountPath: {{ .Values.appConfigMountPath }}/{{ .Values.bpGrouping.configName }}
      serviceAccountName: {{ .Chart.Name }}
      {{- if .Values.nodeSelector }}
      nodeSelector: {{ toYaml .Values.nodeSelector | nindent 8 }}
      {{- end }}
      {{- if .Values.podSecurityContext }}
      securityContext: {{ toYaml .Values.podSecurityContext | nindent 8 }}
      {{- end }}
      volumes:
        - name: {{ .Chart.Name }}
          configMap:
            name: {{ .Chart.Name }}
        - name: {{ .Values.bpGrouping.configName }}
          configMap:
            name: {{ .Values.bpGrouping.configName }}
        - name: {{ .Chart.Name }}-redis-credentials
          secret:
            secretName: {{ .Values.redis.secretName }}
            items:
              - key: password
                path: redis.password

