Skip to content

Commit

Permalink
Merge pull request #296 from MinaFoundation/PM-2073-refactor-openmina…
Browse files Browse the repository at this point in the history
…-node

PM-2073 - Add Discover External IP to Openmina
  • Loading branch information
kaozenn authored Nov 18, 2024
2 parents d3a0ede + 71bad3a commit c16a6ee
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 5 deletions.
2 changes: 1 addition & 1 deletion openmina-node/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0
version: 0.1.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
Expand Down
8 changes: 6 additions & 2 deletions openmina-node/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# openmina-node

![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v0.8.1](https://img.shields.io/badge/AppVersion-v0.8.1-informational?style=flat-square)
![Version: 0.1.1](https://img.shields.io/badge/Version-0.1.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v0.8.1](https://img.shields.io/badge/AppVersion-v0.8.1-informational?style=flat-square)

A Helm chart for Kubernetes

Expand Down Expand Up @@ -46,7 +46,7 @@ helmfile status
| fullnameOverride | string | `""` | The full release name override |
| image.pullPolicy | string | `"IfNotPresent"` | The pullPolicy used when pulling the image |
| image.repository | string | `"openmina/openmina"` | The image repository |
| image.tag | string | `"0.8.3"` | Overrides the image tag whose default is the chart appVersion. |
| image.tag | string | `"0.11.2"` | Overrides the image tag whose default is the chart appVersion. |
| imagePullSecrets | list | `[]` | The secrets used to pull the image |
| ingress.annotations | object | `{}` | The Ingress Annotations |
| ingress.className | string | `""` | The Ingress Class Name to use |
Expand All @@ -58,6 +58,10 @@ helmfile status
| node.args | list | `[]` | The arguments to pass at runtime |
| node.envVars | object | `{}` | The environment variables to set |
| node.homeDirectory | string | `"/root/.openmina"` | The home directory of the node |
| node.libp2p.discoveryExternalIp | object | `{"enabled":false,"targetDNS":"example.nlb.us-west-2.amazonaws.com"}` | Discovery External IP |
| node.libp2p.discoveryExternalIp.enabled | bool | `false` | Enable Discovery External IP |
| node.libp2p.discoveryExternalIp.targetDNS | string | `"example.nlb.us-west-2.amazonaws.com"` | Target DNS |
| node.libp2p.port | int | `8302` | The libp2p peer id |
| node.libp2p.privateKey | string | `""` | The libp2p private key |
| node.libp2p.publicKey | string | `""` | The libp2p public key |
| node.wallet.privateKey | string | `""` | The wallet private key |
Expand Down
26 changes: 26 additions & 0 deletions openmina-node/scripts/get-external-ip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -e

retries=2 # Number of retries
delay=5 # Delay between retries in seconds
externalIp=""

until [ -n "$externalIp" ] || [ $retries -eq 0 ]; do
externalIp=$(nslookup "$DISCOVERY_EXTERNAL_IP_TARGET_DNS" | awk '/^Address: / { print $2; exit }')

if [ -n "$externalIp" ]; then
break
else
echo "Unable to resolve DNS... Retries left: $retries"
((retries--))
sleep $delay
fi
done

if [ -n "$externalIp" ]; then
echo "Discovered External IP: $externalIp"
echo $externalIp > /data/external-ip
else
echo "Error: Failed to retrieve external IP after $retries retries."
exit 1
fi
12 changes: 12 additions & 0 deletions openmina-node/templates/configmap-scripts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "openmina-node.fullname" . }}-scripts
labels:
app: {{ include "openmina-node.fullname" . }}
release: {{ include "openmina-node.fullname" . }}
data:
{{- range $path, $_ := .Files.Glob "scripts/*.sh" }}
{{ $path | trimPrefix "scripts/" }}: |-
{{ $.Files.Get $path | nindent 4 }}
{{ end }}
42 changes: 41 additions & 1 deletion openmina-node/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,51 @@ spec:
serviceAccountName: {{ include "openmina-node.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}

{{- if .Values.node.libp2p.discoveryExternalIp.enabled }}
initContainers:
- name: get-external-ip
image: busybox
command: ["/bin/sh", "/scripts/get-external-ip.sh"]
env:
- name: DISCOVERY_EXTERNAL_IP_TARGET_DNS
value: {{ .Values.node.libp2p.discoveryExternalIp.targetDNS | quote }}
volumeMounts:
- name: scripts
mountPath: /scripts/get-external-ip.sh
subPath: get-external-ip.sh
- name: data
mountPath: /data
{{- end }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: ["/usr/local/bin/openmina", "node"]
{{- if .Values.node.args }}
args:
{{- if .Values.node.libp2p.discoveryExternalIp.enabled }}
- "--libp2p-external-ip"
- "$(cat /data/external-ip)"
{{- end }}
{{- if .Values.node.args }}
{{- toYaml .Values.node.args | nindent 12 }}
{{- end }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
- name: libp2p
containerPort: {{ .Values.node.libp2p.port }}
protocol: TCP
env:
- name: OPENMINA_HOME
value: {{ .Values.node.homeDirectory }}
- name: PORT
value: {{ .Values.service.port | quote }}
- name: LIBP2P_PORT
value: {{ .Values.node.libp2p.port | quote }}
{{- if .Values.node.envVars }}
{{- toYaml .Values.node.envVars | nindent 12 }}
{{- end }}
Expand All @@ -67,9 +94,16 @@ spec:
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- name: scripts
mountPath: /scripts/entrypoint.sh
subPath: entrypoint.sh
- name: openmina-keys
mountPath: {{ .Values.node.homeDirectory }}/keys
readOnly: true
{{- if .Values.node.libp2p.discoveryExternalIp.enabled }}
- name: data
mountPath: /data
{{- end }}
{{- if .Values.persistence.enabled }}
- name: openmina-home
mountPath: {{ .Values.node.homeDirectory }}
Expand All @@ -82,6 +116,12 @@ spec:
secret:
secretName: {{ include "openmina-node.fullname" . }}
defaultMode: 0600
- name: scripts
configMap:
name: {{ include "openmina-node.fullname" . }}-scripts
defaultMode: 0755
- name: data
emptyDir: {}
{{- if .Values.persistence.enabled }}
- name: openmina-home
persistentVolumeClaim:
Expand Down
4 changes: 4 additions & 0 deletions openmina-node/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ spec:
targetPort: http
protocol: TCP
name: http
- port: {{ .Values.node.libp2p.port }}
targetPort: libp2p
protocol: TCP
name: libp2p
selector:
{{- include "openmina-node.selectorLabels" . | nindent 4 }}
10 changes: 9 additions & 1 deletion openmina-node/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ image:
# -- The pullPolicy used when pulling the image
pullPolicy: IfNotPresent
# -- Overrides the image tag whose default is the chart appVersion.
tag: "0.8.3"
tag: "0.11.2"

# -- The secrets used to pull the image
imagePullSecrets: []
Expand Down Expand Up @@ -90,6 +90,14 @@ node:
privateKey: ""
# -- The libp2p public key
publicKey: ""
# -- The libp2p peer id
port: 8302
# -- Discovery External IP
discoveryExternalIp:
# -- Enable Discovery External IP
enabled: false
# -- Target DNS
targetDNS: example.nlb.us-west-2.amazonaws.com
# -- The arguments to pass at runtime
args: []
# -- The environment variables to set
Expand Down

0 comments on commit c16a6ee

Please sign in to comment.