Skip to content

Commit ad089d0

Browse files
committed
feat(charts): add tcp-check init container configuration
- Introduced a new init container configuration for TCP dependency checks in the network charts. - Updated README and values.yaml to document the new initContainer.tcpCheck fields, including image repository, tag, pull policy, timeout, and resource limits. - Ensured compatibility with helm-docs format for autogenerated documentation.
1 parent 1c8ec51 commit ad089d0

11 files changed

Lines changed: 297 additions & 132 deletions

File tree

charts/network/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ A Helm chart for a blockchain network on Kubernetes
2121

2222
| Key | Type | Default | Description |
2323
|-----|------|---------|-------------|
24+
| extraInitContainers | list | `[]` | Additional init containers appended verbatim to each workload. |
2425
| global | object | `{"chainId":null,"networkNodes":{"faucetArtifactPrefix":"besu-faucet","genesisConfigMapName":"besu-genesis","podPrefix":"","serviceName":"","staticNodesConfigMapName":"besu-static-nodes"},"securityContexts":{"container":{},"pod":{}}}` | Global configuration shared across subcharts. |
2526
| global.chainId | int | `nil` | Chain ID applied when charts omit explicit overrides. |
2627
| global.networkNodes | object | `{"faucetArtifactPrefix":"besu-faucet","genesisConfigMapName":"besu-genesis","podPrefix":"","serviceName":"","staticNodesConfigMapName":"besu-static-nodes"}` | Defaults consumed by Besu network node workloads. |
@@ -32,3 +33,10 @@ A Helm chart for a blockchain network on Kubernetes
3233
| global.securityContexts | object | `{"container":{},"pod":{}}` | Shared pod- and container-level security contexts applied when subcharts omit explicit overrides. |
3334
| global.securityContexts.container | object | `{}` | Container security context inherited by subcharts when set. |
3435
| global.securityContexts.pod | object | `{}` | Pod security context inherited by subcharts when set. |
36+
| initContainer | object | `{"tcpCheck":{"dependencies":[],"enabled":false,"image":{"pullPolicy":"IfNotPresent","repository":"ghcr.io/settlemint/btp-waitforit","tag":"v7.7.10"},"resources":{"limits":{"cpu":"100m","memory":"64Mi"},"requests":{"cpu":"10m","memory":"32Mi"}},"timeout":120}}` | Init container configuration shared by subcharts. |
37+
| initContainer.tcpCheck.dependencies | list | `[]` | TCP dependencies expressed as name/endpoint pairs (host:port). |
38+
| initContainer.tcpCheck.enabled | bool | `false` | Enable the TCP dependency check init container by default. |
39+
| initContainer.tcpCheck.image.pullPolicy | string | `"IfNotPresent"` | Image pull policy for the tcp-check init container. |
40+
| initContainer.tcpCheck.image.repository | string | `"ghcr.io/settlemint/btp-waitforit"` | OCI image hosting the tcp-check utility. |
41+
| initContainer.tcpCheck.image.tag | string | `"v7.7.10"` | Image tag for the tcp-check utility. |
42+
| initContainer.tcpCheck.timeout | int | `120` | Timeout in seconds applied to each dependency probe. |

