Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Polygon Heimdall chart #263

Merged
merged 9 commits into from
Oct 9, 2023
21 changes: 21 additions & 0 deletions dysnix/heimdall/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v2
name: heimdall
description: Polygon Heimdall consensus layer node Helm chart

version: 0.0.1
appVersion: "1.0.1"

keywords:
- heimdall
- polygon
- matic
- cryptocurrency
- blockchain
- consensus

sources:
- https://github.com/dysnix/charts

maintainers:
- name: VladStarr
email: vlad.derigin@dysnix.com
132 changes: 132 additions & 0 deletions dysnix/heimdall/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "heimdall.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 "heimdall.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 "heimdall.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create the name of the service account to use
*/}}
{{- define "heimdall.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "heimdall.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "heimdall.labels" -}}
helm.sh/chart: {{ include "heimdall.chart" . }}
app.kubernetes.io/name: {{ include "heimdall.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "heimdall.selectorLabels" -}}
app.kubernetes.io/name: {{ include "heimdall.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- with .Values.podLabels }}
{{ toYaml . | indent 0 }}
{{- end }}
{{- end }}

{{/*
Convert Golang slice to Toml arrat
VladStarr marked this conversation as resolved.
Show resolved Hide resolved
*/}}
{{- define "toml.list" -}}
{{- print "[" }}
{{- range $idx, $element := . }}
{{- if $idx }}, {{ end }}
{{- $element | quote }}
{{- end -}}
{{ print "]" -}}
{{- end }}

{{/*
Render Toml properties
*/}}
{{- define "toml.properties" -}}
{{- $root := index . 0 }}
{{- $context := index . 1 }}
{{- range $k, $v := $root }}
{{- if not (kindIs "map" $v) }}
{{- if kindIs "string" $v }}
{{- $v = (tpl $v $context | quote) }}
{{- else if kindIs "float64" $v }}
{{- $v = int $v }}
VladStarr marked this conversation as resolved.
Show resolved Hide resolved
{{- else if kindIs "slice" $v }}
{{- $v = include "toml.list" $v }}
{{- end }}
{{- if contains "." $k }}
{{- $k = quote $k }}
{{- end }}
{{ $k }} = {{ $v }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Render full Toml config including tables
voron marked this conversation as resolved.
Show resolved Hide resolved
*/}}
{{- define "toml.config" -}}
{{- $context := index . 0 }}
{{- $root := index . 1 }}
{{- include "toml.properties" (list $root $context) }} {{- /* top-level table */}}
{{- range $k, $v := $root }}
{{- if kindIs "map" $v }}
{{- if contains "." $k }}
{{- $k = quote $k }}
{{- end }}

[{{ $k }}]
{{- include "toml.properties" (list $v $context) }} {{/* 1st-level table */}}
{{- range $i, $j := $v }}
{{- if kindIs "map" $j }}
{{- if contains "." $i }}
{{- $i = quote $i }}
{{- end }}
{{- $i = print $k "." $i }}

[{{ $i }}]
{{- include "toml.properties" (list $j $context) }} {{/* 2nd-level table */}}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
11 changes: 11 additions & 0 deletions dysnix/heimdall/templates/configmap-scripts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "heimdall.fullname" . }}-scripts
labels:
{{- include "heimdall.labels" . | nindent 4 }}
data:
init-genesis.sh: |-
{{- include (print $.Template.BasePath "/scripts/_init-genesis.tpl") . | nindent 4 }}
download-snapshot.sh: |-
{{- include (print $.Template.BasePath "/scripts/_download-snapshot.tpl") . | nindent 4 }}
13 changes: 13 additions & 0 deletions dysnix/heimdall/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "heimdall.fullname" . }}-config
labels:
{{- include "heimdall.labels" . | nindent 4 }}
data:
config.toml: |-
{{- include "toml.config" (list $ .Values.tendermintConfig) | indent 4 }}
heimdall-config.toml: |-
{{- include "toml.config" (list $ .Values.heimdallConfig) | indent 4 }}
app.toml: |-
{{- include "toml.config" (list $ .Values.appConfig) | indent 4 }}
61 changes: 61 additions & 0 deletions dysnix/heimdall/templates/ingress-rest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{{- if and .Values.services.rest.enabled .Values.ingress.rest.enabled -}}
{{- $fullName := include "heimdall.fullname" . -}}
{{- $svcPort := .Values.services.rest.port -}}
{{- if and .Values.ingress.rest.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.rest.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.ingress.rest.annotations "kubernetes.io/ingress.class" .Values.ingress.rest.className}}
{{- end }}
{{- end }}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}-rest
labels:
{{- include "heimdall.labels" . | nindent 4 }}
{{- with .Values.ingress.rest.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if and .Values.ingress.rest.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.ingress.rest.className }}
{{- end }}
{{- if .Values.ingress.rest.tls }}
tls:
{{- range .Values.ingress.rest.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.rest.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
pathType: {{ .pathType }}
{{- end }}
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}-rest
port:
number: {{ $svcPort }}
{{- else }}
serviceName: {{ $fullName }}-rest
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
61 changes: 61 additions & 0 deletions dysnix/heimdall/templates/ingress-rpc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{{- if and .Values.services.rpc.enabled .Values.ingress.rpc.enabled -}}
{{- $fullName := include "heimdall.fullname" . -}}
{{- $svcPort := .Values.services.rpc.port -}}
{{- if and .Values.ingress.rpc.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.rpc.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.ingress.rpc.annotations "kubernetes.io/ingress.class" .Values.ingress.rpc.className}}
{{- end }}
{{- end }}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}-rpc
labels:
{{- include "heimdall.labels" . | nindent 4 }}
{{- with .Values.ingress.rpc.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if and .Values.ingress.rpc.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.ingress.rpc.className }}
{{- end }}
{{- if .Values.ingress.rpc.tls }}
tls:
{{- range .Values.ingress.rpc.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.rpc.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
pathType: {{ .pathType }}
{{- end }}
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}-rpc
port:
number: {{ $svcPort }}
{{- else }}
serviceName: {{ $fullName }}-rpc
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
15 changes: 15 additions & 0 deletions dysnix/heimdall/templates/scripts/_download-snapshot.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

set -e

if [ ! -f /data/.downloaded ]; then
apt-get -y update && apt-get -y install wget
wget -qO download.sh https://snapshot-download.polygon.technology/snapdown.sh
sed -i 's/sudo//g' download.sh
chmod +x download.sh

./download.sh --network {{ .Values.network }} --client heimdall --extract-dir /data/data --validate-checksum false
VladStarr marked this conversation as resolved.
Show resolved Hide resolved
touch /data/.downloaded
else
echo "Initial snapshot already downloaded, skipping."
fi
11 changes: 11 additions & 0 deletions dysnix/heimdall/templates/scripts/_init-genesis.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

set -e

if [ ! -f /data/.initialized ]; then
/usr/bin/heimdalld init --home /data
wget -O /data/config/genesis.json {{ .Values.init.genesisUrl }}
touch /data/.initialized
else
echo "Heimdall is already initialized, skipping init."
fi
36 changes: 36 additions & 0 deletions dysnix/heimdall/templates/service-metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{{- if .Values.services.metrics.enabled }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "heimdall.fullname" . }}-metrics
{{- if .Values.services.metrics.annotations }}
voron marked this conversation as resolved.
Show resolved Hide resolved
annotations:
{{- .Values.services.metrics.annotations | nindent 4 }}
{{- end }}
labels:
service-type: metrics
{{- include "heimdall.labels" . | nindent 4 }}
spec:
type: {{ .Values.services.metrics.type }}
{{- with .Values.services.metrics.loadBalancerIP }}
loadBalancerIP: {{ . }}
{{- end }}
{{- with .Values.services.metrics.clusterIP }}
clusterIP: {{ . }}
{{- end }}
{{- with .Values.services.metrics.externalTrafficPolicy }}
externalTrafficPolicy: {{ . }}
{{- end }}
{{- with .Values.services.metrics.internalTrafficPolicy }}
internalTrafficPolicy: {{ . }}
{{- end }}
{{- with .Values.services.p2p.publishNotReadyAddresses }}
VladStarr marked this conversation as resolved.
Show resolved Hide resolved
publishNotReadyAddresses: {{ . }}
{{- end }}
ports:
- name: metrics
port: {{ .Values.services.metrics.port }}
targetPort: metrics
selector:
{{- include "heimdall.selectorLabels" . | nindent 4 }}
{{- end }}
Loading
Loading