
---
# Source: redis/templates/redis-master-statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: redis-master
  namespace: infra
  labels:
    app: redis
    chart: redis-6.4.5
    release: "redis"
    heritage: "Tiller"
spec:
  selector:
    matchLabels:
      release: "redis"
      role: master
      app: redis
  serviceName: redis-master
  template:
    metadata:
      labels:
        release: "redis"
        chart: redis-6.4.5
        role: master
        app: redis
    spec:    
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: redis
                operator: In
                values:
                - "true"    
      securityContext:
        fsGroup: 1001
      serviceAccountName: "default"
      containers:
      - name: redis
        image: bitnami/redis:4.0.14
        imagePullPolicy: "IfNotPresent"
        securityContext:
          runAsUser: 1001
        command:
        - /bin/bash
        - -c
        - |
          if [[ -n $REDIS_PASSWORD_FILE ]]; then
            password_aux=`cat ${REDIS_PASSWORD_FILE}`
            export REDIS_PASSWORD=$password_aux
          fi
          ARGS=("--port" "${REDIS_PORT}")
          ARGS+=("--requirepass" "${REDIS_PASSWORD}")
          ARGS+=("--include" "/opt/bitnami/redis/etc/redis.conf")
          ARGS+=("--include" "/opt/bitnami/redis/etc/master.conf")
          /run.sh ${ARGS[@]}
        env:
        - name: REDIS_REPLICATION_MODE
          value: master
        - name: REDIS_PASSWORD
          value: admin
        - name: REDIS_PORT
          value: "6379"
        ports:
        - name: redis
          containerPort: 6379
        livenessProbe:
          initialDelaySeconds: 30
          periodSeconds: 10
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 5
          exec:
            command:
            - sh
            - -c
            - /health/ping_local.sh 5
        readinessProbe:
          initialDelaySeconds: 5
          periodSeconds: 10
          timeoutSeconds: 1
          successThreshold: 1
          failureThreshold: 5
          exec:
            command:
            - sh
            - -c
            - /health/ping_local.sh 5
        resources:
          limits:
            cpu: 10
            memory: 10Gi
          requests:
            cpu: 1
            memory: 1G
          
        volumeMounts:
        - name: health
          mountPath: /health
        - name: redis-data
          mountPath: /data   #/bitnami/redis/data
        - name: config
          mountPath: /opt/bitnami/redis/etc
      volumes:
      - name: health
        configMap:
          name: redis-health
          defaultMode: 0755
      - name: config
        configMap:
          name: redis
      - name: redis-data
        emptyDir: {}

  # volumeClaimTemplates:
  #   - metadata:
  #       name: redis-data
  #       labels:
  #         app: "redis"
  #         component: "master"
  #         release: "redis"
  #         heritage: "Tiller"
  #     spec:
  #       accessModes:
  #         - "ReadWriteOnce"
  #       selector:
  #         matchLabels:
  #           infra-pvname: infra-redis-master-pv
  #       resources:
  #         requests:
  #           storage: "1Gi"
  updateStrategy:
    type: RollingUpdate

