Skip to content

Commit a97dc4b

Browse files
authored
feat(cardano-node): support custom mithril image overrides (#415)
Adds support for specifying a dedicated image, tag, and pullPolicy for the mithril-snapshot initContainer. Sets default pullPolicy to Always to ensure mutable tags (like latest-unstable) are always checked on restart. Note: The built-in mithril-client v0.13.9 in ghcr.io/blinklabs-io/cardano-node:11.0.1-1 has a closed-channel stream race condition bug on GCS (Download: could not write 0 bytes to stream). Suggest using ghcr.io/input-output-hk/mithril-client:latest-unstable (or v2617.0+). Signed-off-by: Ales Verbic <verbotenj@blinklabs.io>
1 parent 5b02f8f commit a97dc4b

3 files changed

Lines changed: 55 additions & 16 deletions

File tree

charts/cardano-node/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
apiVersion: v2
22
name: cardano-node
33
description: Creates a Cardano node deployment with SOCAT sidecar
4-
version: 0.8.5
5-
appVersion: 10.5.3
4+
version: 0.8.6
5+
appVersion: 11.0.1
66
maintainers:
77
- name: aurora
88
email: aurora@blinklabs.io

charts/cardano-node/templates/statefulset.yaml

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,29 @@ spec:
2727
{{ toYaml . | indent 8 }}
2828
{{- end }}
2929
spec:
30+
{{- if .Values.mithril.enabled }}
31+
securityContext:
32+
fsGroup: 1000
33+
{{- end }}
3034
{{- if .Values.affinity }}
3135
affinity: {{ .Values.affinity | toYaml | nindent 8 }}
3236
{{- end }}
3337
{{- if .Values.mithril.enabled }}
3438
initContainers:
3539
# Download Cardano snapshot using mithril-client
3640
- name: mithril-snapshot
37-
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
38-
imagePullPolicy: {{ .Values.image.pullPolicy }}
41+
securityContext:
42+
runAsNonRoot: true
43+
runAsUser: 1000
44+
runAsGroup: 1000
45+
image: {{ .Values.mithril.image.repository | default .Values.image.repository }}:{{ .Values.mithril.image.tag | default .Values.image.tag }}
46+
imagePullPolicy: {{ .Values.mithril.image.pullPolicy }}
3947
command: ["/bin/sh", "-c"]
4048
args:
4149
- |
4250
set -e
51+
set -o pipefail
52+
export PATH=/app/bin:$PATH
4353
NETWORK="{{ .Values.cardano_network }}"
4454
4555
if [ "$DEBUG_INIT" = "true" ]; then
@@ -50,10 +60,7 @@ spec:
5060
ls -la /data/db/ || true
5161
fi
5262
53-
if ! command -v jq >/dev/null 2>&1; then
54-
echo "ERROR: jq is required but not found in the image"
55-
exit 1
56-
fi
63+
5764
if ! command -v mithril-client >/dev/null 2>&1; then
5865
echo "ERROR: mithril-client is required but not found in the image"
5966
exit 1
@@ -88,15 +95,26 @@ spec:
8895
fi
8996
9097
# Read keys from image config files if they exist, otherwise use values from helm chart
98+
# Read keys from image config files if they exist, otherwise use values from helm chart or fall back to known defaults
9199
if [ -f "/opt/cardano/config/${NETWORK}/genesis.vkey" ] && [ -s "/opt/cardano/config/${NETWORK}/genesis.vkey" ]; then
92100
GENESIS_VERIFICATION_KEY=$(cat /opt/cardano/config/${NETWORK}/genesis.vkey)
93101
export GENESIS_VERIFICATION_KEY
94102
elif [ -n "{{ .Values.mithril.genesisVerificationKey }}" ]; then
95103
export GENESIS_VERIFICATION_KEY="{{ .Values.mithril.genesisVerificationKey }}"
96104
else
97-
echo "ERROR: Genesis verification key not found in image or values.yaml"
98-
echo "Please set mithril.genesisVerificationKey in values.yaml"
99-
exit 1
105+
echo "Resolving default genesis verification key automatically for ${NETWORK}..."
106+
case ${NETWORK} in
107+
mainnet)
108+
export GENESIS_VERIFICATION_KEY="5b3139312c36362c3134302c3138352c3133382c31312c3233372c3230372c3235302c3134342c32372c322c3138382c33302c31322c38312c3135352c3230342c31302c3137392c37352c32332c3133382c3139362c3231372c352c31342c32302c35372c37392c33392c3137365d"
109+
;;
110+
preview|preprod)
111+
export GENESIS_VERIFICATION_KEY="5b3132372c37332c3132342c3136312c362c3133372c3133312c3231332c3230372c3131372c3139382c38352c3137362c3139392c3136322c3234312c36382c3132332c3131392c3134352c31332c3233322c3234332c34392c3232392c322c3234392c3230352c3230352c33392c3233352c34345d"
112+
;;
113+
*)
114+
echo "ERROR: Genesis verification key not found and no default for ${NETWORK}"
115+
exit 1
116+
;;
117+
esac
100118
fi
101119
102120
if [ -f "/opt/cardano/config/${NETWORK}/ancillary.vkey" ] && [ -s "/opt/cardano/config/${NETWORK}/ancillary.vkey" ]; then
@@ -105,7 +123,18 @@ spec:
105123
elif [ -n "{{ .Values.mithril.ancillaryVerificationKey }}" ]; then
106124
export ANCILLARY_VERIFICATION_KEY="{{ .Values.mithril.ancillaryVerificationKey }}"
107125
else
108-
echo "No ancillary verification key found (optional - skipping fast bootstrap)"
126+
echo "Resolving default ancillary verification key automatically for ${NETWORK}..."
127+
case ${NETWORK} in
128+
mainnet)
129+
export ANCILLARY_VERIFICATION_KEY="5b32332c37312c39362c3133332c34372c3235332c3232362c3133362c3233352c35372c3136342c3130362c3138362c322c32312c32392c3132302c3136332c38392c3132312c3137372c3133382c3230382c3133382c3231342c39392c35382c32322c302c35382c332c36395d"
130+
;;
131+
preview|preprod)
132+
export ANCILLARY_VERIFICATION_KEY="5b3138392c3139322c3231362c3135302c3131342c3231362c3233372c3231302c34352c31382c32312c3139362c3230382c3234362c3134362c322c3235322c3234332c3235312c3139372c32382c3135372c3230342c3134352c33302c31342c3232382c3136382c3132392c38332c3133362c33365d"
133+
;;
134+
*)
135+
echo "No ancillary verification key default found for ${NETWORK} (optional)"
136+
;;
137+
esac
109138
fi
110139
111140
export AGGREGATOR_ENDPOINT=https://aggregator.${__path}.api.mithril.network/aggregator
@@ -122,10 +151,18 @@ spec:
122151
echo "Using configured snapshot digest: ${SNAPSHOT_DIGEST}"
123152
else
124153
echo "Fetching latest snapshot digest from ${AGGREGATOR_ENDPOINT}..."
125-
SNAPSHOT_DIGEST=$(mithril-client cardano-db snapshot list --json | jq -r '.[0].hash')
154+
if ! SNAPSHOT_DIGEST=$(mithril-client cardano-db snapshot list --json | grep -o '"hash":"[^"]*' | head -n 1 | cut -d'"' -f4); then
155+
echo "ERROR: Failed to fetch snapshot list from aggregator!"
156+
exit 1
157+
fi
126158
echo "Latest snapshot digest: ${SNAPSHOT_DIGEST}"
127159
fi
128160
161+
if [ -z "${SNAPSHOT_DIGEST}" ]; then
162+
echo "ERROR: Failed to obtain a valid snapshot digest from aggregator!"
163+
exit 1
164+
fi
165+
129166
mkdir -p /data
130167
cd /data
131168
echo "Starting mithril snapshot download..."

charts/cardano-node/values.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cardano_network: preview
55
# extraPodLabels: {}
66
image:
77
repository: ghcr.io/blinklabs-io/cardano-node
8-
tag: 10.5.3
8+
tag: 11.0.1-1
99
pullPolicy: IfNotPresent
1010
replicaCount: 1
1111
resources: {}
@@ -27,9 +27,11 @@ service:
2727

2828
# Mithril snapshot restoration via initContainer
2929
mithril:
30-
# Enable Mithril snapshot download via initContainer (recommended)
31-
# Runs mithril-client in initContainer before the main cardano-node container starts
3230
enabled: true
31+
image:
32+
repository: "ghcr.io/input-output-hk/mithril-client"
33+
tag: "unstable"
34+
pullPolicy: "Always"
3335
# Genesis and ancillary keys - read from image config files by default
3436
# These are fallbacks if /opt/cardano/config/{network}/*.vkey files don't exist
3537
genesisVerificationKey: "" # Optional: fallback if image doesn't have genesis.vkey

0 commit comments

Comments
 (0)