apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Chart.Name }}
  labels:
    app: {{ .Chart.Name }}
spec:
  selector:
    matchLabels:
      app: {{ .Chart.Name }}
  replicas: {{ .Values.replicas }}
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "true"
        traffic.sidecar.istio.io/excludeOutboundPorts: '6379'
      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:
          tcpSocket:
            port: {{ .Values.port }}
          failureThreshold: 10
          initialDelaySeconds: 75
          periodSeconds: 20
          successThreshold: 1
          timeoutSeconds: 5
        readinessProbe:
          httpGet:
            path: {{ .Values.readinessPath }}
            port: {{ .Values.port }}
          failureThreshold: 1
          initialDelaySeconds: 75
          periodSeconds: 20
          successThreshold: 1
          timeoutSeconds: 5
        {{- if not .Values.global.disableRequestsLimits }}
        resources:
          limits:
            cpu: 500m
            memory: 768Mi
          requests:
            cpu: 500m
            memory: 768Mi
        {{- end }}
        env:
          - name: JAVA_OPTS
            value: {{ .Values.javaOpts }}
          - name: REDIS_PASSWORD
            valueFrom:
              secretKeyRef:
                name: {{ .Values.redis.secretName }}
                key: password
        volumeMounts:
          - name: {{ .Chart.Name }}
            mountPath: {{ .Values.appConfigMountPath }}
          - name: {{ .Chart.Name }}-trembita-business-processes
            mountPath: {{ .Values.trembitaBusinessProcessesConfigMountPath }}
          - name: {{ .Values.keycloak.trembitaInvokerClient.secretName }}
            mountPath: {{ .Values.trembitaInvokerKeycloakClientSecretsMountPath }}
          - name: {{ .Chart.Name }}-redis-credentials
            mountPath: {{ .Values.redisSecretsMountPath }}
      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: {{ .Chart.Name }}-trembita-business-processes
          configMap:
            name: {{ .Chart.Name }}-trembita-business-processes
        - name: {{ .Values.keycloak.trembitaInvokerClient.secretName }}
          secret:
            secretName: {{ .Values.keycloak.trembitaInvokerClient.secretName }}
            items:
            - key: clientSecret
              path: keycloak.client-secret
        - name: {{ .Chart.Name }}-redis-credentials
          secret:
            secretName: {{ .Values.redis.secretName }}
            items:
              - key: password
                path: redis.password
