apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "common.names.fullname" . }}-scripts
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
data:
  ping_readiness_local.sh: |-
    {{- if .Values.usePasswordFile }}
    password_aux=`cat ${REDIS_PASSWORD_FILE}`
    export REDISCLI_AUTH=$password_aux
    {{- else }}
    export REDISCLI_AUTH=$REDIS_PASSWORD
    {{- end }}
    response=$(
      timeout -s 9 $1 \
      redis-cli \
        -h localhost \
{{- if .Values.tls.enabled }}
        -p $REDIS_TLS_PORT \
        --tls \
        --cert {{ template "redis-cluster.tlsCert" . }} \
        --key {{ template "redis-cluster.tlsCertKey" . }} \
        --cacert {{ template "redis-cluster.tlsCACert" . }} \
{{- else }}
        -p $REDIS_PORT \
{{- end }}
        ping
    )
    if [ "$response" != "PONG" ]; then
      echo "$response"
      exit 1
    fi
  ping_liveness_local.sh: |-
    {{- if .Values.usePasswordFile }}
    password_aux=`cat ${REDIS_PASSWORD_FILE}`
    export REDISCLI_AUTH=$password_aux
    {{- else }}
    export REDISCLI_AUTH=$REDIS_PASSWORD
    {{- end }}
    response=$(
      timeout -s 9 $1 \
      redis-cli \
        -h localhost \
{{- if .Values.tls.enabled }}
        -p $REDIS_TLS_PORT \
        --tls \
        --cert {{ template "redis-cluster.tlsCert" . }} \
        --key {{ template "redis-cluster.tlsCertKey" . }} \
        --cacert {{ template "redis-cluster.tlsCACert" . }} \
{{- else }}
        -p $REDIS_PORT \
{{- end }}
        ping
    )
    if [ "$response" != "PONG" ] && [ "$response" != "LOADING Redis is loading the dataset in memory" ]; then
      echo "$response"
      exit 1
    fi
