Skip to content

Commit

Permalink
[geth] add startupProbe (#315)
Browse files Browse the repository at this point in the history
* [geth] port startupProbe from op-geth chart
  • Loading branch information
VladStarr authored Aug 22, 2024
1 parent 430b3f0 commit 9792619
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 18 deletions.
4 changes: 2 additions & 2 deletions dysnix/geth/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: geth
description: Go-ethereum blockchain node Helm Chart

version: 1.0.17
appVersion: v1.14.5
version: 1.0.18
appVersion: v1.14.8

keywords:
- geth
Expand Down
13 changes: 13 additions & 0 deletions dysnix/geth/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,17 @@ Convert Golang slice to Toml array
{{- $element | quote }}
{{- end -}}
{{ print "]" -}}
{{- end }}

{{- define "geth.healthcheck" -}}
{{- $context := index . 0 }}
{{- $root := index . 1 }}
{{- if and $root.exec (kindIs "string" $root.exec.command) }}
{{- omit $root "enabled" "exec" | toYaml }}
exec:
command:
{{- tpl $root.exec.command $context | nindent 4 }}
{{- else }}
{{- omit $root "enabled" | toYaml }}
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions dysnix/geth/templates/configmap-scripts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ data:
{{- include (print $.Template.BasePath "/scripts/_readiness.tpl") . | nindent 4 }}
liveness.sh: |-
{{- include (print $.Template.BasePath "/scripts/_liveness.tpl") . | nindent 4 }}
wait-for-sync.sh: |-
{{- include (print $.Template.BasePath "/scripts/_wait-for-sync.tpl") . | nindent 4 }}
{{- if or .Values.syncToS3.enabled .Values.initFromS3.enabled }}
init-from-s3.sh: |-
{{- include (print $.Template.BasePath "/scripts/_init-from-s3.tpl") . | nindent 4 }}
Expand Down
36 changes: 36 additions & 0 deletions dysnix/geth/templates/scripts/_wait-for-sync.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env sh
# shellcheck disable=SC3040

# We assume that node is syncing from initial snapshot when:
# (get_block_number == 0x0) OR (is_syncing == true)

set -e

HTTP_PORT="{{ .Values.config.node.http.port }}"

# expected output format: 0x50938d
get_block_number() {
wget "http://localhost:$HTTP_PORT" -qO- \
--header 'Content-Type: application/json' \
--post-data '{"jsonrpc":"2.0","method":"eth_blockNumber","id":1}' \
| sed -r 's/.*"result":"([^"]+)".*/\1/g'
}

# exit codes: 1 = sync completed, 0 = sync in progress
is_syncing() {
wget "http://localhost:$HTTP_PORT" -qO- \
--header 'Content-Type: application/json' \
--post-data '{"jsonrpc":"2.0","method":"eth_syncing","id":1}' \
| grep -qv "false"
}

if ! get_block_number | grep -qE '^0x[a-z0-9]+'; then
echo "Error reading block number"; exit 1
fi

if is_syncing || [ "$(get_block_number)" = "0x0" ]; then
echo "Initial sync is in progress"
exit 1
else
exit 0
fi
22 changes: 6 additions & 16 deletions dysnix/geth/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,25 +193,15 @@ spec:
mountPath: /scripts
{{- if .Values.livenessProbe.enabled }}
livenessProbe:
{{- if and .Values.livenessProbe.exec (kindIs "string" .Values.livenessProbe.exec.command) }}
{{- omit .Values.livenessProbe "enabled" "exec" | toYaml | nindent 10 }}
exec:
command:
{{- tpl .Values.livenessProbe.exec.command . | nindent 14 }}
{{- else }}
{{- omit .Values.livenessProbe "enabled" | toYaml | nindent 10 }}
{{- end }}
{{- include "geth.healthcheck" (list $ .Values.livenessProbe) | nindent 10 }}
{{- end }}
{{- if .Values.readinessProbe.enabled }}
readinessProbe:
{{- if and .Values.readinessProbe.exec (kindIs "string" .Values.readinessProbe.exec.command) }}
{{- omit .Values.readinessProbe "enabled" "exec" | toYaml | nindent 10 }}
exec:
command:
{{- tpl .Values.readinessProbe.exec.command . | nindent 14 }}
{{- else }}
{{- omit .Values.readinessProbe "enabled" | toYaml | nindent 10 }}
{{- end }}
{{- include "geth.healthcheck" (list $ .Values.readinessProbe) | nindent 10 }}
{{- end }}
{{- if .Values.startupProbe.enabled }}
startupProbe:
{{- include "geth.healthcheck" (list $ .Values.startupProbe) | nindent 10 }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 10 }}
Expand Down
12 changes: 12 additions & 0 deletions dysnix/geth/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,18 @@ readinessProbe:
- /scripts/readiness.sh
- "60"

# .startupProbe.exec.command can also be in a templated string format
startupProbe:
enabled: false
initialDelaySeconds: 10
periodSeconds: 5
failureThreshold: 120960 # periodSeconds * failureThreshold = 7 days
timeoutSeconds: 10
exec:
command:
- sh
- /scripts/wait-for-sync.sh

## Main Geth config
config:
## Use a utility like OpenSSL to create JWT via command: openssl rand -hex 32
Expand Down

0 comments on commit 9792619

Please sign in to comment.