From c0a67b500a98d8148d26e47e43a70add645bd9e7 Mon Sep 17 00:00:00 2001 From: David Lehuby Date: Wed, 4 Sep 2024 13:45:54 +1000 Subject: [PATCH] PM-1952 - Add Openmina Helm Chart --- .pre-commit-config.yaml | 1 + openmina-node/.helmignore | 23 ++++ openmina-node/Chart.yaml | 24 ++++ openmina-node/README.md | 75 ++++++++++++ openmina-node/templates/_helpers.tpl | 62 ++++++++++ openmina-node/templates/deployment.yaml | 86 ++++++++++++++ openmina-node/templates/secret.yaml | 9 ++ openmina-node/templates/serviceaccount.yaml | 13 +++ openmina-node/values.yaml | 123 ++++++++++++++++++++ 9 files changed, 416 insertions(+) create mode 100644 openmina-node/.helmignore create mode 100644 openmina-node/Chart.yaml create mode 100644 openmina-node/README.md create mode 100644 openmina-node/templates/_helpers.tpl create mode 100644 openmina-node/templates/deployment.yaml create mode 100644 openmina-node/templates/secret.yaml create mode 100644 openmina-node/templates/serviceaccount.yaml create mode 100644 openmina-node/values.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dc5f080a..0583fcfa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,6 +19,7 @@ repos: mina-staking-ledgers-exporter,\ mina-transactions-generator,\ on-chain-voting,\ + openmina-node,\ pgt-gov-bot,\ pgt-leader-bot,\ redisinsight,\ diff --git a/openmina-node/.helmignore b/openmina-node/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/openmina-node/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/openmina-node/Chart.yaml b/openmina-node/Chart.yaml new file mode 100644 index 00000000..95c380e8 --- /dev/null +++ b/openmina-node/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: openmina-node +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +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 + +# 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: "v0.8.1" diff --git a/openmina-node/README.md b/openmina-node/README.md new file mode 100644 index 00000000..a2ea5358 --- /dev/null +++ b/openmina-node/README.md @@ -0,0 +1,75 @@ +# 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) + +A Helm chart for Kubernetes + +## Prerequisites + +Before using this Helm chart, you should have the following prerequisites: + +- Access to Kubernetes cluster (If needed contact your friendly neighbourhood DevOps engineer) +- Helm >= v3.14.3 +- (**Optional**) helmfile >= v0.162.0 to install this chart + +## Installation + +> Note: **examples** can be found in the repository + +To install this Helm chart, the easiest is to create a helmfile.yaml with needed values and run: + +``` +helmfile template +helmfile apply +``` + +Or use helmfile only to generate resources and apply them with kubectl like so: + +``` +helmfile template | kubectl -f - +``` + +Verify that the chart is deployed successfully: + +> Note: `kubectl` is a better suited tool for this + +``` +helmfile status +``` + +## Values + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| affinity | object | `{}` | Affinity rules | +| deploymentAnnotations | object | `{}` | Annotations to add to deployments | +| 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 | `"v0.8.1"` | Overrides the image tag whose default is the chart appVersion. | +| imagePullSecrets | list | `[]` | The secrets used to pull the image | +| livenessProbe | string | `nil` | Liveness check configuration | +| nameOverride | string | `""` | The release name override | +| node.args | list | `[]` | The arguments to pass at runtime | +| node.envVars | object | `{}` | The environment variables to set | +| node.libp2p.privateKey | string | `""` | The libp2p private key | +| node.libp2p.publicKey | string | `""` | The libp2p public key | +| node.port | int | `3000` | The port the openmina container listens on | +| node.wallet.privateKey | string | `""` | The wallet private key | +| node.wallet.publicKey | string | `""` | The wallet public key | +| nodeSelector | object | `{}` | Node selector labels | +| podAnnotations | object | `{}` | Annotations to add to the pods | +| podLabels | object | `{}` | Label to add to the pods | +| podSecurityContext | object | `{}` | The Pod Security Context | +| readinessProbe | string | `nil` | Readiness check configuration | +| replicaCount | int | `1` | The number of replicas | +| resources | object | `{}` | Resource limitations for the pods | +| securityContext | object | `{}` | The Security Context | +| serviceAccount.annotations | object | `{}` | Annotations to add to the service account | +| serviceAccount.automount | bool | `true` | Automatically mount a ServiceAccount's API credentials? | +| serviceAccount.create | bool | `true` | Specifies whether a service account should be created | +| serviceAccount.name | string | `""` | If not set and create is true, a name is generated using the fullname template | +| tolerations | list | `[]` | Tolerations | +| volumeMounts | list | `[]` | Additional volumeMounts on the output Deployment definition. | +| volumes | list | `[]` | Additional volumes on the output Deployment definition. | + diff --git a/openmina-node/templates/_helpers.tpl b/openmina-node/templates/_helpers.tpl new file mode 100644 index 00000000..b6b24bc8 --- /dev/null +++ b/openmina-node/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "openmina-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 "openmina-node.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 }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "openmina-node.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "openmina-node.labels" -}} +helm.sh/chart: {{ include "openmina-node.chart" . }} +{{ include "openmina-node.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "openmina-node.selectorLabels" -}} +app.kubernetes.io/name: {{ include "openmina-node.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "openmina-node.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "openmina-node.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/openmina-node/templates/deployment.yaml b/openmina-node/templates/deployment.yaml new file mode 100644 index 00000000..aeb2f189 --- /dev/null +++ b/openmina-node/templates/deployment.yaml @@ -0,0 +1,86 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "openmina-node.fullname" . }} + {{- with .Values.deploymentAnnotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} + labels: + {{- include "openmina-node.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "openmina-node.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "openmina-node.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "openmina-node.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + 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: + {{- toYaml .Values.node.args | nindent 12 }} + {{- end }} + ports: + - name: http + containerPort: {{ .Values.node.port }} + protocol: TCP + env: + {{- if .Values.node.envVars }} + {{- toYaml .Values.node.envVars | nindent 12 }} + {{- end }} + livenessProbe: + {{- toYaml .Values.livenessProbe | nindent 12 }} + readinessProbe: + {{- toYaml .Values.readinessProbe | nindent 12 }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: openmina-node-data + mountPath: "/root/.openmina/keys" + readOnly: true + {{- with .Values.volumeMounts }} + {{- toYaml . | nindent 12 }} + {{- end }} + volumes: + - name: openmina-node-data + secret: + secretName: {{ include "openmina-node.fullname" . }} + defaultMode: 0600 + {{- with .Values.volumes }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/openmina-node/templates/secret.yaml b/openmina-node/templates/secret.yaml new file mode 100644 index 00000000..bddfd16c --- /dev/null +++ b/openmina-node/templates/secret.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "openmina-node.fullname" . }} +data: + wallet-key: {{ .Values.node.wallet.privateKey | b64enc }} + wallet-key.pub: {{ .Values.node.wallet.publicKey | b64enc }} + libp2p-key: {{ .Values.node.libp2p.privateKey | b64enc }} + libp2p-key.pub: {{ .Values.node.libp2p.publicKey | b64enc }} diff --git a/openmina-node/templates/serviceaccount.yaml b/openmina-node/templates/serviceaccount.yaml new file mode 100644 index 00000000..c63e5f65 --- /dev/null +++ b/openmina-node/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "openmina-node.serviceAccountName" . }} + labels: + {{- include "openmina-node.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/openmina-node/values.yaml b/openmina-node/values.yaml new file mode 100644 index 00000000..9faeac71 --- /dev/null +++ b/openmina-node/values.yaml @@ -0,0 +1,123 @@ +# Default values for openmina. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +# -- The number of replicas +replicaCount: 1 + +image: + # -- The image repository + repository: openmina/openmina + # -- The pullPolicy used when pulling the image + pullPolicy: IfNotPresent + # -- Overrides the image tag whose default is the chart appVersion. + tag: "v0.8.1" + +# -- The secrets used to pull the image +imagePullSecrets: [] +# -- The release name override +nameOverride: "" +# -- The full release name override +fullnameOverride: "" + +serviceAccount: + # -- Specifies whether a service account should be created + create: true + # -- Automatically mount a ServiceAccount's API credentials? + automount: true + # -- Annotations to add to the service account + annotations: {} + # -- The name of the service account to use. + # -- If not set and create is true, a name is generated using the fullname template + name: "" + +# -- Annotations to add to deployments +deploymentAnnotations: {} +# -- Annotations to add to the pods +podAnnotations: {} +# -- Label to add to the pods +podLabels: {} + +# -- The Pod Security Context +podSecurityContext: {} + # fsGroup: 2000 + +# -- The Security Context +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +node: + # -- The port the openmina container listens on + port: 3000 + wallet: + # -- The wallet private key + privateKey: "" + # -- The wallet public key + publicKey: "" + libp2p: + # -- The libp2p private key + privateKey: "" + # -- The libp2p public key + publicKey: "" + # -- The arguments to pass at runtime + args: [] + # -- The environment variables to set + envVars: {} + # - name: FOO + # value: FOO + # - name: BAR + # valueFrom: + # secretKeyRef: + # name: mySecret + # key: bar + +# -- Resource limitations for the pods +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +# -- Liveness check configuration +livenessProbe: + # httpGet: + # path: / + # port: http +# -- Readiness check configuration +readinessProbe: + # httpGet: + # path: / + # port: http + +# -- Additional volumes on the output Deployment definition. +volumes: [] +# - name: foo +# secret: +# secretName: mysecret +# optional: false + +# -- Additional volumeMounts on the output Deployment definition. +volumeMounts: [] +# - name: foo +# mountPath: "/etc/foo" +# readOnly: true + +# -- Node selector labels +nodeSelector: {} + +# -- Tolerations +tolerations: [] + +# -- Affinity rules +affinity: {}