charts/network/charts/network-bootstrapper/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,23 @@ A Helm chart for Kubernetes
2222
| artifacts.external.staticNodes | list | `[]` | Collection of enode URIs persisted to the `besu-static-nodes` ConfigMap when `source` equals `external`. |
2323
| artifacts.external.validators | list | `[]` | Validator node definitions providing the data expected by the nodes chart. Each entry must include `address`, `publicKey`, `privateKey`, and `enode`. |
2424
| artifacts.source | string | `"generated"` | Determines how Besu network artifacts are populated. Use `generated` to run the job or `external` to supply values manually. |
25+
| extraInitContainers | list | `[]` | Additional init containers appended verbatim to the job pod spec. |
2526
| fullnameOverride | string | `"bootstrapper"` | Override for the fully qualified resource name generated by helpers. |
2627
| global.chainId | int | `nil` | Chain ID applied when `settings.chainId` is unset. |
2728
| image.pullPolicy | string | `"IfNotPresent"` | Image pull policy controlling when Kubernetes fetches updated image layers. |
2829
| image.repository | string | `"ghcr.io/settlemint/network-bootstrapper"` | OCI registry path hosting the network bootstrapper image. |
2930
| image.tag | string | `""` | Image tag override; leave empty to inherit the chart appVersion. |
3031
| imagePullSecrets | list | `[]` | Image pull secrets enabling access to private registries. |
31-
| initContainers | list|string | `[]` | Init containers executed before the bootstrapper container starts. |
32+
| initContainer.tcpCheck.dependencies | list | `[]` | TCP dependencies expressed as name/endpoint pairs (host:port strings). |
33+
| initContainer.tcpCheck.enabled | bool | `false` | Enable a tcp-check init container before the bootstrapper job starts. |
34+
| initContainer.tcpCheck.image.pullPolicy | string | `"IfNotPresent"` | Image pull policy for the tcp-check init container. |
35+
| initContainer.tcpCheck.image.repository | string | `"ghcr.io/settlemint/btp-waitforit"` | OCI image hosting the tcp-check utility. |
36+
| initContainer.tcpCheck.image.tag | string | `"v7.7.10"` | Image tag for the tcp-check utility. |
37+
| initContainer.tcpCheck.resources.limits.cpu | string | `"100m"` | |
38+
| initContainer.tcpCheck.resources.limits.memory | string | `"64Mi"` | |
39+
| initContainer.tcpCheck.resources.requests.cpu | string | `"10m"` | |
40+
| initContainer.tcpCheck.resources.requests.memory | string | `"32Mi"` | |
41+
| initContainer.tcpCheck.timeout | int | `120` | Timeout in seconds applied to each dependency probe. |
3242
| nameOverride | string | `""` | Override for the short release name used by name templates. |
3343
| nodeSelector | object | `{}` | |
3444
| podAnnotations | object | `{}` | |

charts/network/charts/network-bootstrapper/templates/_helpers.tpl

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,81 @@ Create the name of the service account to use
6262
{{- end }}
6363

