-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy path_helpers.tpl
372 lines (347 loc) · 11.8 KB
/
_helpers.tpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
{{/*
Expand the name of the chart.
*/}}
{{- define "aztec-network.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "aztec-network.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "aztec-network.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "aztec-network.labels" -}}
helm.sh/chart: {{ include "aztec-network.chart" . }}
{{ include "aztec-network.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "aztec-network.selectorLabels" -}}
app.kubernetes.io/name: {{ include "aztec-network.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Aztec Image
*/}}
{{- define "aztec-network.image" -}}
image: {{ .Values.images.aztec.image }}
imagePullPolicy: {{ .Values.images.aztec.pullPolicy }}
{{- end -}}
{{- define "aztec-network.pxeUrl" -}}
http://{{ include "aztec-network.fullname" . }}-pxe.{{ .Release.Namespace }}:{{ .Values.pxe.service.nodePort }}
{{- end -}}
{{- define "aztec-network.bootNodeUrl" -}}
http://{{ include "aztec-network.fullname" . }}-boot-node.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.bootNode.service.nodePort }}
{{- end -}}
{{- define "aztec-network.validatorUrl" -}}
http://{{ include "aztec-network.fullname" . }}-validator-lb.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.validator.service.nodePort }}
{{- end -}}
{{- define "aztec-network.blobSinkUrl" -}}
http://{{ include "aztec-network.fullname" . }}-blob-sink.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.blobSink.service.nodePort }}
{{- end -}}
{{- define "aztec-network.metricsHost" -}}
http://{{ include "aztec-network.fullname" . }}-metrics.{{ .Release.Namespace }}
{{- end -}}
{{- define "helpers.flag" -}}
{{- $name := index . 0 -}}
{{- $value := index . 1 -}}
{{- if $value -}}
{{- if kindIs "string" $value -}}
{{- if ne $value "" -}}
--{{ $name }} {{ $value }}{{ " " }}
{{- end -}}
{{- else -}}
--{{ $name }} {{ $value }}{{ " " }}
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Service Address Setup Container
*/}}
{{- define "aztec-network.serviceAddressSetupContainer" -}}
- name: setup-service-addresses
image: bitnami/kubectl
command:
- /bin/bash
- -c
- |
/scripts/setup-service-addresses.sh
env:
- name: NETWORK_PUBLIC
value: "{{ .Values.network.public }}"
- name: NAMESPACE
value: {{ .Release.Namespace }}
- name: TELEMETRY
value: "{{ .Values.telemetry.enabled }}"
- name: OTEL_COLLECTOR_ENDPOINT
value: "{{ .Values.telemetry.otelCollectorEndpoint }}"
- name: EXTERNAL_ETHEREUM_HOSTS
value: "{{ .Values.ethereum.execution.externalHosts }}"
- name: ETHEREUM_PORT
value: "{{ .Values.ethereum.execution.service.port }}"
- name: EXTERNAL_ETHEREUM_CONSENSUS_HOST
value: "{{ .Values.ethereum.beacon.externalHost }}"
- name: EXTERNAL_ETHEREUM_CONSENSUS_HOST_API_KEY
value: "{{ .Values.ethereum.beacon.apiKey }}"
- name: EXTERNAL_ETHEREUM_CONSENSUS_HOST_API_KEY_HEADER
value: "{{ .Values.ethereum.beacon.apiKeyHeader }}"
- name: ETHEREUM_CONSENSUS_PORT
value: "{{ .Values.ethereum.beacon.service.port }}"
- name: EXTERNAL_BOOT_NODE_HOST
value: "{{ .Values.bootNode.externalHost }}"
- name: BOOT_NODE_PORT
value: "{{ .Values.bootNode.service.nodePort }}"
- name: EXTERNAL_PROVER_NODE_HOST
value: "{{ .Values.proverNode.externalHost }}"
- name: PROVER_NODE_PORT
value: "{{ .Values.proverNode.service.nodePort }}"
- name: PROVER_BROKER_PORT
value: "{{ .Values.proverBroker.service.nodePort }}"
- name: USE_GCLOUD_LOGGING
value: "{{ .Values.telemetry.useGcloudLogging }}"
- name: SERVICE_NAME
value: {{ include "aztec-network.fullname" . }}
volumeMounts:
- name: scripts
mountPath: /scripts
- name: config
mountPath: /shared/config
{{- end -}}
{{/*
Sets up the OpenTelemetry resource attributes for a service
*/}}
{{- define "aztec-network.otelResourceSetupContainer" -}}
{{- $serviceName := base $.Template.Name | trimSuffix ".yaml" -}}
- name: setup-otel-resource
{{- include "aztec-network.image" . | nindent 2 }}
command:
- /bin/bash
- -c
- |
/scripts/setup-otel-resource.sh
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: K8S_POD_UID
valueFrom:
fieldRef:
fieldPath: metadata.uid
- name: K8S_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: K8S_NAMESPACE_NAME
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: OTEL_SERVICE_NAME
value: "{{ $serviceName }}"
- name: OTEL_RESOURCE_ATTRIBUTES
value: 'service.namespace={{ .Release.Namespace }},environment={{ .Values.environment | default "production" }}'
volumeMounts:
- name: scripts
mountPath: /scripts
- name: config
mountPath: /shared/config
{{- end -}}
{{/**
Anti-affinity when running in public network mode
*/}}
{{- define "aztec-network.publicAntiAffinity" -}}
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- validator
- boot-node
- prover-node
- prover-broker
topologyKey: "kubernetes.io/hostname"
namespaceSelector: {}
{{- end -}}
{{- define "aztec-network.gcpLocalSsd" -}}
nodeSelector:
local-ssd: "true"
{{- end -}}
{{- define "aztec-network.waitForEthereum" -}}
if [ -n "${EXTERNAL_ETHEREUM_HOSTS}" ]; then
export ETHEREUM_HOSTS="${EXTERNAL_ETHEREUM_HOSTS}"
fi
echo "Awaiting any ethereum node from: ${ETHEREUM_HOSTS}"
while true; do
for HOST in $(echo "${ETHEREUM_HOSTS}" | tr ',' '\n'); do
if curl -s -X POST -H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":67}' \
"${HOST}" | grep -q 0x; then
echo "Ethereum node ${HOST} is ready!"
break 2
fi
echo "Waiting for Ethereum node ${HOST}..."
done
sleep 5
done
{{- end -}}
{{/*
Combined wait-for-services and configure-env container for full nodes
*/}}
{{- define "aztec-network.combinedWaitAndConfigureContainer" -}}
- name: wait-and-configure
{{- include "aztec-network.image" . | nindent 2 }}
command:
- /bin/bash
- -c
- |
# If we already have a registry address, and the bootstrap nodes are set, then we don't need to wait for the services
if [ -n "{{ .Values.aztec.contracts.registryAddress }}" ] && [ -n "{{ .Values.aztec.bootstrapENRs }}" ]; then
echo "Registry address and bootstrap nodes already set, skipping wait for services"
echo "{{ include "aztec-network.pxeUrl" . }}" > /shared/pxe/pxe_url
else
source /shared/config/service-addresses
cat /shared/config/service-addresses
{{- include "aztec-network.waitForEthereum" . | nindent 8 }}
if [ "{{ .Values.validator.dynamicBootNode }}" = "true" ]; then
echo "{{ include "aztec-network.pxeUrl" . }}" > /shared/pxe/pxe_url
else
until curl --silent --head --fail "${BOOT_NODE_HOST}/status" > /dev/null; do
echo "Waiting for boot node..."
sleep 5
done
echo "Boot node is ready!"
echo "${BOOT_NODE_HOST}" > /shared/pxe/pxe_url
fi
fi
# Configure environment
source /shared/config/service-addresses
/scripts/configure-full-node-env.sh "$(cat /shared/pxe/pxe_url)"
volumeMounts:
- name: pxe-url
mountPath: /shared/pxe
- name: scripts
mountPath: /scripts
- name: config
mountPath: /shared/config
- name: contracts-env
mountPath: /shared/contracts
env:
- name: P2P_ENABLED
value: "{{ .Values.fullNode.p2p.enabled }}"
- name: BOOTSTRAP_NODES
value: "{{ .Values.aztec.bootstrapENRs }}"
- name: REGISTRY_CONTRACT_ADDRESS
value: "{{ .Values.aztec.contracts.registryAddress }}"
- name: SLASH_FACTORY_CONTRACT_ADDRESS
value: "{{ .Values.aztec.contracts.slashFactoryAddress }}"
{{- end -}}
{{/*
Combined P2P, Service Address, and OpenTelemetry Setup Container
*/}}
{{- define "aztec-network.combinedAllSetupContainer" -}}
{{- $serviceName := base $.Template.Name | trimSuffix ".yaml" -}}
- name: setup-all
{{- include "aztec-network.image" . | nindent 2 }}
command:
- /bin/bash
- -c
- |
# Setup P2P addresses
/scripts/setup-p2p-addresses.sh
# Setup service addresses
/scripts/setup-service-addresses.sh
# Setup OpenTelemetry resource
/scripts/setup-otel-resource.sh
env:
- name: NETWORK_PUBLIC
value: "{{ .Values.network.public }}"
- name: NAMESPACE
value: {{ .Release.Namespace }}
- name: P2P_TCP_PORT
value: "{{ .Values.validator.service.p2pTcpPort }}"
- name: P2P_UDP_PORT
value: "{{ .Values.validator.service.p2pUdpPort }}"
- name: TELEMETRY
value: "{{ .Values.telemetry.enabled }}"
- name: OTEL_COLLECTOR_ENDPOINT
value: "{{ .Values.telemetry.otelCollectorEndpoint }}"
- name: EXTERNAL_ETHEREUM_HOSTS
value: "{{ .Values.ethereum.execution.externalHosts }}"
- name: ETHEREUM_PORT
value: "{{ .Values.ethereum.execution.service.port }}"
- name: EXTERNAL_ETHEREUM_CONSENSUS_HOST
value: "{{ .Values.ethereum.beacon.externalHost }}"
- name: EXTERNAL_ETHEREUM_CONSENSUS_HOST_API_KEY
value: "{{ .Values.ethereum.beacon.apiKey }}"
- name: EXTERNAL_ETHEREUM_CONSENSUS_HOST_API_KEY_HEADER
value: "{{ .Values.ethereum.beacon.apiKeyHeader }}"
- name: ETHEREUM_CONSENSUS_PORT
value: "{{ .Values.ethereum.beacon.service.port }}"
- name: EXTERNAL_BOOT_NODE_HOST
value: "{{ .Values.bootNode.externalHost }}"
- name: BOOT_NODE_PORT
value: "{{ .Values.bootNode.service.nodePort }}"
- name: EXTERNAL_PROVER_NODE_HOST
value: "{{ .Values.proverNode.externalHost }}"
- name: PROVER_NODE_PORT
value: "{{ .Values.proverNode.service.nodePort }}"
- name: PROVER_BROKER_PORT
value: "{{ .Values.proverBroker.service.nodePort }}"
- name: USE_GCLOUD_LOGGING
value: "{{ .Values.telemetry.useGcloudLogging }}"
- name: SERVICE_NAME
value: {{ include "aztec-network.fullname" . }}
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: K8S_POD_UID
valueFrom:
fieldRef:
fieldPath: metadata.uid
- name: K8S_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: K8S_NAMESPACE_NAME
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: OTEL_SERVICE_NAME
value: "{{ $serviceName }}"
- name: OTEL_RESOURCE_ATTRIBUTES
value: 'service.namespace={{ .Release.Namespace }},environment={{ .Values.environment | default "production" }}'
volumeMounts:
- name: scripts
mountPath: /scripts
- name: config
mountPath: /shared/config
{{- end -}}