---
apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-config
  namespace: cache
  labels:
    app: cube
    component: redis
data:
  init.sh: |
    #!/bin/bash
    if [[ ${HOSTNAME} == 'redis-0' ]]; then
      redis-server /redis-config/master.conf
    else
      redis-server /redis-config/slave.conf
    fi
  master.conf: |
    bind 0.0.0.0
    port 6379

    maxmemory 16777216
    dir /redis-data
  sentinel.conf: |
    bind 0.0.0.0
    port 26379

    sentinel monitor redis redis-0.redis 6379 2
    sentinel parallel-syncs redis 1
    sentinel down-after-milliseconds redis 10000
    sentinel failover-timeout redis 20000
  sentinel.sh: |
    #!/bin/bash
    while ! ping -c 1 redis-0.redis; do
        echo 'Waiting for server'
        sleep 1
    done

    redis-sentinel /redis-sentinel-conf/sentinel.conf
  slave.conf: |
    bind 0.0.0.0
    port 6379

    dir .

    slaveof redis-0.redis 6379