apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "redis.fullname" . }}
  labels:
    {{- include "redis.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.master.replicas }}
  selector:
    matchLabels:
      {{- include "redis.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "redis.labels" . | nindent 8 }}
    spec:
      serviceAccountName: {{ include "redis.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: redis
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          command:
            - redis-server
            - --maxmemory
            - {{ .Values.redis.maxmemory }}mb
            - --maxmemory-policy
            - {{ .Values.redis.maxmemoryPolicy }}
            - --appendonly
            - {{ .Values.redis.appendonly | quote }}
          ports:
            - name: redis
              containerPort: 6379
              protocol: TCP
          {{- with .Values.livenessProbe }}
          livenessProbe:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          {{- with .Values.readinessProbe }}
          readinessProbe:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          {{- if .Values.persistence.enabled }}
          volumeMounts:
            - name: redis-data
              mountPath: /data
          {{- end }}
      {{- if .Values.persistence.enabled }}
      volumes:
        - name: redis-data
          persistentVolumeClaim:
            claimName: {{ include "redis.fullname" . }}
      {{- end }}