6464
{{/*
65-
Render init container specifications provided via values.
66-
Accepts either a YAML string or a list of init container maps and indents output appropriately.
65+
Render a tcp-check init container when enabled.
6766
*/}}
68-
{{- define "network-bootstrapper.renderInitContainers" -}}
69-
{{- $ctx := .context -}}
70-
{{- $containers := .containers -}}
71-
{{- $indent := .indent | default 2 -}}
72-
{{- if $containers -}}
73-
{{- if kindIs "string" $containers -}}
74-
{{ tpl $containers $ctx | nindent $indent }}
75-
{{- else -}}
76-
{{ tpl (toYaml $containers) $ctx | nindent $indent }}
77-
{{- end -}}
67+
{{- define "network-bootstrapper.tcpCheckInitContainer" -}}
68+
{{- $ctx := index . "context" -}}
69+
{{- $cfg := default (dict) (index . "config") -}}
70+
{{- $indent := index . "indent" | default 2 -}}
71+
{{- $enabled := default false (get $cfg "enabled") -}}
72+
{{- if $enabled -}}
73+
{{- $image := default (dict) (get $cfg "image") -}}
74+
{{- $repository := default "ghcr.io/settlemint/btp-waitforit" (get $image "repository") -}}
75+
{{- $tag := default "v7.7.10" (get $image "tag") -}}
76+
{{- $pullPolicy := default "IfNotPresent" (get $image "pullPolicy") -}}
77+
{{- $timeout := default 120 (get $cfg "timeout") -}}
78+
{{- $resources := get $cfg "resources" -}}
79+
{{- $dependencies := default (list) (get $cfg "dependencies") -}}
80+
{{- $count := len $dependencies -}}
81+
{{- $script := include "network-bootstrapper.tcpCheckScript" (dict "ctx" $ctx "timeout" $timeout "dependencies" $dependencies "count" $count) -}}
82+
{{- $container := dict "name" "tcp-check" "image" (printf "%s:%s" $repository $tag) "imagePullPolicy" $pullPolicy "command" (list "/bin/sh" "-ec") "args" (list $script) -}}
83+
{{- if $resources }}{{- $_ := set $container "resources" $resources }}{{- end -}}
84+
{{ toYaml (list $container) | nindent $indent }}
7885
{{- end -}}
86+
{{- end }}
87+
88+
{{/*
89+
Produce the shell script executed by the tcp-check init container.
90+
*/}}
91+
{{- define "network-bootstrapper.tcpCheckScript" -}}
92+
set -euo pipefail
93+
INTERVAL=2
94+
TIMEOUT={{ index . "timeout" }}
95+
if [ {{ index . "count" }} -eq 0 ]; then
96+
echo "No dependencies configured; skipping checks."
97+
exit 0
98+
fi
99+
100+
check() {
101+
name="$1"
102+
endpoint="$2"
103+
host="${endpoint%:*}"
104+
port="${endpoint##*:}"
105+
echo "Waiting for ${name} (${endpoint})..."
106+
elapsed=0
107+
while true; do
108+
if nc -z "$host" "$port" >/dev/null 2>&1; then
109+
echo "${name} ready."
110+
break
111+
fi
112+
sleep "${INTERVAL}"
113+
elapsed=$((elapsed+INTERVAL))
114+
if [ "$elapsed" -ge "$TIMEOUT" ]; then
115+
echo "Timeout waiting for ${name} (${endpoint})."
116+
exit 1
117+
fi
118+
done
119+
}
120+
121+
{{- range $dependency := index . "dependencies" }}
122+
{{- $name := default "dependency" (get $dependency "name") }}
123+
{{- $endpointTemplate := default "" (get $dependency "endpoint") }}
124+
{{- $endpoint := tpl $endpointTemplate (index . "ctx") }}
125+
check {{ printf "%q" $name }} {{ printf "%q" $endpoint }}
126+
{{- end }}
127+
{{- end }}
128+
129+
{{/*
130+
Render arbitrarily defined init containers without modification.
131+
*/}}
132+
{{- define "network-bootstrapper.extraInitContainers" -}}
133+
{{- $ctx := index . "context" -}}
134+
{{- $containers := default (list) (index . "containers") -}}
135+
{{- $indent := index . "indent" | default 2 -}}
136+
{{- if gt (len $containers) 0 -}}
137+
{{ tpl (toYaml $containers) $ctx | nindent $indent }}
79138
{{- end -}}
139+
{{- end }}
80140

