{{- 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:
      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}}
        command: ["/bin/boot", "--port", "6379"]
        ports:
        - containerPort: 6379
        volumeMounts:
        - name: redis-creds
          mountPath: /var/run/secrets/drycc/redis/creds
        {{- if .Values.persistence.enabled }}
        - name: redis-data
          mountPath: /data
        {{- end }}
      volumes:
      - name: redis-creds
        secret:
          secretName: redis-creds
  {{- 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 }}
