health-configmap.yaml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: {{ printf "%s-health" (include "common.names.fullname" .) }}
  5. namespace: {{ .Release.Namespace | quote }}
  6. labels: {{- include "common.labels.standard" . | nindent 4 }}
  7. {{- if .Values.commonLabels }}
  8. {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
  9. {{- end }}
  10. {{- if .Values.commonAnnotations }}
  11. annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  12. {{- end }}
  13. data:
  14. ping_readiness_local.sh: |-
  15. #!/bin/bash
  16. [[ -f $REDIS_PASSWORD_FILE ]] && export REDIS_PASSWORD="$(< "${REDIS_PASSWORD_FILE}")"
  17. [[ -n "$REDIS_PASSWORD" ]] && export REDISCLI_AUTH="$REDIS_PASSWORD"
  18. response=$(
  19. timeout -s 15 $1 \
  20. redis-cli \
  21. -h localhost \
  22. {{- if .Values.tls.enabled }}
  23. -p $REDIS_TLS_PORT \
  24. --tls \
  25. --cacert {{ template "redis.tlsCACert" . }} \
  26. {{- if .Values.tls.authClients }}
  27. --cert {{ template "redis.tlsCert" . }} \
  28. --key {{ template "redis.tlsCertKey" . }} \
  29. {{- end }}
  30. {{- else }}
  31. -p $REDIS_PORT \
  32. {{- end }}
  33. ping
  34. )
  35. if [ "$?" -eq "124" ]; then
  36. echo "Timed out"
  37. exit 1
  38. fi
  39. if [ "$response" != "PONG" ]; then
  40. echo "$response"
  41. exit 1
  42. fi
  43. ping_liveness_local.sh: |-
  44. #!/bin/bash
  45. [[ -f $REDIS_PASSWORD_FILE ]] && export REDIS_PASSWORD="$(< "${REDIS_PASSWORD_FILE}")"
  46. [[ -n "$REDIS_PASSWORD" ]] && export REDISCLI_AUTH="$REDIS_PASSWORD"
  47. response=$(
  48. timeout -s 15 $1 \
  49. redis-cli \
  50. -h localhost \
  51. {{- if .Values.tls.enabled }}
  52. -p $REDIS_TLS_PORT \
  53. --tls \
  54. --cacert {{ template "redis.tlsCACert" . }} \
  55. {{- if .Values.tls.authClients }}
  56. --cert {{ template "redis.tlsCert" . }} \
  57. --key {{ template "redis.tlsCertKey" . }} \
  58. {{- end }}
  59. {{- else }}
  60. -p $REDIS_PORT \
  61. {{- end }}
  62. ping
  63. )
  64. if [ "$?" -eq "124" ]; then
  65. echo "Timed out"
  66. exit 1
  67. fi
  68. responseFirstWord=$(echo $response | head -n1 | awk '{print $1;}')
  69. if [ "$response" != "PONG" ] && [ "$responseFirstWord" != "LOADING" ] && [ "$responseFirstWord" != "MASTERDOWN" ]; then
  70. echo "$response"
  71. exit 1
  72. fi
  73. {{- if .Values.sentinel.enabled }}
  74. ping_sentinel.sh: |-
  75. #!/bin/bash
  76. {{- if .Values.auth.sentinel }}
  77. [[ -f $REDIS_PASSWORD_FILE ]] && export REDIS_PASSWORD="$(< "${REDIS_PASSWORD_FILE}")"
  78. [[ -n "$REDIS_PASSWORD" ]] && export REDISCLI_AUTH="$REDIS_PASSWORD"
  79. {{- end }}
  80. response=$(
  81. timeout -s 15 $1 \
  82. redis-cli \
  83. -h localhost \
  84. {{- if .Values.tls.enabled }}
  85. -p $REDIS_SENTINEL_TLS_PORT_NUMBER \
  86. --tls \
  87. --cacert "$REDIS_SENTINEL_TLS_CA_FILE" \
  88. {{- if .Values.tls.authClients }}
  89. --cert "$REDIS_SENTINEL_TLS_CERT_FILE" \
  90. --key "$REDIS_SENTINEL_TLS_KEY_FILE" \
  91. {{- end }}
  92. {{- else }}
  93. -p $REDIS_SENTINEL_PORT \
  94. {{- end }}
  95. ping
  96. )
  97. if [ "$?" -eq "124" ]; then
  98. echo "Timed out"
  99. exit 1
  100. fi
  101. if [ "$response" != "PONG" ]; then
  102. echo "$response"
  103. exit 1
  104. fi
  105. parse_sentinels.awk: |-
  106. /ip/ {FOUND_IP=1}
  107. /port/ {FOUND_PORT=1}
  108. /runid/ {FOUND_RUNID=1}
  109. !/ip|port|runid/ {
  110. if (FOUND_IP==1) {
  111. IP=$1; FOUND_IP=0;
  112. }
  113. else if (FOUND_PORT==1) {
  114. PORT=$1;
  115. FOUND_PORT=0;
  116. } else if (FOUND_RUNID==1) {
  117. printf "\nsentinel known-sentinel {{ .Values.sentinel.masterSet }} %s %s %s", IP, PORT, $0; FOUND_RUNID=0;
  118. }
  119. }
  120. {{- end }}
  121. ping_readiness_master.sh: |-
  122. #!/bin/bash
  123. [[ -f $REDIS_MASTER_PASSWORD_FILE ]] && export REDIS_MASTER_PASSWORD="$(< "${REDIS_MASTER_PASSWORD_FILE}")"
  124. [[ -n "$REDIS_MASTER_PASSWORD" ]] && export REDISCLI_AUTH="$REDIS_MASTER_PASSWORD"
  125. response=$(
  126. timeout -s 15 $1 \
  127. redis-cli \
  128. -h $REDIS_MASTER_HOST \
  129. -p $REDIS_MASTER_PORT_NUMBER \
  130. {{- if .Values.tls.enabled }}
  131. --tls \
  132. --cacert {{ template "redis.tlsCACert" . }} \
  133. {{- if .Values.tls.authClients }}
  134. --cert {{ template "redis.tlsCert" . }} \
  135. --key {{ template "redis.tlsCertKey" . }} \
  136. {{- end }}
  137. {{- end }}
  138. ping
  139. )
  140. if [ "$?" -eq "124" ]; then
  141. echo "Timed out"
  142. exit 1
  143. fi
  144. if [ "$response" != "PONG" ]; then
  145. echo "$response"
  146. exit 1
  147. fi
  148. ping_liveness_master.sh: |-
  149. #!/bin/bash
  150. [[ -f $REDIS_MASTER_PASSWORD_FILE ]] && export REDIS_MASTER_PASSWORD="$(< "${REDIS_MASTER_PASSWORD_FILE}")"
  151. [[ -n "$REDIS_MASTER_PASSWORD" ]] && export REDISCLI_AUTH="$REDIS_MASTER_PASSWORD"
  152. response=$(
  153. timeout -s 15 $1 \
  154. redis-cli \
  155. -h $REDIS_MASTER_HOST \
  156. -p $REDIS_MASTER_PORT_NUMBER \
  157. {{- if .Values.tls.enabled }}
  158. --tls \
  159. --cacert {{ template "redis.tlsCACert" . }} \
  160. {{- if .Values.tls.authClients }}
  161. --cert {{ template "redis.tlsCert" . }} \
  162. --key {{ template "redis.tlsCertKey" . }} \
  163. {{- end }}
  164. {{- end }}
  165. ping
  166. )
  167. if [ "$?" -eq "124" ]; then
  168. echo "Timed out"
  169. exit 1
  170. fi
  171. responseFirstWord=$(echo $response | head -n1 | awk '{print $1;}')
  172. if [ "$response" != "PONG" ] && [ "$responseFirstWord" != "LOADING" ]; then
  173. echo "$response"
  174. exit 1
  175. fi
  176. ping_readiness_local_and_master.sh: |-
  177. script_dir="$(dirname "$0")"
  178. exit_status=0
  179. "$script_dir/ping_readiness_local.sh" $1 || exit_status=$?
  180. "$script_dir/ping_readiness_master.sh" $1 || exit_status=$?
  181. exit $exit_status
  182. ping_liveness_local_and_master.sh: |-
  183. script_dir="$(dirname "$0")"
  184. exit_status=0
  185. "$script_dir/ping_liveness_local.sh" $1 || exit_status=$?
  186. "$script_dir/ping_liveness_master.sh" $1 || exit_status=$?
  187. exit $exit_status