{{- if eq .Values.global.redisLocation "on-cluster" }}
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: drycc-redis
  labels:
    heritage: drycc
  annotations:
    component.drycc.cc/version: {{ .Values.imageTag }}
spec:
  serviceName: drycc-redis
  replicas: {{ .Values.replicas }}
  selector:
    matchLabels:
      app: drycc-redis
  template:
    metadata:
      labels:
        app: drycc-redis
    spec:
      affinity:
        podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAffinityPreset.type "key" .Values.podAffinityPreset.key "values" .Values.podAffinityPreset.values ) | nindent 10 }}
        podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAntiAffinityPreset.type "key" .Values.podAntiAffinityPreset.key "values" .Values.podAntiAffinityPreset.values ) | nindent 10 }}
        nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.nodeAffinityPreset.type "key" .Values.nodeAffinityPreset.key "values" .Values.nodeAffinityPreset.values ) | nindent 10 }}
      containers:
      - name: drycc-redis
        image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/redis:{{ .Values.imageTag }}
        imagePullPolicy: {{ .Values.imagePullPolicy }}
        {{- if or (.Values.limitsCpu) (.Values.limitsMemory)}}
        resources:
          limits:
            {{- if (.Values.limitsCpu) }}
            cpu: {{.Values.limitsCpu}}
            {{- end}}
            {{- if (.Values.limitsMemory) }}
            memory: {{.Values.limitsMemory}}
            {{- end}}
        {{- end}}
        args:
        - "/bin/boot"
        - "--port"
        - "6379"
        ports:
        - containerPort: 6379
        {{- if .Values.persistence.enabled }}
        env:
        - name: DRYCC_REDIS_PASSWORD
          valueFrom:
            secretKeyRef:
              name: redis-creds
              key: password
        volumeMounts:
        - name: redis-data
          mountPath: /data
        {{- end }}
      securityContext:
        fsGroup: 1001
        runAsGroup: 1001
        runAsUser: 1001
  {{- if .Values.persistence.enabled }}
  volumeClaimTemplates:
  - metadata:
      name: redis-data
    spec:
      accessModes: [ "ReadWriteOnce" ]
      {{- if .Values.persistence.storageClass }}
      {{- if (eq "-" .Values.persistence.storageClass) }}
      storageClassName: ""
      {{- else }}
      storageClassName: "{{ .Values.persistence.storageClass }}"
      {{- end }}
      {{- end }}
      resources:
        requests:
          storage: {{ .Values.persistence.size | quote }}
  {{- end }}
{{- end }}
