apiVersion: databases.spotahome.com/v1
kind: RedisFailover
metadata:
  name: {{ include "redis-sentinel.fullname" . }}
  labels:
    collect.logs: plain-text
spec:
  auth:
    secretPath: {{ .Values.redis.auth.secretName }}
  sentinel:
    {{- if or .Values.sentinel.podAnnotations .Values.global.registry.sentinel.istio.sidecar.enabled }}
    podAnnotations:
      {{- range $key, $value := .Values.sentinel.podAnnotations }}
      {{ $key }}: {{ $value | quote }}
      {{- end }}
      {{- if .Values.global.registry.sentinel.istio.sidecar.enabled }}
      sidecar.istio.io/inject: 'true'
      {{- include "sentinel.istioResources" . | nindent 6 }}
      {{- end }}
    {{- end }}
    serviceAccountName: {{ include "redis-sentinel.serviceAccountName" . }}
    image: "{{ .Values.dockerRegistry }}/{{ .Values.sentinel.image.repository }}:{{ .Values.sentinel.image.tag | default .Chart.AppVersion }}"
    replicas: {{ .Values.global.registry.sentinel.replicas }}
    {{- if .Values.sentinel.customConfig }}
    customConfig:
      {{- range .Values.sentinel.customConfig }}
      - "{{ . }}"
      {{- end }}
    {{- end }}
    {{- if or .Values.global.registry.sentinel.container.resources.requests .Values.global.registry.sentinel.container.resources.limits }}
    resources:
      {{- toYaml .Values.global.registry.sentinel.container.resources | nindent 6 }}
    {{- end }}
    {{- if .Values.sentinel.metrics.enabled }}
    exporter:
      enabled: true
      image: {{ .Values.dockerRegistry }}/leominov/redis_sentinel_exporter:1.3.0
    {{- end }}
  redis:
    {{- if or .Values.redis.podAnnotations .Values.global.registry.redis.istio.sidecar.enabled }}
    podAnnotations:
      {{- range $key, $value := .Values.redis.podAnnotations }}
      {{ $key }}: {{ $value | quote }}
      {{- end }}
      {{- if .Values.global.registry.redis.istio.sidecar.enabled }}
      sidecar.istio.io/inject: 'true'
      {{- include "redis.istioResources" . | nindent 6 }}
      {{- end }}
    {{- end }}
    serviceAccountName: {{ include "redis-sentinel.serviceAccountName" . }}
    image: "{{ .Values.dockerRegistry }}/{{ .Values.redis.image.repository }}:{{ .Values.redis.image.tag | default .Chart.AppVersion }}"
    replicas: {{ .Values.global.registry.redis.replicas }}
    {{- if .Values.global.registry.redis.container.customConfig }}
    customConfig:
      {{- range .Values.global.registry.redis.container.customConfig }}
      - "{{ . }}"
      {{- end }}
    {{- end }}
    {{- if or .Values.global.registry.redis.container.resources.requests .Values.global.registry.redis.container.resources.limits }}
    resources:
      {{- toYaml .Values.global.registry.redis.container.resources | nindent 6 }}
    {{- end }}
    {{- if .Values.redis.storage.create }}
    storage:
      #keepAfterDeletion is necessary because of its a workaround of https://github.com/spotahome/redis-operator/issues/397
      keepAfterDeletion: true
      persistentVolumeClaim:
        metadata:
          name: {{ include "redis-sentinel.fullname" . }}-data
        spec:
          accessModes:
            - ReadWriteOnce
          resources:
            requests:
              storage: {{ .Values.redis.storage.size }}
          storageClassName: {{ .Values.global.storageClass }}
    {{- end }}
    {{- if .Values.redis.metrics.enabled }}
    exporter:
      enabled: true
      image: {{ .Values.dockerRegistry }}/oliver006/redis_exporter:v1.3.5-alpine
      args:
        - --web.telemetry-path
        - /metrics
      env:
        - name: REDIS_EXPORTER_LOG_FORMAT
          value: txt
    {{- end }}

