apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-redis-ha-health-configmap
  namespace: "argocd"
  labels:
    heritage: Helm
    release: argocd
    chart: redis-ha-4.34.11
    app: argocd-redis-ha
data:
  redis_liveness.sh: |
    response=$(
      redis-cli \
        -h localhost \
        -p 6379 \
        ping
    )
    echo "response=$response"
    case $response in
      PONG|LOADING*) ;;
      *) exit 1 ;;
    esac
    exit 0
  redis_readiness.sh: |
    response=$(
      redis-cli \
        -h localhost \
        -p 6379 \
        ping
    )
    if [ "$response" != "PONG" ] ; then
      echo "ping=$response"
      exit 1
    fi

    response=$(
      redis-cli \
        -h localhost \
        -p 6379 \
        role
    )
    role=$( echo "$response" | sed "1!d" )
    if [ "$role" = "master" ]; then
      echo "role=$role"
      exit 0
    elif [ "$role" = "slave" ]; then
      repl=$( echo "$response" | sed "4!d" )
      echo "role=$role; repl=$repl"
      if [ "$repl" = "connected" ]; then
        exit 0
      else
        exit 1
      fi
    else
      echo "role=$role"
      exit 1
    fi
  sentinel_liveness.sh: |
    response=$(
      redis-cli \
        -h localhost \
        -p 26379 \
        ping
    )
    if [ "$response" != "PONG" ]; then
      echo "$response"
      exit 1
    fi
    echo "response=$response"