81141
{{/*
82142
Resolve pod and container security contexts by layering chart values over global defaults.

charts/network/charts/network-bootstrapper/templates/job.yaml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,21 @@ spec:
3535
securityContext:
3636
{{- toYaml $podSecurityContext | nindent 8 }}
3737
{{- end }}
38-
{{- with .Values.initContainers }}
38+
{{- $globalValues := default (dict) .Values.global }}
39+
{{- $initConfig := default (dict) .Values.initContainer }}
40+
{{- $globalInitConfig := default (dict) (get $globalValues "initContainer") }}
41+
{{- $globalTcpDefaults := default (dict) (get $globalInitConfig "tcpCheck") }}
42+
{{- $chartTcpOverrides := default (dict) (get $initConfig "tcpCheck") }}
43+
{{- $tcpCheckConfig := mergeOverwrite (deepCopy $globalTcpDefaults) $chartTcpOverrides }}
44+
{{- $globalExtraInit := default (list) (get $globalValues "extraInitContainers") }}
45+
{{- $chartExtraInit := default (list) .Values.extraInitContainers }}
46+
{{- $extraInitContainers := concat $globalExtraInit $chartExtraInit }}
47+
{{- $tcpEnabled := default false (get $tcpCheckConfig "enabled") }}
48+
{{- $hasExtraInit := gt (len $extraInitContainers) 0 }}
49+
{{- if or $tcpEnabled $hasExtraInit }}
3950
initContainers:
40-
{{- include "network-bootstrapper.renderInitContainers" (dict "context" $ "containers" . "indent" 8) }}
51+
{{- include "network-bootstrapper.tcpCheckInitContainer" (dict "context" . "config" $tcpCheckConfig "indent" 8) }}
52+
{{- include "network-bootstrapper.extraInitContainers" (dict "context" . "containers" $extraInitContainers "indent" 8) }}
4153
{{- end }}
4254
containers:
4355
- name: {{ .Chart.Name }}
@@ -55,7 +67,6 @@ spec:
5567
{{- $resolvedStaticDomain := default $clusterDomain .Values.settings.staticNodeDomain }}
5668
{{- $resolvedStaticPort := default $defaultStaticPort .Values.settings.staticNodePort }}
5769
{{- $resolvedStaticDiscovery := default $defaultStaticDiscovery .Values.settings.staticNodeDiscoveryPort }}
58-
{{- $globalValues := default (dict) .Values.global }}
5970
{{- $settingsValues := default (dict) .Values.settings }}
6071
{{- $globalNodes := default (dict) (get $globalValues "networkNodes") }}
6172
{{- $localChainId := get $settingsValues "chainId" }}

charts/network/charts/network-bootstrapper/values.yaml

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,36 +60,32 @@ securityContext:
6060
# runAsNonRoot: true
6161
# runAsUser: 1000
6262

63-
# -- (list|string) Init containers executed before the bootstrapper container starts.
64-
initContainers: []
65-
# - name: wait-for-genesis
66-
# image: busybox:1.36
67-
# imagePullPolicy: IfNotPresent
68-
# command:
69-
# - sh
70-
# - -c
71-
# args:
72-
# - >-
73-
# until nc -z ${STATIC_NODE_HOST:?} ${STATIC_NODE_PORT:?}; do echo "waiting for nodes"; sleep 2; done
74-
# env:
75-
# - name: STATIC_NODE_HOST
76-
# value: besu-node-validator-0.besu-node-validator
77-
# - name: STATIC_NODE_PORT
78-
# value: "30303"
79-
# envFrom:
80-
# - secretRef:
81-
# name: bootstrapper-env
82-
# volumeMounts:
83-
# - name: config
84-
# mountPath: /config
85-
# resources:
86-
# requests:
87-
# cpu: 50m
88-
# memory: 64Mi
89-
# securityContext: {}
90-
# workingDir: /config
91-
# stdin: false
92-
# tty: false
63+
# Init container configuration shared across the bootstrapper job.
64+
initContainer:
65+
tcpCheck:
66+
# -- (bool) Enable a tcp-check init container before the bootstrapper job starts.
67+
enabled: false
68+
image:
69+
# -- (string) OCI image hosting the tcp-check utility.
70+
repository: ghcr.io/settlemint/btp-waitforit
71+
# -- (string) Image tag for the tcp-check utility.
72+
tag: v7.7.10
73+
# -- (string) Image pull policy for the tcp-check init container.
74+
pullPolicy: IfNotPresent
75+
# -- (int) Timeout in seconds applied to each dependency probe.
76+
timeout: 120
77+
resources:
78+
limits:
79+
cpu: 100m
80+
memory: 64Mi
81+
requests:
82+
cpu: 10m
83+
memory: 32Mi
84+
# -- (list) TCP dependencies expressed as name/endpoint pairs (host:port strings).
85+
dependencies: []
86+
87+
# -- (list) Additional init containers appended verbatim to the job pod spec.
88+
extraInitContainers: []
9389

9490
# CPU and memory requests or limits for the bootstrapper container.
9591
resources:

charts/network/charts/network-nodes/README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ A Helm chart for Kubernetes
6060
| config.ws.host | string | `"0.0.0.0"` | Network interface for the WebSocket listener. |
6161
| config.ws.maxActiveConnections | int | `2000` | Maximum concurrent WebSocket connections. |
6262
| config.ws.maxFrameSize | int | `2097152` | Maximum WebSocket frame size in bytes. |
63+
| extraInitContainers | list | `[]` | Additional init containers appended verbatim to both StatefulSets. |
6364
| fullnameOverride | string | `"besu-node"` | Override for the fully qualified release name used in resource naming. |
6465
| httpRoute.annotations | object | `{}` | |
6566
| httpRoute.enabled | bool | `false` | Enable rendering of an HTTPRoute resource. |
@@ -78,9 +79,16 @@ A Helm chart for Kubernetes
7879
| ingress.enabled | bool | `false` | Enable creation of an Ingress resource. |
7980
| ingress.hosts | list | `[{"host":"chart-example.local","paths":[{"path":"/","pathType":"ImplementationSpecific"}]}]` | Hostname and path routing rules for the Ingress. |
8081
| ingress.tls | list | `[]` | TLS configuration for Ingress hosts. |
81-
| initContainers.rpc | list|string | `[]` | Additional init containers exclusively for RPC pods. |
82-
| initContainers.shared | list|string | `[]` | Init containers applied to both validator and RPC pods. |
83-
| initContainers.validator | list|string | `[]` | Additional init containers exclusively for validator pods. |
82+
| initContainer.tcpCheck.dependencies | list | `[]` | TCP dependencies expressed as name/endpoint pairs (host:port strings). |
83+
| initContainer.tcpCheck.enabled | bool | `false` | Enable a tcp-check init container before Besu pods start. |
84+
| initContainer.tcpCheck.image.pullPolicy | string | `"IfNotPresent"` | Image pull policy for the tcp-check init container. |
85+
| initContainer.tcpCheck.image.repository | string | `"ghcr.io/settlemint/btp-waitforit"` | OCI image hosting the tcp-check utility. |
86+
| initContainer.tcpCheck.image.tag | string | `"v7.7.10"` | Image tag for the tcp-check utility. |
87+
| initContainer.tcpCheck.resources.limits.cpu | string | `"100m"` | |
88+
| initContainer.tcpCheck.resources.limits.memory | string | `"64Mi"` | |
89+
| initContainer.tcpCheck.resources.requests.cpu | string | `"10m"` | |
90+
| initContainer.tcpCheck.resources.requests.memory | string | `"32Mi"` | |
91+
| initContainer.tcpCheck.timeout | int | `120` | Timeout in seconds applied to each dependency probe. |
8492
| livenessProbe.failureThreshold | int | `3` | Consecutive failures required before the container is restarted. |
8593
| livenessProbe.httpGet.path | string | `"/readiness?minPeers=1&maxBlocksBehind=10000"` | HTTP path used for liveness probing. |
8694
| livenessProbe.httpGet.port | string|int | `"json-rpc"` | Target container port serving the liveness endpoint. |

charts/network/charts/network-nodes/templates/_helpers.tpl

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,81 @@ Resolve the number of validator replicas, falling back to global overrides when
111111
{{- end }}
112112

113113
{{/*
114-
Render init container specifications provided via values.
115-
Accepts either a YAML string or a list of init container maps and indents output appropriately.
114+
Render a tcp-check init container when enabled.
116115
*/}}
117-
{{- define "nodes.renderInitContainers" -}}
118-
{{- $ctx := .context -}}
119-
{{- $containers := .containers -}}
120-
{{- $indent := .indent | default 2 -}}
121-
{{- if $containers -}}
122-
{{- if kindIs "string" $containers -}}
123-
{{ tpl $containers $ctx | nindent $indent }}
124-
{{- else -}}
125-
{{ tpl (toYaml $containers) $ctx | nindent $indent }}
126-
{{- end -}}
116+
{{- define "nodes.tcpCheckInitContainer" -}}
117+
{{- $ctx := index . "context" -}}
118+
{{- $cfg := default (dict) (index . "config") -}}
119+
{{- $indent := index . "indent" | default 2 -}}
120+
{{- $enabled := default false (get $cfg "enabled") -}}
121+
{{- if $enabled -}}
122+
{{- $image := default (dict) (get $cfg "image") -}}
123+
{{- $repository := default "ghcr.io/settlemint/btp-waitforit" (get $image "repository") -}}
124+
{{- $tag := default "v7.7.10" (get $image "tag") -}}
125+
{{- $pullPolicy := default "IfNotPresent" (get $image "pullPolicy") -}}
126+
{{- $timeout := default 120 (get $cfg "timeout") -}}
127+
{{- $resources := get $cfg "resources" -}}
128+
{{- $dependencies := default (list) (get $cfg "dependencies") -}}
129+
{{- $count := len $dependencies -}}
130+
{{- $script := include "nodes.tcpCheckScript" (dict "ctx" $ctx "timeout" $timeout "dependencies" $dependencies "count" $count) -}}
131+
{{- $container := dict "name" "tcp-check" "image" (printf "%s:%s" $repository $tag) "imagePullPolicy" $pullPolicy "command" (list "/bin/sh" "-ec") "args" (list $script) -}}
132+
{{- if $resources }}{{- $_ := set $container "resources" $resources }}{{- end -}}
133+
{{ toYaml (list $container) | nindent $indent }}
127134
{{- end -}}
135+
{{- end }}
136+
137+
{{/*
138+
Produce the shell script executed by the tcp-check init container.
139+
*/}}
140+
{{- define "nodes.tcpCheckScript" -}}
141+
set -euo pipefail
142+
INTERVAL=2
143+
TIMEOUT={{ index . "timeout" }}
144+
if [ {{ index . "count" }} -eq 0 ]; then
145+
echo "No dependencies configured; skipping checks."
146+
exit 0
147+
fi
148+
149+
check() {
150+
name="$1"
151+
endpoint="$2"
152+
host="${endpoint%:*}"
153+
port="${endpoint##*:}"
154+
echo "Waiting for ${name} (${endpoint})..."
155+
elapsed=0
156+
while true; do
157+
if nc -z "$host" "$port" >/dev/null 2>&1; then
158+
echo "${name} ready."
159+
break
160+
fi
161+
sleep "${INTERVAL}"
162+
elapsed=$((elapsed+INTERVAL))
163+
if [ "$elapsed" -ge "$TIMEOUT" ]; then
164+
echo "Timeout waiting for ${name} (${endpoint})."
165+
exit 1
166+
fi
167+
done
168+
}
169+
170+
{{- range $dependency := index . "dependencies" }}
171+
{{- $name := default "dependency" (get $dependency "name") }}
172+
{{- $endpointTemplate := default "" (get $dependency "endpoint") }}
173+
{{- $endpoint := tpl $endpointTemplate (index . "ctx") }}
174+
check {{ printf "%q" $name }} {{ printf "%q" $endpoint }}
175+
{{- end }}
176+
{{- end }}
177+
178+
{{/*
179+
Render arbitrarily defined init containers without modification.
180+
*/}}
181+
{{- define "nodes.extraInitContainers" -}}
182+
{{- $ctx := index . "context" -}}
183+
{{- $containers := default (list) (index . "containers") -}}
184+
{{- $indent := index . "indent" | default 2 -}}
185+
{{- if gt (len $containers) 0 -}}
186+
{{ tpl (toYaml $containers) $ctx | nindent $indent }}
128187
{{- end -}}
188+
{{- end }}
129189

130190
{{/*
131191
Resolve pod and container security contexts using global defaults plus chart overrides.

0 commit comments

Comments
 (0)