apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.name }}-deployment
  labels:
    app: {{ .Values.name }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: {{ .Values.name }}
  strategy:
    type: RollingUpdate
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "true"
        traffic.sidecar.istio.io/excludeOutboundPorts: '6379'
      labels:
        app: {{ .Values.name }}
        collect.logs: "json"
    spec:
      serviceAccountName: {{ .Values.name }}
      securityContext: {}
      containers:
        - name: {{ .Values.name }}
          image: "{{ .Values.image.name }}:{{ .Values.image.version }}"
          imagePullPolicy: Always
          ports:
            - containerPort: {{ .Values.port }}
              protocol: TCP
          livenessProbe:
            httpGet:
              path: {{ .Values.probes.liveness.path }}
              port: {{ .Values.port }}
            failureThreshold: 1
            initialDelaySeconds: 180
            periodSeconds: 20
            successThreshold: 1
            timeoutSeconds: 5
          readinessProbe:
            httpGet:
              path: {{ .Values.probes.readiness.path }}
              port: {{ .Values.port }}
            failureThreshold: 5
            initialDelaySeconds: 60
            periodSeconds: 20
            successThreshold: 1
            timeoutSeconds: 5
          {{- if not .Values.global.disableRequestsLimits }}
          resources:
            limits:
              cpu: 500m
              memory: 800Mi
            requests:
              cpu: 500m
              memory: 800Mi
          {{- end }}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - name: {{ .Chart.Name }}
              mountPath: {{ .Values.appConfigMountPath }}
            - name: {{ .Chart.Name }}-redis-credentials
              mountPath: {{ .Values.redisSecretsMountPath }}
          env:
            - name: REDIS_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ .Values.redis.secretName }}
                  key: password
            - name: REDIS_NODE
              value: rfs-redis-sentinel.{{ .Release.Namespace }}.svc:26379
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      terminationGracePeriodSeconds: 30
      volumes:
        - name: {{ .Chart.Name }}
          configMap:
            name: {{ .Chart.Name }}
        - name: {{ .Chart.Name }}-redis-credentials
          secret:
            secretName: {{ .Values.redis.secretName }}
            items:
              - key: password
                path: redis.password