Skip to content

Commit

Permalink
Add Mina test charts
Browse files Browse the repository at this point in the history
  • Loading branch information
akoptelov committed Nov 16, 2023
1 parent bc848d0 commit 825056f
Show file tree
Hide file tree
Showing 50 changed files with 1,408 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mina-common/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: mina-test-common
description: Common templates for Mina test nodes
type: library
version: 0.0.1
appVersion: "0.0.0"
7 changes: 7 additions & 0 deletions mina-common/templates/_ip.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{/*
External service address
*/}}
{{- define "mina-common.service-external-ip" }}
{{- $name := include "mina-common.fullname" . | upper }}
{{- printf "$(%s_SERVICE_HOST)" (regexReplaceAll "[^A-Z_]" $name "_") }}
{{- end }}
27 changes: 27 additions & 0 deletions mina-common/templates/_name.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "mina-common.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name. Usually this is used as a deployment or service name.
*/}}
{{- define "mina-common.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}

{{/*
Creates a DNS-compatible name qualified with the release name
*/}}
{{- define "mina-common.qname" }}
{{ $name := index . 0 }}
{{ $ := index . 1 }}
{{ printf "%s-%s" $.Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
21 changes: 21 additions & 0 deletions mina-common/templates/_peers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{/*
Multiaddress of a peer
*/}}
{{- define "mina-common.peers.multiAddress" }}
{{- $name := include "mina-common.peers.dnsName" . }}
{{- $port := default "8302" .Peer.port }}
{{- $peerid := .Peer.peerId }}
{{- printf "/dns4/%s/tcp/%s/p2p/%s" $name $port $peerid }}
{{- end }}

{{/*
Peer DNS name (usually service name).
Assumes that the peer description is in .Values.Peer
*/}}
{{- define "mina-common.peers.dnsName" }}
{{- if .Peer.fullName }}
{{- .Peer.fullName -}}
{{- else }}
{{- include "mina-common.qname" (list .Peer.name .) | trim }}
{{- end }}
{{- end }}
6 changes: 6 additions & 0 deletions ocaml-test-node/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: mina-test-common
repository: file://../mina-common
version: 0.0.1
digest: sha256:c13c24e4a92368b1f1015144292e55432c5e0a23c1a2b6fa63c9b2e8bdfe3ff4
generated: "2023-11-13T12:34:00.297609804+03:00"
16 changes: 16 additions & 0 deletions ocaml-test-node/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v2
name: ocaml-test-node
description: A Helm chart for OCaml Mina test node.
type: application
version: 0.0.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "2.0.0rampup4"

dependencies:
- name: mina-test-common
repository: file://../mina-common
version: ">=0.0.0"
Empty file.
56 changes: 56 additions & 0 deletions ocaml-test-node/templates/_args.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{{/*
Mina arguments
*/}}
{{- define "ocaml-test-node.args" -}}[
{{ include "ocaml-test-node.args.common" . }}
{{ include "ocaml-test-node.peers.args" . }}
{{ include "ocaml-test-node.args.demoMode" . }}
{{ include "ocaml-test-node.args.blockProducer" . }}
{{ include "ocaml-test-node.args.values" . }}
]
{{- end }}

{{/*
Common Mina arguments
*/}}
{{- define "ocaml-test-node.args.common" -}}
"--log-level", "Debug",
"--insecure-rest-server",
"--config-file", {{ include "ocaml-test-node.daemonJson.path" . | quote }},
"--libp2p-keypair", {{ include "ocaml-test-node.libp2p.path" . | quote }},
{{- if .Values.isSeed }}
"--seed",
{{- end }}
"--external-ip", {{ include "mina-common.service-external-ip" . | quote }},
{{- end -}}

{{/*
Mina arguments for demo mode
*/}}
{{- define "ocaml-test-node.args.demoMode" -}}
{{- if .Values.demoMode -}}
--demo-mode,
{{- end -}}
{{- end -}}

{{/*
Mina arguments for block production mode
*/}}
{{- define "ocaml-test-node.args.blockProducer" -}}
{{- if .Values.blockProducer -}}
--blockProductionKey, {{ include "ocaml-test-node.blockProducerKey.path" . }}
{{- end -}}
{{- end -}}

{{/*
Mina arguments specified in .Values
*/}}
{{- define "ocaml-test-node.args.values" }}
{{- range .Values.args }}
{{ . | quote }},
{{- end }}
{{- end }}

{{/*
Mina external
*/}}
54 changes: 54 additions & 0 deletions ocaml-test-node/templates/_blockProducerKey.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{{/*
Full block production key path
*/}}
{{- define "ocaml-test-node.blockProducerKey.path" -}}
{{- include "ocaml-test-node.blockProducerKey.volumeMount.path" . }}/{{ include "ocaml-test-node.blockProducerKey.name" . }}
{{- end }}

{{/*
Mount point of block production keys
*/}}
{{- define "ocaml-test-node.blockProducerKey.volumeMount.path" -}}
/keys
{{- end }}

{{/*
Block production key file name
*/}}
{{- define "ocaml-test-node.blockProducerKey.name" -}}
.block-producer
{{- end }}

{{/*
Block producer key init containers (none)
*/}}
{{- define "ocaml-test-node.blockProducerKey.initContainers" }}{{ end -}}

{{/*
Block producer volume mount
*/}}
{{- define "ocaml-test-node.blockProducerKey.volumeMounts" }}
{{- if .Values.blockProducerKey.secret }}
- name: {{ include "ocaml-test-node.blockProducerKey.volume.name" }}
mountPath: {{ include "ocaml-test-node.blockProducerKey.volumeMount.path" . }}
{{- end }}
{{- end }}

{{/*
Block producer key volume
*/}}
{{- define "ocaml-test-node.blockProducerKey.volume.name" }}block-producer-key{{ end }}

{{/*
Block producer key volume
*/}}
{{- define "ocaml-test-node.blockProducerKey.volume" }}
{{- if .Values.blockProducerKey.secret }}
- name: {{ include "ocaml-test-node.blockProducerKey.volume.name" }}
secret:
secretName: {{ .Values.blockProducerKey.secret }}
items:
- key: key
path: {{ .Values.blockProducerKey.file.name }}
{{- end }}
{{- end }}
6 changes: 6 additions & 0 deletions ocaml-test-node/templates/_common.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{/*
Mina image
*/}}
{{- define "ocaml-test-node.image" -}}
{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}
{{- end }}
80 changes: 80 additions & 0 deletions ocaml-test-node/templates/_daemonJson.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{{/*
Path to daemon.json config file
*/}}
{{- define "ocaml-test-node.daemonJson.path" -}}
{{ include "ocaml-test-node.daemonJson.volumeMount.path" . }}/{{ include "ocaml-test-node.daemonJson.file.name" . }}
{{- end }}

{{/*
Mount point of block production keys
*/}}
{{- define "ocaml-test-node.daemonJson.volumeMount.path" -}}
/config
{{- end }}

{{/*
Block production key file name
*/}}
{{- define "ocaml-test-node.daemonJson.file.name" -}}
daemon.json
{{- end }}

{{/*
Init containers for daemon.json
*/}}
{{- define "ocaml-test-node.daemonJson.initContainers" -}}
{{- include "ocaml-test-node.daemonJson.fetchContainer" . }}
{{- end }}

{{/*
Init container for daemon.json
*/}}
{{- define "ocaml-test-node.daemonJson.fetchContainer" }}
{{- if .Values.daemonJson.remote }}
- name: daemon-json-download
image: alpine
command: [ "sh", "-c" ]
args:
- curl -o {{ include "ocaml-test-node.daemonJson.path" . }} {{ .Values.daemonJson.remote.url }}
volumeMounts:
- name: {{ include "ocaml-test-node.daemonJson.volume.name" . }}
mountPath: {{ include "ocaml-test-node.daemonJson.volumeMount.path" . }}
{{- else if .Values.daemonJson.local }}
- name: daemon-json-copy
image: {{ include "ocaml-test-node.image" . }}
command: [ "sh", "-c" ]
args:
- cp {{ .Values.daemonJson.local.path }} {{ include "ocaml-test-node.daemonJson.path" . }}
volumeMounts:
- name: {{ include "ocaml-test-node.daemonJson.volume.name" . }}
mountPath: {{ include "ocaml-test-node.daemonJson.volumeMount.path" . }}
{{- end }}
{{- end }}


{{/*
Config volume mount
*/}}
{{- define "ocaml-test-node.daemonJson.volumeMounts" }}
- name: {{ include "ocaml-test-node.daemonJson.volume.name" . }}
mountPath: {{ include "ocaml-test-node.daemonJson.volumeMount.path" . }}
{{- end }}

{{/*
Config volume (containing daemon.json)
*/}}
{{- define "ocaml-test-node.daemonJson.volume.name" }}daemon-json{{ end }}

{{/*
Config volume (containing daemon.json)
*/}}
{{- define "ocaml-test-node.daemonJson.volume" }}
- name: {{ include "ocaml-test-node.daemonJson.volume.name" . }}
{{- if .Values.daemonJson.secret }}
secret:
name: {{ .Values.daemonJson.secret }}
items: [ daemon.json ]
{{- else }}
emptyDir: {}
{{- end }}
{{- end }}
9 changes: 9 additions & 0 deletions ocaml-test-node/templates/_env.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{/*
Mina env
*/}}
{{- define "ocaml-test-node.env" }}
- name: "MINA_LIBP2P_PASS"
value: ""
- name: "MINA_PRIVKEY_PASS"
value: ""
{{- end }}
66 changes: 66 additions & 0 deletions ocaml-test-node/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "ocaml-test-node.name" -}}
{{- default .Chart.Name .Values.nameOverride | 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 "ocaml-test-node.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "ocaml-test-node.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "ocaml-test-node.labels" -}}
helm.sh/chart: {{ include "ocaml-test-node.chart" . }}
{{ include "ocaml-test-node.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
openmina.com/node-kind: ocaml
{{- end }}

{{/*
Pod labels
*/}}
{{- define "ocaml-test-node.podLabels" -}}
openmina.com/node-kind: ocaml
{{- end }}

{{/*
Selector labels
*/}}
{{- define "ocaml-test-node.selectorLabels" -}}
app.kubernetes.io/name: {{ include "ocaml-test-node.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "ocaml-test-node.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "ocaml-test-node.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
13 changes: 13 additions & 0 deletions ocaml-test-node/templates/_initContainers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{/*
All init containers
*/}}
{{- define "ocaml-test-node.initContainers" }}
{{ include "ocaml-test-node.daemonJson.initContainers" . }}
{{ include "ocaml-test-node.libp2p.initContainers" . }}
{{ include "ocaml-test-node.blockProducerKey.initContainers" . }}
{{- if (and (not .Values.seed) (gt (int .Values.seedWaitTimeout) 0))}}
- name: wait
image: busybox
command: ["sh", "-c", "sleep {{ .Values.seedWaitTimeout }}"]
{{- end }}
{{- end }}
Loading

0 comments on commit 825056f

Please sign in to comment.