From 7a5ab2dfbb950df840403ec876d04356d895daa8 Mon Sep 17 00:00:00 2001 From: Anton Rubets Date: Mon, 14 Oct 2024 12:26:55 +0300 Subject: [PATCH 1/3] Add ton chart first version --- dysnix/ton/.helmignore | 23 +++ dysnix/ton/Chart.yaml | 28 ++++ dysnix/ton/files/api_healthcheck.py | 37 +++++ dysnix/ton/files/config.py | 97 ++++++++++++ dysnix/ton/files/init.sh | 63 ++++++++ dysnix/ton/files/node_healthcheck.sh | 32 ++++ dysnix/ton/templates/NOTES.txt | 22 +++ dysnix/ton/templates/_helpers.tpl | 62 ++++++++ dysnix/ton/templates/_volumes.tpl | 71 +++++++++ dysnix/ton/templates/configmaps.yaml | 34 +++++ dysnix/ton/templates/ingress.yaml | 61 ++++++++ dysnix/ton/templates/service.yaml | 15 ++ dysnix/ton/templates/serviceaccount.yaml | 12 ++ dysnix/ton/templates/statefullset.yaml | 134 ++++++++++++++++ dysnix/ton/values.yaml | 187 +++++++++++++++++++++++ 15 files changed, 878 insertions(+) create mode 100644 dysnix/ton/.helmignore create mode 100644 dysnix/ton/Chart.yaml create mode 100644 dysnix/ton/files/api_healthcheck.py create mode 100644 dysnix/ton/files/config.py create mode 100644 dysnix/ton/files/init.sh create mode 100644 dysnix/ton/files/node_healthcheck.sh create mode 100644 dysnix/ton/templates/NOTES.txt create mode 100644 dysnix/ton/templates/_helpers.tpl create mode 100644 dysnix/ton/templates/_volumes.tpl create mode 100644 dysnix/ton/templates/configmaps.yaml create mode 100644 dysnix/ton/templates/ingress.yaml create mode 100644 dysnix/ton/templates/service.yaml create mode 100644 dysnix/ton/templates/serviceaccount.yaml create mode 100644 dysnix/ton/templates/statefullset.yaml create mode 100644 dysnix/ton/values.yaml diff --git a/dysnix/ton/.helmignore b/dysnix/ton/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/dysnix/ton/.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/dysnix/ton/Chart.yaml b/dysnix/ton/Chart.yaml new file mode 100644 index 00000000..21b94079 --- /dev/null +++ b/dysnix/ton/Chart.yaml @@ -0,0 +1,28 @@ +apiVersion: v2 +name: ton +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.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: "1.16.0" + +maintainers: + - name: Tony + email: anton.rubets@dysnix.com diff --git a/dysnix/ton/files/api_healthcheck.py b/dysnix/ton/files/api_healthcheck.py new file mode 100644 index 00000000..936cf631 --- /dev/null +++ b/dysnix/ton/files/api_healthcheck.py @@ -0,0 +1,37 @@ + +import socket +import requests +import sys + +def is_port_open(host, port): + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + try: + s.connect((host, port)) + return True + except (socket.timeout, ConnectionRefusedError): + return False + +def check_url(url): + try: + response = requests.get(url) + return response.status_code == 200 + except requests.RequestException: + return False + +def main(): + host = '127.0.0.1' + port = 8081 + url = f'http://{host}:{port}/getMasterchainInfo' + + if not is_port_open(host, port): + print(f"Port {port} on {host} is not open.") + sys.exit(1) + + if not check_url(url): + print(f"URL {url} did not return status code 200.") + sys.exit(1) + + print(f"Port {port} on {host} is open and URL {url} returned status code 200.") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/dysnix/ton/files/config.py b/dysnix/ton/files/config.py new file mode 100644 index 00000000..5afd9f0d --- /dev/null +++ b/dysnix/ton/files/config.py @@ -0,0 +1,97 @@ + +import json +import os +from time import sleep + +TON_ROOT = os.getenv('TON_ROOT', '/var/ton-work/db') +ETC_ROOT=f"{TON_ROOT}/etc" +GLOBAL_CONFIG=f"{ETC_ROOT}/global-config.json" +API_GLOBAL_CONFIG=f"{ETC_ROOT}/api-global-config.json" +CERT_ROOT=f"{ETC_ROOT}/node_certs" +NODE_CONFIG=f"{TON_ROOT}/config.json" +NODE_CONFIG_OUT=f"{TON_ROOT}/config.json" + +if not os.path.exists(f"{CERT_ROOT}/json_liteserver"): + print("Waiting for json_liteserver") + sleep(2) + +if os.path.exists(NODE_CONFIG): + with open(NODE_CONFIG, 'r') as f: + config = json.load(f) + +# TON NODE CONFIG GENERATION +cert_files = [f for f in os.listdir(CERT_ROOT)] +if "json_server" in cert_files: + server_cert: dict = json.load(open(f"{CERT_ROOT}/json_server")) +else: + raise Exception("json_server not found") + +if "json_client" in cert_files: + client_cert: dict = json.load(open(f"{CERT_ROOT}/json_client")) +else: + raise Exception("json_client not found") + +if "json_liteserver" in cert_files: + liteserver_cert: dict = json.load(open(f"{CERT_ROOT}/json_liteserver")) +else: + raise Exception("json_liteserver not found") + +config['control'] = [{ + "id": server_cert.get('PUB'), + "port": int(os.getenv('CONSOLER_PORT', "30001")), + "allowed": [ + { + "id": client_cert.get('PUB'), + "permissions": 15 + } + ] + } +] +config['liteservers'] = [ + { + "id": liteserver_cert.get('PUB'), + "port": int(os.getenv('LITESERVER_PORT', "43679")) + } +] + +with open(NODE_CONFIG_OUT, 'w') as f: + json.dump(config, f, indent=4) + +# HERE PART FOR TON-HTTP-API +# Need get global-config.json and change liteserver only to my node +# This is 127.0.0.1 + port 43679 + +# Make ip +# CERT str(codecs.encode(lite_cert_read, "base64")).replace("\n", "")[2:46] + +import socket +import struct +import codecs +ip_local = "127.0.0.1" +if "liteserver.pub" in cert_files: + f = open(f"{CERT_ROOT}/liteserver.pub", "rb+") + lite_cert_read = f.read()[4:] +else: + raise Exception("liteserver.pub not found") +liteserver = [ + { + "ip": struct.unpack('>i', socket.inet_aton(ip_local))[0], + "port": int(os.getenv('LITESERVER_PORT', "43679")), + "id": { + "@type": "pub.ed25519", + "key": str(codecs.encode(lite_cert_read, "base64").decode("utf-8").replace("\n", "")) + } + } +] + +if os.path.exists(GLOBAL_CONFIG): + with open(GLOBAL_CONFIG, 'r') as f: + global_config = json.load(f) +else: + raise Exception("global-config.json not found") + +global_config['liteservers'] = liteserver + +with open(API_GLOBAL_CONFIG, 'w') as f: + json.dump(global_config, f, indent=4) + diff --git a/dysnix/ton/files/init.sh b/dysnix/ton/files/init.sh new file mode 100644 index 00000000..7727e4d3 --- /dev/null +++ b/dysnix/ton/files/init.sh @@ -0,0 +1,63 @@ + +#!/bin/sh +# +# TON_ROOT="/var/ton-work/db" +# CONSOLE_PORT="30001" + +ETC_ROOT="$TON_ROOT/etc" +LOG_ROOT="$TON_ROOT/log" +CERT_ROOT="$ETC_ROOT/node_certs" +MAINNET_CONFIG_URL="https://ton.org/global-config.json" +MAINNET_CONFIG="$ETC_ROOT/global-config.json" +NODE_CONFIG="$TON_ROOT/config.json" +KEYRING_ROOT="$TON_ROOT/keyring" +# Function for execute generate-random-id in specific directory +generate_random_id() { + local mode=$1 + local key_name=$2 + local mv + if [ ! -f "${CERT_ROOT}/${key_name}" ]; then + cd $CERT_ROOT + read -r PRI PUB <<< $(generate-random-id -m $mode -n $key_name) + echo "{\"PRI\": \"${PRI}\",\"PUB\": \"${PUB}\"}" > "${CERT_ROOT}/json_${key_name}" + if [ $key_name == "server" ]; then + cp "${CERT_ROOT}/${key_name}" "${KEYRING_ROOT}/${PRI}" + fi + if [ $key_name == "liteserver" ]; then + cp "${CERT_ROOT}/${key_name}" "${KEYRING_ROOT}/${PRI}" + fi + else + echo -e "##### Found existing ${key_name} keys, skipping" + fi +} + +mkdir -p $ETC_ROOT +mkdir -p $KEYRING_ROOT +mkdir -p $CERT_ROOT + +# GET IP +PUBLIC_IP=$(curl -s ifconfig.me) + +# DOWNLOAD MAINNET CONFIG + +if [ -f $MAINNET_CONFIG ]; then + echo -e "##### Found existing global config, skipping" +else + echo -e "##### Downloading provided global config." + wget -q $MAINNET_CONFIG_URL -O $MAINNET_CONFIG +fi + +# GENERATE CONFIG +if [ -f $NODE_CONFIG ]; then + echo -e "##### Found existing local config, skipping" +else + echo -e "##### Using provided IP: $PUBLIC_IP:$CONSOLE_PORT" + validator-engine -C $MAINNET_CONFIG --db $TON_ROOT --ip "$PUBLIC_IP:$CONSOLE_PORT" +fi + + + +# GENERATE CERTIFICATES +generate_random_id "keys" "server" +generate_random_id "keys" "client" +generate_random_id "keys" "liteserver" \ No newline at end of file diff --git a/dysnix/ton/files/node_healthcheck.sh b/dysnix/ton/files/node_healthcheck.sh new file mode 100644 index 00000000..a75dc470 --- /dev/null +++ b/dysnix/ton/files/node_healthcheck.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# TON_ROOT="/var/ton-work/db" +# CONSOLE_PORT="30001" + +ETC_ROOT="$TON_ROOT/etc" +LOG_ROOT="$TON_ROOT/log" +CERT_ROOT="$ETC_ROOT/node_certs" + +SERVER_PUB="${CERT_ROOT}/server.pub" +CLIENT_CERT="${CERT_ROOT}/client" + +if [ ! -f "${SERVER_PUB}" ]; then + echo "Server keys not found, exiting" + exit 1 +fi + +if [ ! -f "${CLIENT_CERT}" ]; then + echo "Client keys not found, exiting" + exit 1 +fi + +server_time=`validator-engine-console -p $SERVER_PUB -k $CLIENT_CERT -a 127.0.0.1:30001 -c getstats | grep unixtime | awk '{print $2}'` +current_time=`date +%s` +time_diff=$((current_time - server_time)) +echo "Time difference: $time_diff" + +if [ $time_diff -gt 2 ]; then + echo "Time difference is greater than 2 seconds, exiting" + exit 1 +fi + +exit 0 \ No newline at end of file diff --git a/dysnix/ton/templates/NOTES.txt b/dysnix/ton/templates/NOTES.txt new file mode 100644 index 00000000..a661e473 --- /dev/null +++ b/dysnix/ton/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "ton.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "ton.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "ton.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "ton.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/dysnix/ton/templates/_helpers.tpl b/dysnix/ton/templates/_helpers.tpl new file mode 100644 index 00000000..343c646b --- /dev/null +++ b/dysnix/ton/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "ton.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 "ton.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 "ton.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "ton.labels" -}} +helm.sh/chart: {{ include "ton.chart" . }} +{{ include "ton.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "ton.selectorLabels" -}} +app.kubernetes.io/name: {{ include "ton.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "ton.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "ton.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/dysnix/ton/templates/_volumes.tpl b/dysnix/ton/templates/_volumes.tpl new file mode 100644 index 00000000..713c1149 --- /dev/null +++ b/dysnix/ton/templates/_volumes.tpl @@ -0,0 +1,71 @@ +{{- define "ton.volumeMountsTemplate" -}} +- name: data + mountPath: {{ $.Values.config.fullnode.root }} +- name: archive + mountPath: {{ $.Values.config.fullnode.root }}/archive +{{- end }} + + +{{- define "ton.volumesTemplate" }} +{{- with $.Values.persistance }} + {{- if (and (hasKey . "data") (not (empty .data))) }} + {{- if eq .data.type "hostPath" }} +- name: data + hostPath: + path: {{ required "persistance.data.path required" .data.path }} + type: {{ .data.perm | default "DirectoryOrCreate" }} + {{- end }} + {{- end }} + {{- if (and (hasKey . "archive") (not (empty .archive))) }} + {{- if eq .archive.type "hostPath" }} +- name: archive + hostPath: + path: {{ required "persistance.archive.path required" .archive.path }} + type: {{ .archive.perm | default "DirectoryOrCreate" }} + {{- end }} + {{- end }} +{{- end }} +{{- end }} + + +{{- define "ton.valoumeClainmTemplates" }} +{{- with $.Values.permistance }} +{{- if (and (hasKey . "data") (not (empty .data))) }} + {{- if eq .data.type "pvc" }} +- name: data + label: + app.kubernetes.io/name: {{ include "ton.name" . }} + app.kubernetes.io/instance: {{ $.Release.Name }} + annotations: + {{- if .data.annotations }} + {{- toYaml .data.annotations | nindent 4 }} + {{- end }} + accessModes: + - {{ .data.accessMode | default "ReadWriteOnce" }} + storageClassName: {{ .data.storageClassName | default "" }} + resources: + requests: + storage: {{ .data.size }} +{{- end }} +{{- end }} +{{- if .archive -}} +{{- if eq .archive.type "pvc" -}} +- name: data + label: + app.kubernetes.io/name: {{ include "ton.name" . }} + app.kubernetes.io/instance: {{ $.Release.Name }} + annotations: + {{- if .archive.annotations }} + {{- toYaml .archive.annotations | nindent 4 }} + {{- end }} + accessModes: + - {{ .archive.accessMode | default "ReadWriteOnce" }} + storageClassName: {{ .archive.storageClassName | default "" }} + resources: + requests: + storage: {{ .archive.size }} +{{- end }} +{{- end }} +{{- end }} +{{- end }} + diff --git a/dysnix/ton/templates/configmaps.yaml b/dysnix/ton/templates/configmaps.yaml new file mode 100644 index 00000000..69010dc3 --- /dev/null +++ b/dysnix/ton/templates/configmaps.yaml @@ -0,0 +1,34 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "ton.fullname" . }}-scripts + labels: + {{- include "ton.labels" . | nindent 4 }} +data: + init.sh: |- + {{- tpl ($.Files.Get "files/init.sh") . | indent 4 }} + config.py: |- + {{- tpl ($.Files.Get "files/config.py") . | indent 4 }} + api_healthcheck.py: |- + {{- tpl ($.Files.Get "files/api_healthcheck.py") . | indent 4 }} + node_healthcheck.sh: |- + {{- tpl ($.Files.Get "files/node_healthcheck.sh") . | indent 4 }} + +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "ton.fullname" . }}-api-config + labels: + {{- include "ton.labels" . | nindent 4 }} +data: + {{- range $key, $value := .Values.config.api.env }} + {{- if eq $key "TON_API_TONLIB_LITESERVER_CONFIG"}} + {{ $key }}: "{{ $.Values.config.fullnode.root}}/{{ $value }}" + {{- else if eq $key "TON_API_TONLIB_KEYSTORE"}} + {{ $key }}: "{{ $.Values.config.fullnode.root}}/{{ $value }}" + {{- else }} + {{ $key }}: {{ $value | quote }} + {{- end }} + {{- end }} + TON_API_HTTP_PORT: "{{ .Values.config.api.port }}" \ No newline at end of file diff --git a/dysnix/ton/templates/ingress.yaml b/dysnix/ton/templates/ingress.yaml new file mode 100644 index 00000000..0d7ef5b4 --- /dev/null +++ b/dysnix/ton/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "ton.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.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 }} + labels: + {{- include "ton.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.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 }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/dysnix/ton/templates/service.yaml b/dysnix/ton/templates/service.yaml new file mode 100644 index 00000000..4b089594 --- /dev/null +++ b/dysnix/ton/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "ton.fullname" . }} + labels: + {{- include "ton.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: api + protocol: TCP + name: api + selector: + {{- include "ton.selectorLabels" . | nindent 4 }} diff --git a/dysnix/ton/templates/serviceaccount.yaml b/dysnix/ton/templates/serviceaccount.yaml new file mode 100644 index 00000000..7bd91594 --- /dev/null +++ b/dysnix/ton/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "ton.serviceAccountName" . }} + labels: + {{- include "ton.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/dysnix/ton/templates/statefullset.yaml b/dysnix/ton/templates/statefullset.yaml new file mode 100644 index 00000000..3fd862c3 --- /dev/null +++ b/dysnix/ton/templates/statefullset.yaml @@ -0,0 +1,134 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "ton.fullname" . }} + labels: + {{- include "ton.labels" . | nindent 4 }} +spec: + selector: + matchLabels: + {{- include "ton.selectorLabels" . | nindent 6 }} + serviceName: {{ include "ton.name" . }} + replicas: {{ .Values.replicaCount }} + template: + metadata: + labels: + {{- include "ton.labels" . | nindent 8 }} + spec: + initContainers: + - name: config-initializer + image: "{{ .Values.image.tonnode.repository }}:{{ .Values.image.tonnode.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.tonnode.pullPolicy }} + command: ["/bin/bash", "/scripts/init.sh"] + env: + - name: TON_ROOT + value: {{ .Values.config.fullnode.root }} + - name: CONSOLE_PORT + value: {{ .Values.config.fullnode.console_port | quote }} + - name: LITESERVER_PORT + value: {{ .Values.config.fullnode.liteserver_port | quote }} + volumeMounts: + - name: data + mountPath: /var/ton-work/db + - name: scripts-volume + mountPath: "/scripts/init.sh" + subPath: init.sh + - name: config-generator + image: "python:3.11" + imagePullPolicy: {{ .Values.image.tonnode.pullPolicy }} + command: ["python3", "/scripts/config.py"] + env: + - name: TON_ROOT + value: {{ .Values.config.fullnode.root }} + - name: CONSOLE_PORT + value: {{ .Values.config.fullnode.console_port | quote }} + - name: LITESERVER_PORT + value: {{ .Values.config.fullnode.liteserver_port | quote }} + volumeMounts: + - name: data + mountPath: /var/ton-work/db + - name: scripts-volume + mountPath: /scripts/config.py + subPath: config.py + containers: + - name: ton-node + image: "{{ .Values.image.tonnode.repository }}:{{ .Values.image.tonnode.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.tonnode.pullPolicy }} + command: ["validator-engine", "-c", "/var/ton-work/db/config.json", "-C", "/var/ton-work/db/etc/global-config.json", "--db", "/var/ton-work/db/"] + env: + - name: TON_ROOT + value: {{ .Values.config.fullnode.root }} + ports: + - containerPort: {{ .Values.config.fullnode.console_port }} + hostPort: {{ .Values.config.fullnode.console_port }} + name: console + protocol: UDP + - containerPort: {{ .Values.config.fullnode.liteserver_port }} + hostPort: {{ .Values.config.fullnode.liteserver_port }} + name: liteserver + protocol: TCP + {{- if .Values.nodecheck.readinessProbe.enabled }} + {{- with (omit .Values.nodecheck.readinessProbe "enabled") }} + readinessProbe: + {{- toYaml . | nindent 10 }} + {{- end }} + {{- end }} + {{- if .Values.nodecheck.livenessProbe.enabled }} + {{- with (omit .Values.nodecheck.livenessProbe "enabled") }} + livenessProbe: + {{- toYaml . | nindent 10 }} + {{- end }} + {{- end }} + {{- if .Values.nodecheck.startupProbe.enabled }} + {{- with (omit .Values.nodecheck.startupProbe "enabled") }} + startupProbe: + {{- toYaml . | nindent 10 }} + {{- end }} + {{- end }} + volumeMounts: + {{- include "ton.volumeMountsTemplate" . | nindent 8 }} + - name: scripts-volume + mountPath: /scripts/health.sh + subPath: node_healthcheck.sh + #### API + - name: ton-api + image: toncenter/ton-http-api:v2.0.46 + imagePullPolicy: {{ .Values.image.tonnode.pullPolicy }} + command: ["/bin/sh", "-c", "gunicorn -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8081 pyTON.main:app"] + ports: + - containerPort: {{ .Values.config.api.port }} + name: api + protocol: TCP + envFrom: + - configMapRef: + name: {{ include "ton.fullname" . }}-api-config + {{- if .Values.apicheck.readinessProbe.enabled }} + {{- with (omit .Values.apicheck.readinessProbe "enabled") }} + readinessProbe: + {{- toYaml . | nindent 10 }} + {{- end }} + {{- end }} + {{- if .Values.apicheck.livenessProbe.enabled }} + {{- with (omit .Values.apicheck.livenessProbe "enabled") }} + livenessProbe: + {{- toYaml . | nindent 10 }} + {{- end }} + {{- end }} + {{- if .Values.apicheck.startupProbe.enabled }} + {{- with (omit .Values.apicheck.startupProbe "enabled") }} + startupProbe: + {{- toYaml . | nindent 10 }} + {{- end }} + {{- end }} + volumeMounts: + {{- include "ton.volumeMountsTemplate" . | nindent 8 }} + - name: scripts-volume + mountPath: /scripts/health.py + subPath: api_healthcheck.py + volumes: + {{- include "ton.volumesTemplate" . | nindent 6 }} + - name: scripts-volume + configMap: + name: {{ include "ton.fullname" . }}-scripts + volumeClaimTemplates: + {{- include "ton.valoumeClainmTemplates" . | nindent 4 }} \ No newline at end of file diff --git a/dysnix/ton/values.yaml b/dysnix/ton/values.yaml new file mode 100644 index 00000000..65106872 --- /dev/null +++ b/dysnix/ton/values.yaml @@ -0,0 +1,187 @@ +replicaCount: 1 + +image: + # -- image configuration for ton + tonnode: + repository: ghcr.io/ton-blockchain/ton + pullPolicy: IfNotPresent + tag: "v2024.09" + # -- image configuration for ton api + apinode: + repository: toncenter/ton-http-api + pullPolicy: IfNotPresent + tag: "v2.0.46" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: 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: "" + +# -- set persistence info for data and archive +persistance: + data: {} + # type: hostPath | existingClaim | pvc + # hostPath: /data/chain + # existingClaim: $name + # storageClass: "standard" + # accessModes: + # - ReadWriteOnce + # size: 10Gi + archive: {} + # type: hostPath | existingClaim | pvc + # hostPath: /data/accounts + # existingClaim: $name + # storageClass: "standard" + # accessModes: + # - ReadWriteOnce + # size: 10Gi + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +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 + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +config: + # -- ton chain node config + fullnode: + root: /var/ton-work/db + console_port: 30001 + liteserver_port: 43679 + # -- ton api config + api: + port: 8081 + env: + TON_API_ROOT_PATH: "/" + TON_API_WEBSERVERS_WORKERS: "4" + TON_API_GET_METHODS_ENABLED: "1" + TON_API_JSON_RPC_ENABLED: "1" + TON_API_LOGS_JSONIFY: "1" + TON_API_CACHE_ENABLED: "0" + TON_API_TONLIB_LITESERVER_CONFIG: etc/api-global-config.json + TON_API_TONLIB_KEYSTORE: etc/ton_keystore/ + +# -- Ton node probes +nodecheck: + readinessProbe: + enabled: true + timeoutSeconds: 10 + failureThreshold: 2 + successThreshold: 1 + periodSeconds: 10 + exec: + command: + - sh + - /scripts/health.sh + # 24h for sync + startupProbe: + enabled: true + failureThreshold: 2880 + periodSeconds: 30 + timeoutSeconds: 1 + exec: + command: + - sh + - /scripts/health.sh + livenessProbe: + enabled: true + timeoutSeconds: 3 + failureThreshold: 2 + successThreshold: 1 + periodSeconds: 10 + exec: + command: + - sh + - /scripts/health.sh + +# -- Api node probes +apicheck: + readinessProbe: + enabled: true + timeoutSeconds: 10 + failureThreshold: 2 + successThreshold: 1 + periodSeconds: 10 + exec: + command: + - python3 + - /scripts/health.py + livenessProbe: + enabled: true + timeoutSeconds: 3 + failureThreshold: 2 + successThreshold: 1 + periodSeconds: 10 + exec: + command: + - python3 + - /scripts/health.py + startupProbe: + enabled: true + failureThreshold: 2880 + periodSeconds: 30 + timeoutSeconds: 1 + exec: + command: + - python3 + - /scripts/health.py From 4fdfef0f31e66c2ff3e6ac9fd75a659f3277f09b Mon Sep 17 00:00:00 2001 From: Anton Rubets Date: Mon, 14 Oct 2024 13:27:14 +0300 Subject: [PATCH 2/3] Small fixes --- dysnix/ton/templates/_volumes.tpl | 6 +++--- dysnix/ton/values.yaml | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dysnix/ton/templates/_volumes.tpl b/dysnix/ton/templates/_volumes.tpl index 713c1149..2253d86f 100644 --- a/dysnix/ton/templates/_volumes.tpl +++ b/dysnix/ton/templates/_volumes.tpl @@ -6,10 +6,10 @@ {{- end }} -{{- define "ton.volumesTemplate" }} -{{- with $.Values.persistance }} +{{- define "ton.volumesTemplate" -}} +{{- with $.Values.persistance -}} {{- if (and (hasKey . "data") (not (empty .data))) }} - {{- if eq .data.type "hostPath" }} + {{- if eq .data.type "hostPath" -}} - name: data hostPath: path: {{ required "persistance.data.path required" .data.path }} diff --git a/dysnix/ton/values.yaml b/dysnix/ton/values.yaml index 65106872..90e8c17b 100644 --- a/dysnix/ton/values.yaml +++ b/dysnix/ton/values.yaml @@ -27,7 +27,10 @@ serviceAccount: # -- set persistence info for data and archive persistance: - data: {} + data: + path: /data/chain + type: hostPath + perm: DirectoryOrCreate # type: hostPath | existingClaim | pvc # hostPath: /data/chain # existingClaim: $name @@ -35,7 +38,10 @@ persistance: # accessModes: # - ReadWriteOnce # size: 10Gi - archive: {} + archive: + path: /data/archive + type: hostPath + perm: DirectoryOrCreate # type: hostPath | existingClaim | pvc # hostPath: /data/accounts # existingClaim: $name From 81241b63cadd6dfce7c10c184a5a855da1148f54 Mon Sep 17 00:00:00 2001 From: Anton Rubets Date: Mon, 14 Oct 2024 17:20:40 +0300 Subject: [PATCH 3/3] Fix probes --- dysnix/ton/values.yaml | 58 +++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/dysnix/ton/values.yaml b/dysnix/ton/values.yaml index 90e8c17b..5e5d0421 100644 --- a/dysnix/ton/values.yaml +++ b/dysnix/ton/values.yaml @@ -162,32 +162,32 @@ nodecheck: # -- Api node probes apicheck: - readinessProbe: - enabled: true - timeoutSeconds: 10 - failureThreshold: 2 - successThreshold: 1 - periodSeconds: 10 - exec: - command: - - python3 - - /scripts/health.py - livenessProbe: - enabled: true - timeoutSeconds: 3 - failureThreshold: 2 - successThreshold: 1 - periodSeconds: 10 - exec: - command: - - python3 - - /scripts/health.py - startupProbe: - enabled: true - failureThreshold: 2880 - periodSeconds: 30 - timeoutSeconds: 1 - exec: - command: - - python3 - - /scripts/health.py + readinessProbe: {} + # enabled: true + # timeoutSeconds: 10 + # failureThreshold: 2 + # successThreshold: 1 + # periodSeconds: 10 + # exec: + # command: + # - python3 + # - /scripts/health.py + livenessProbe: {} + # enabled: true + # timeoutSeconds: 3 + # failureThreshold: 2 + # successThreshold: 1 + # periodSeconds: 10 + # exec: + # command: + # - python3 + # - /scripts/health.py + startupProbe: {} + # enabled: true + # failureThreshold: 2880 + # periodSeconds: 30 + # timeoutSeconds: 1 + # exec: + # command: + # - python3 + # - /scripts/health.py