apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-config
  namespace: default
data:
  init.sh: |
    #!/bin/bash
    echo ""
    echo "In init.sh"
    echo "=========="
    echo ""
    if [[ ${DOLLAR}{HOSTNAME} == 'redis-0' ]]; then
      echo "Host is redis-0"
      redis-server /redis-config/master.conf
    else
      echo "Host is ${DOLLAR}{HOSTNAME}"
      redis-server /redis-config/slave.conf
    fi
  master.conf: |
    bind 0.0.0.0
    port 6379

    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
    echo ""
    echo "In sentinel.sh"
    echo "=============="
    echo ""
    while ! ping -c 1 redis-0.redis; do
        echo 'Waiting for server'
        sleep 1
    done

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

    dir .

    slaveof redis-0.redis 6379
