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 Bor chart #264

Merged
merged 7 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions dysnix/bor/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v2
name: bor
description: Polygon Bor execution layer node Helm chart

version: 0.0.1
appVersion: "1.0.6"

keywords:
- geth
- bor
- polygon
- matic
- cryptocurrency
- blockchain

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

maintainers:
- name: VladStarr
email: [email protected]
12 changes: 12 additions & 0 deletions dysnix/bor/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Bor RPC can be accessed via port {{ .Values.services.rpc.http.port }} on the following DNS name from within your cluster:
{{ include "bor.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local

To connect to Bor RPC:

1. Forward the port of the pod:

$ kubectl port-forward --namespace {{ .Release.Namespace }} $(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "bor.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath='{ .items[0].metadata.name }') {{ .Values.services.rpc.http.port }}

2. Connect using the bor cli:

$ bor attach http://{{ include "bor.fullname" . }}:{{ .Values.services.rpc.http.port }}
152 changes: 152 additions & 0 deletions dysnix/bor/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "bor.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 "bor.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 "bor.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

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

{{/*
Common labels
*/}}
{{- define "bor.labels" -}}
helm.sh/chart: {{ include "bor.chart" . }}
app.kubernetes.io/name: {{ include "bor.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 "bor.selectorLabels" -}}
app.kubernetes.io/name: {{ include "bor.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- with .Values.podLabels }}
{{ toYaml . | indent 0 }}
{{- end }}
{{- end }}

{{/*
Convert Golang slice to Toml array
*/}}
{{- 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 }}
{{- if contains "{{" $v }} {{- /* render templated values */}}
{{- $v = tpl $v $context }}
{{- if not (or (regexMatch "^[0-9]+$" $v) (regexMatch "^(true|false)$" $v)) }}
{{- $v = quote $v }}
{{- end }}
{{- else }}
{{- $v = quote $v }}
{{- end }}
{{- else if or (kindIs "int" $v) (kindIs "float64" $v) }}
{{- $v = int $v }}
{{- 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
*/}}
{{- 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 }}

{{- define "bor.healthcheck" -}}
{{- $context := index . 0 }}
{{- $root := index . 1 }}
{{- if and $root.exec (kindIs "string" $root.exec.command) }}
{{- omit $root "enabled" "exec" | toYaml }}
exec:
command:
{{- tpl $root.exec.command $context | nindent 4 }}
{{- else }}
{{- omit $root "enabled" | toYaml }}
{{- end }}
{{- end }}
11 changes: 11 additions & 0 deletions dysnix/bor/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 "bor.fullname" . }}-scripts
labels:
{{- include "bor.labels" . | nindent 4 }}
data:
check-readiness.sh: |-
{{- include (print $.Template.BasePath "/scripts/_check-readiness.tpl") . | nindent 4 }}
download-snapshot.sh: |-
{{- include (print $.Template.BasePath "/scripts/_download-snapshot.tpl") . | nindent 4 }}
9 changes: 9 additions & 0 deletions dysnix/bor/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "bor.fullname" . }}-config
labels:
{{- include "bor.labels" . | nindent 4 }}
data:
config.toml: |-
{{- include "toml.config" (list $ .Values.config) | indent 4 }}
61 changes: 61 additions & 0 deletions dysnix/bor/templates/ingress-http.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{{- if and .Values.services.rpc.enabled .Values.ingress.http.enabled -}}
{{- $fullName := include "bor.fullname" . -}}
{{- $svcPort := .Values.services.rpc.httpPort -}}
{{- if and .Values.ingress.http.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.http.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.ingress.http.annotations "kubernetes.io/ingress.class" .Values.ingress.http.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 }}-http
labels:
{{- include "bor.labels" . | nindent 4 }}
{{- with .Values.ingress.http.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if and .Values.ingress.http.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.ingress.http.className }}
{{- end }}
{{- if .Values.ingress.http.tls }}
tls:
{{- range .Values.ingress.http.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.http.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 }}
61 changes: 61 additions & 0 deletions dysnix/bor/templates/ingress-ws.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{{- if and .Values.services.rpc.enabled .Values.ingress.ws.enabled -}}
{{- $fullName := include "bor.fullname" . -}}
{{- $svcPort := .Values.services.rpc.wsPort -}}
{{- if and .Values.ingress.ws.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.ws.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.ingress.ws.annotations "kubernetes.io/ingress.class" .Values.ingress.ws.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 }}-ws
labels:
{{- include "bor.labels" . | nindent 4 }}
{{- with .Values.ingress.ws.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if and .Values.ingress.ws.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.ingress.ws.className }}
{{- end }}
{{- if .Values.ingress.ws.tls }}
tls:
{{- range .Values.ingress.ws.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.ws.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 }}
20 changes: 20 additions & 0 deletions dysnix/bor/templates/scripts/_check-readiness.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env sh
set -e

# Retrieving latest block timestamp
get_block_timestamp() {
bor attach http://localhost:{{ .Values.config.jsonrpc.http.port }} --exec "eth.getBlock(eth.blockNumber).timestamp" 2>/dev/null
}

if [ -z $1 ]; then
echo "Usage: $0 {allowed-block-gap-in-seconds}" && exit 1
fi

allowed_gap=$1
current_gap=$(expr $(date +%s) - $(get_block_timestamp))

if [ $current_gap -le $allowed_gap ]; then
exit 0
else
echo "Current block timestamp gap ($current_gap) is higher than allowed ($allowed_gap)" && exit 1
fi
15 changes: 15 additions & 0 deletions dysnix/bor/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.config.chain }} --client bor --extract-dir /data/bor/chaindata --validate-checksum true
touch /data/.downloaded
else
echo "Initial snapshot already downloaded, skipping."
fi
Loading
Loading