diff --git a/.gitignore b/.gitignore index 7dbf4eb..a791c5a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ dist *.eggs .venv* .DS_Store +.idea .vscode node_modules diff --git a/charts/tezos/templates/_helpers.tpl b/charts/tezos/templates/_helpers.tpl index b7b006a..0505098 100644 --- a/charts/tezos/templates/_helpers.tpl +++ b/charts/tezos/templates/_helpers.tpl @@ -127,21 +127,6 @@ metadata: {{- dict "data" (uniq $allAccounts) | toJson }} {{- end }} -{{/* - Should deploy TZKT indexer? -*/}} -{{- define "tezos.shouldDeployTzktIndexer" -}} - {{- $indexers := .Values.indexers | default dict }} - {{- if $indexers.tzkt }} - {{- $tzkt_config := $indexers.tzkt.config | default dict }} - {{- if $tzkt_config.rpc_url }} - {{- "true" }} - {{- else }} - {{- "" }} - {{- end }} - {{- end }} -{{- end }} - {{/* Checks if `bcdIndexer` has `rpcUrl` and `dbPassword` set. Returns the true type or empty string which is falsey. diff --git a/charts/tezos/templates/static.yaml b/charts/tezos/templates/static.yaml index 33a18ca..895d771 100644 --- a/charts/tezos/templates/static.yaml +++ b/charts/tezos/templates/static.yaml @@ -34,16 +34,3 @@ spec: node_class: {{ $key }} --- {{- end }} -{{- if (include "tezos.shouldDeployTzktIndexer" .) }} -apiVersion: v1 -kind: Service -metadata: - name: {{ .Values.tzkt_indexer_statefulset.name }} - namespace: {{ .Release.Namespace }} -spec: - ports: - - port: 5000 - selector: - app: {{ .Values.tzkt_indexer_statefulset.name }} - type: NodePort -{{- end }} diff --git a/charts/tezos/templates/tzkt_indexer.yaml b/charts/tezos/templates/tzkt_indexer.yaml deleted file mode 100644 index 5b7e93b..0000000 --- a/charts/tezos/templates/tzkt_indexer.yaml +++ /dev/null @@ -1,322 +0,0 @@ -{{- define "tezos.tzkt.setDbConnectionEnvVar" -}} -{{ print " " "server=$(POSTGRES_HOST);port=$(POSTGRES_PORT);database=$(POSTGRES_DB);username=$(POSTGRES_USER);password=$(POSTGRES_PASSWORD);command timeout=$(POSTGRES_COMMAND_TIMEOUT);" }} -{{- end -}} - -{{- if (include "tezos.shouldDeployTzktIndexer" .) }} -{{- $tzkt_indexer := get (.Values.indexers | default dict) "tzkt" }} -{{- $postgres_port := $tzkt_indexer.db.port | default 5432 | quote -}} -{{- $postgres_command_timeout := $tzkt_indexer.db.command_timeout | default 600 | quote -}} -{{- /* - The path of a downloaded snapshot. - The file's name format is "{CHAIN_NAME}-{indexer_image_tag}.backup" -*/}} -{{- /* Extract tzkt version from tzkt image */}} -{{- $indexer_image:= split ":" $tzkt_indexer.images.indexer }} -{{- $snapshot_file := print "/etc/db-snapshot/" $tzkt_indexer.db.name "-" $indexer_image._1 ".backup" }} -{{- /* - A file every pod uses to remember its imported snapshot. - By keeping track, pods won't try to re-upgrade their db on restarts. -*/}} -{{- $MY_IMPORTED_SNAPSHOTS_URL := print "/etc/db-snapshot/my-imported-snapshots-url.txt" }} - -apiVersion: v1 -kind: Secret -metadata: - name: db-creds -data: - POSTGRES_HOST: {{ b64enc ($tzkt_indexer.db.host | default "localhost") }} - POSTGRES_USER: {{ b64enc $tzkt_indexer.db.user }} - POSTGRES_PASSWORD: {{ b64enc $tzkt_indexer.db.password }} - POSTGRES_DB: {{ b64enc $tzkt_indexer.db.name }} - -{{- if and (not $tzkt_indexer.db.isExternal) $tzkt_indexer.db.snapshot_url }} ---- -{{/* -This script is mounted into postgres's /docker-entrypoint-initdb.d directory -where it is run on db initialization. -*/}} -kind: ConfigMap -apiVersion: v1 -metadata: - name: import-db-script - namespace: {{ .Release.Namespace }} -data: - import-db-snapshot.sh: | - #!/bin/bash - set -ex - - # The first execution of this script is on initialization of the db via - # docker-entrypoint-initdb.db. Subsequent times are done on db upgrades. The - # postgres container runs as user 999(postgres) and not root, so it doesn't - # have write access to the indexer-db pv (on AWS). The $MY_IMPORTED_SNAPSHOTS_URL - # file gets owned by the postgres user via the download-db-snapshot - # initContainer, so that this way the postgres user can write the current - # snapshot url to it. - - echo "Importing snapshot $SNAPSHOT_URL" - pg_restore -U "$POSTGRES_USER" \ - -v --no-owner --clean \ - --if-exists --exit-on-error \ - --dbname "$POSTGRES_DB" \ - --single-transaction \ - "$SNAPSHOT_FILE" - - echo "Snapshot imported" - echo "$SNAPSHOT_URL" > "$MY_IMPORTED_SNAPSHOTS_URL" -{{/* -TIP: When developing, you can choose to persist the snapshot file after it's -imported. This will save time as the pod would not have to re-download it. To -enable this, add `keep_snapshot_after_import: true` in the tzkt section of -values.yaml. File name format is "{db_name}-{indexer_image_tag}.backup". -*/}} - {{ if not $tzkt_indexer.keep_snapshot_after_import }} - rm -fv "$SNAPSHOT_FILE" - {{ end }} -{{- end }} - ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: {{ .Values.tzkt_indexer_statefulset.name }} - namespace: {{ .Release.Namespace }} -{{- if $tzkt_indexer.annotations }} - annotations: {{ $tzkt_indexer.annotations | toYaml | nindent 4 }} -{{- end }} -spec: - podManagementPolicy: Parallel - replicas: {{ $tzkt_indexer.replicas }} - selector: - matchLabels: - app: {{ .Values.tzkt_indexer_statefulset.name }} - serviceName: "" - template: - metadata: - labels: - app: {{ .Values.tzkt_indexer_statefulset.name }} - spec: - {{- if and (not $tzkt_indexer.db.isExternal) $tzkt_indexer.db.snapshot_url }} - initContainers: - - image: {{ .Values.tezos_k8s_images.utils }} - name: download-db-snapshot - volumeMounts: - - name: indexer-db - mountPath: /etc/db-snapshot - subPath: db-snapshot - env: - - name: SNAPSHOT_URL - value: {{ $tzkt_indexer.db.snapshot_url }} - - name: SNAPSHOT_FILE - value: {{ $snapshot_file }} - - name: MY_IMPORTED_SNAPSHOTS_URL - value: {{ $MY_IMPORTED_SNAPSHOTS_URL }} - command: ["/bin/sh", "-c"] - args: - - | - set -ex - - if [ ! -f "$MY_IMPORTED_SNAPSHOTS_URL" ]; - then - # Create file to track the current imported db snapshot. Once - # the snapshot is imported we will record its url in this file. - touch "$MY_IMPORTED_SNAPSHOTS_URL" - fi - - imported_snapshot_url=$(cat "$MY_IMPORTED_SNAPSHOTS_URL" || true) - if [ "$imported_snapshot_url" != "$SNAPSHOT_URL" -a ! -f "$SNAPSHOT_FILE" ] - then - echo "Downloading db snapshot from $SNAPSHOT_URL ..." - curl -LfSs -o "$SNAPSHOT_FILE" "$SNAPSHOT_URL" - echo "Successfully downloaded snapshot" - else - echo "Skipping snapshot download" - fi - - # Make 999(postgres) own the directory so that it can record the - # current snapshot url and delete snapshot files. - chown -R 999:999 /etc/db-snapshot - - cat "$MY_IMPORTED_SNAPSHOTS_URL" - - name: upgrade-db - image: "{{ $tzkt_indexer.images.postgres }}" - volumeMounts: - - name: indexer-db - mountPath: /var/lib/postgresql/data - subPath: data - - name: indexer-db - mountPath: /etc/db-snapshot - subPath: db-snapshot - - name: import-db-script - mountPath: /etc/import-script - env: - {{- /* https://github.com/docker-library/docs/blob/master/postgres/README.md#pgdata */}} - - name: PGDATA - value: /var/lib/postgresql/data/pgdata - - name: SNAPSHOT_URL - value: {{ $tzkt_indexer.db.snapshot_url }} - - name: SNAPSHOT_FILE - value: {{ $snapshot_file }} - - name: MY_IMPORTED_SNAPSHOTS_URL - value: {{ $MY_IMPORTED_SNAPSHOTS_URL }} - envFrom: - - secretRef: - name: db-creds - securityContext: - {{/* Run as user 999(postgres) */}} - runAsUser: 999 - command: ["/bin/sh", "-c"] - args: - - | - set -x - - if [ ! -d "$PGDATA" ]; then - echo "No db exists to upgrade. Exiting." - exit 0 - fi - - if [ -f "$MY_IMPORTED_SNAPSHOTS_URL" ]; then - current_imported_snapshot=$(cat "$MY_IMPORTED_SNAPSHOTS_URL") - if [ "$current_imported_snapshot" = "$SNAPSHOT_URL" ]; then - echo "Already imported $current_imported_snapshot. Exiting." - exit 0 - fi - fi - - pg_ctl start - - # Drop the db. There are certain db objects that pg_restore - # cannot cascade delete. So wipe the whole db. - dropdb -U "$POSTGRES_USER" --if-exists "$POSTGRES_DB" - # Recreate the db - createdb -U "$POSTGRES_USER" "$POSTGRES_DB" - /etc/import-script/import-db-snapshot.sh - import_exit_code="$?" - - pg_ctl stop - [ "$import_exit_code" != 0 ] && exit 1 || exit 0 - {{- end }} - containers: - - image: {{ .Values.tezos_k8s_images.utils }} - name: readiness - command: ["/bin/sh", "-c"] - args: - - | - while : - do - [ "$(curl -s http://localhost:5000/v1/head | jq '.synced')" = true ] \ - && { touch /tmp/synced; echo "Synced"; } \ - || { echo "Indexer syncing..."; rm -f /tmp/synced; } - sleep 8s - done - readinessProbe: - {{- /* - initialDelaySeconds gives indexer time to boot up and grab chain data - before starting the probe. Also some blocks can take longer than others - to sync, such as when fetching baking/endorsing rights for a cycle. - So we set failureThreshold to 3. Tzkt has a bug where occasionally the - indexer sync status returns a false positive. Usually when the container - just starts. We set the successThreshold at 2 so we are more likely to - know if the indexer is actually synced. - */}} - initialDelaySeconds: 30 - periodSeconds: 10 - timeoutSeconds: 5 - failureThreshold: 3 - successThreshold: 2 - exec: - command: ["cat", "/tmp/synced"] - - image: "{{ $tzkt_indexer.images.api }}" - name: api - ports: - - containerPort: 5000 - env: - - name: Logging__LogLevel__Default - value: {{ $tzkt_indexer.config.api_log_level }} - - name: POSTGRES_PORT - value: {{ $postgres_port }} - - name: POSTGRES_COMMAND_TIMEOUT - value: {{ $postgres_command_timeout }} - - name: ConnectionStrings__DefaultConnection - value: {{- include "tezos.tzkt.setDbConnectionEnvVar" . }} - {{- /* https://github.com/baking-bad/tzkt/blob/198e3879d4/docker-compose.yml#L26 */}} - - name: TZKT_API_KESTREL__ENDPOINTS__HTTP__URL - value: "http://0.0.0.0:5000" - envFrom: - - secretRef: - name: db-creds - - image: "{{ $tzkt_indexer.images.indexer }}" - name: indexer - volumeMounts: - - name: tzkt-env - mountPath: /etc/tzkt - env: - - name: TezosNode__Endpoint - value: {{ $tzkt_indexer.config.rpc_url }} - - name: Logging__LogLevel__Default - value: {{ $tzkt_indexer.config.indexer_log_level }} - - name: POSTGRES_PORT - value: {{ $postgres_port }} - - name: POSTGRES_COMMAND_TIMEOUT - value: {{ $postgres_command_timeout }} - - name: ConnectionStrings__DefaultConnection - value: {{- include "tezos.tzkt.setDbConnectionEnvVar" . }} - envFrom: - - secretRef: - name: db-creds - {{- if not $tzkt_indexer.db.isExternal }} - - image: {{ $tzkt_indexer.images.postgres }} - name: db - imagePullPolicy: IfNotPresent - ports: - - containerPort: 5432 - volumeMounts: - - name: indexer-db - mountPath: /var/lib/postgresql/data - subPath: data - {{- if $tzkt_indexer.db.snapshot_url }} - - name: indexer-db - mountPath: /etc/db-snapshot - subPath: db-snapshot - {{- /* Postgres on db initialization runs import-db-snapshot.sh */}} - - name: import-db-script - mountPath: /docker-entrypoint-initdb.d - {{- end }} - env: - {{- /* https://github.com/docker-library/docs/blob/master/postgres/README.md#pgdata */}} - - name: PGDATA - value: /var/lib/postgresql/data/pgdata - {{- if $tzkt_indexer.db.snapshot_url }} - - name: SNAPSHOT_URL - value: {{ $tzkt_indexer.db.snapshot_url }} - - name: SNAPSHOT_FILE - value: {{ $snapshot_file }} - - name: MY_IMPORTED_SNAPSHOTS_URL - value: {{ $MY_IMPORTED_SNAPSHOTS_URL }} - {{- end }} - envFrom: - - secretRef: - name: db-creds - {{- end }} - volumes: - - name: tzkt-env - emptyDir: {} - {{- if not $tzkt_indexer.db.isExternal }} - - name: import-db-script - configMap: - name: import-db-script - {{- /* Execute permissions */}} - defaultMode: 111 - {{- end }} - {{- if not $tzkt_indexer.db.isExternal }} - volumeClaimTemplates: - - metadata: - name: indexer-db - spec: - accessModes: - - ReadWriteOnce - storageClassName: {{ $tzkt_indexer.storageClassName }} - resources: - requests: - storage: {{ required "DB storage size must be specified" $tzkt_indexer.storage }} - {{- end }} -{{- end }} diff --git a/charts/tezos/values.yaml b/charts/tezos/values.yaml index 1a363aa..e5f4fd4 100644 --- a/charts/tezos/values.yaml +++ b/charts/tezos/values.yaml @@ -630,57 +630,6 @@ protocols: # kernel: "" # parameters_ty: # prim: unit -# -## Deploy an indexer with the chain. An indexer puts the chain -## contents in a database for efficient indexing. Most dapps need it. -## Supported indexers: -## * tzkt: https://github.com/baking-bad/tzkt -## * bcd: https://github.com/baking-bad/bcdhub -## Templatized indexer configuration values go in the config field. -## -# indexers: -# tzkt: -# images: -# api: "bakingbad/tzkt-api:1.12.0" -# indexer: "bakingbad/tzkt-sync:1.12.0" -# postgres: "postgres:13" -# -# ## Database volumeClaimTemplates config -# storageClassName: "" -# storage: "100Gi" -# ## Statefulset annotations -# # annotations: -# -# ## Indexer replicas -# replicas: 1 -# -# db: -# # By default creates a postgres db container. Setting to true won't create -# # it and instead expects credentials for an external postgres database. -# isExternal: false -# ## Tzkt provides new snapshots as they update their code. Update your -# ## indexers by specifying new docker image tags and by using the matching -# ## snapshot_url. Spin up an additional replica if you only have one to -# ## avoid downtime. See tzkt's readme for public networks' db snapshot urls. -# ## If you want to index a brand new archive node you are spinning up, just -# ## let the indexer start syncing with it from scratch. -# ## https://github.com/baking-bad/tzkt -# snapshot_url: https://snapshots.tzkt.io/tzkt_v1.12_mainnet.backup -# host: localhost -# port: 5432 -# name: db -# user: foo -# password: bar -# command_timeout: 600 -# -# ## Configurable tzkt fields -# config: -# ## RPC url of the node to index. A rolling node is sufficient if the -# ## indexer is bootstrapped from the most recent snapshot. Otherwise an -# ## archive node is needed. -# rpc_url: http://rolling-node-0.rolling-node:8732 -# # api_log_level: Debug -# # indexer_log_level: Debug ## Set values `indexerRpcUrl` and `db.password` for an indexer to be created. bcdIndexer: diff --git a/charts/tzkt/.helmignore b/charts/tzkt/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/tzkt/.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/charts/tzkt/Chart.yaml b/charts/tzkt/Chart.yaml new file mode 100644 index 0000000..127e471 --- /dev/null +++ b/charts/tzkt/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: tzkt +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: 1.13.2 diff --git a/charts/tzkt/templates/NOTES.txt b/charts/tzkt/templates/NOTES.txt new file mode 100644 index 0000000..e69de29 diff --git a/charts/tzkt/templates/_helpers.tpl b/charts/tzkt/templates/_helpers.tpl new file mode 100644 index 0000000..5e5b70f --- /dev/null +++ b/charts/tzkt/templates/_helpers.tpl @@ -0,0 +1,72 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "tzkt.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 "tzkt.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 "tzkt.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "tzkt.labels" -}} +helm.sh/chart: {{ include "tzkt.chart" . }} +{{ include "tzkt.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "tzkt.selectorLabels" -}} +app.kubernetes.io/name: {{ include "tzkt.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "tzkt.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "tzkt.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{/* tzkt db connection string */}} +{{- define "tzkt.connectionString" -}} +{{printf "server=$(POSTGRES_HOST);port=$(POSTGRES_PORT);database=$(POSTGRES_DB);username=$(POSTGRES_USER);password=$(POSTGRES_PASSWORD);command timeout=$(POSTGRES_COMMAND_TIMEOUT);" }} +{{- end -}} + +{{/* tzkt api httl url */}} +{{- define "tzkt.apiUrl" -}} +{{ print "http://0.0.0.0:" .Values.api.port }} +{{- end -}} diff --git a/charts/tzkt/templates/configmap.yaml b/charts/tzkt/templates/configmap.yaml new file mode 100644 index 0000000..35c0d98 --- /dev/null +++ b/charts/tzkt/templates/configmap.yaml @@ -0,0 +1,36 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "tzkt.fullname" . }}-db + labels: + {{- include "tzkt.labels" . | nindent 4 }} +data: + POSTGRES_HOST: "{{ .Values.externalDatabase.host }}" + POSTGRES_PORT: "{{ .Values.externalDatabase.port }}" + POSTGRES_USER: "{{ .Values.externalDatabase.user }}" + POSTGRES_DB: "{{ .Values.externalDatabase.database }}" + POSTGRES_COMMAND_TIMEOUT: "{{ .Values.externalDatabase.commandTimeout }}" +{{- if .Values.api.appSettings }} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "tzkt.fullname" . }}-api-appsettings + labels: + {{- include "tzkt.labels" . | nindent 4 }} +data: + appsettings.json: |- + {{ .Values.api.appSettings | nindent 4 }} +{{- end }} +{{- if .Values.sync.appSettings }} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "tzkt.fullname" . }}-sync-appsettings + labels: + {{- include "tzkt.labels" . | nindent 4 }} +data: + appsettings.json: |- + {{ .Values.sync.appSettings | nindent 4 }} +{{- end }} diff --git a/charts/tzkt/templates/secret.yaml b/charts/tzkt/templates/secret.yaml new file mode 100644 index 0000000..da7aac0 --- /dev/null +++ b/charts/tzkt/templates/secret.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "tzkt.fullname" . }}-db-creds + labels: + {{- include "tzkt.labels" . | nindent 4 }} +data: + POSTGRES_PASSWORD: {{ b64enc .Values.externalDatabase.password }} diff --git a/charts/tzkt/templates/service.yaml b/charts/tzkt/templates/service.yaml new file mode 100644 index 0000000..a657433 --- /dev/null +++ b/charts/tzkt/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "tzkt.fullname" . }} + labels: + {{- include "tzkt.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "tzkt.selectorLabels" . | nindent 4 }} diff --git a/charts/tzkt/templates/statefulset.yaml b/charts/tzkt/templates/statefulset.yaml new file mode 100644 index 0000000..7272105 --- /dev/null +++ b/charts/tzkt/templates/statefulset.yaml @@ -0,0 +1,112 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "tzkt.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "tzkt.labels" . | nindent 4 }} + annotations: + {{- toYaml .Values.annotations | nindent 4 }} +spec: + podManagementPolicy: Parallel + replicas: 1 + selector: + matchLabels: + {{- include "tzkt.selectorLabels" . | nindent 6 }} + serviceName: "" + template: + metadata: + labels: + {{- include "tzkt.selectorLabels" . | nindent 8 }} + spec: + containers: + - image: {{ .Values.tezos_k8s_images.utils }} + name: readiness + command: ["/bin/sh", "-c"] + args: + - | + while : + do + [ "$(curl -s http://localhost:5000/v1/head | jq '.synced')" = true ] \ + && { touch /tmp/synced; echo "Synced"; } \ + || { echo "Indexer syncing..."; rm -f /tmp/synced; } + sleep 8s + done + {{- /* + initialDelaySeconds gives indexer time to boot up and grab chain data + before starting the probe. Also some blocks can take longer than others + to sync, such as when fetching baking/endorsing rights for a cycle. + So we set failureThreshold to 3. Tzkt has a bug where occasionally the + indexer sync status returns a false positive. Usually when the container + just starts. We set the successThreshold at 2 so we are more likely to + know if the indexer is actually synced. + */}} + readinessProbe: + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + failureThreshold: 3 + successThreshold: 2 + exec: + command: ["cat", "/tmp/synced"] + - name: api + image: {{ .Values.api.image.repository }}:{{ .Values.api.image.tag }} + imagePullPolicy: "{{ .Values.api.image.pullPolicy }}" + ports: + - containerPort: {{ .Values.api.port }} + name: http + protocol: TCP + {{- if .Values.api.appSettings }} + volumeMounts: + - mountPath: /app/appsettings.json + name: {{ include "tzkt.fullname" . }}-api-appsettings + subPath: appsettings.json + {{- end }} + env: + - name: Logging__LogLevel__Default + value: "{{ .Values.api.logLevel }}" + - name: ConnectionStrings__DefaultConnection + value: "{{- include "tzkt.connectionString" . }}" + - name: TZKT_API_KESTREL__ENDPOINTS__HTTP__URL + value: "{{- include "tzkt.apiUrl" . }}" + envFrom: + - configMapRef: + name: {{ include "tzkt.fullname" . }}-db + - secretRef: + name: {{ include "tzkt.fullname" . }}-db-creds + - name: indexer + image: {{ .Values.sync.image.repository }}:{{ .Values.sync.image.tag}} + imagePullPolicy: "{{ .Values.sync.image.pullPolicy }}" + volumeMounts: + - name: tzkt-env + mountPath: /etc/tzkt + {{- if .Values.sync.appSettings }} + - mountPath: /app/appsettings.json + name: {{ include "tzkt.fullname" . }}-sync-appsettings + subPath: appsettings.json + {{- end }} + env: + - name: Logging__LogLevel__Default + value: "{{ .Values.sync.logLevel }}" + - name: TezosNode__Endpoint + value: "{{ .Values.sync.tezosNodeEndpoint }}" + - name: ConnectionStrings__DefaultConnection + value: "{{- include "tzkt.connectionString" . }}" + envFrom: + - configMapRef: + name: {{ include "tzkt.fullname" . }}-db + - secretRef: + name: {{ include "tzkt.fullname" . }}-db-creds + volumes: + - name: tzkt-env + emptyDir: {} + {{- if .Values.api.appSettings }} + - configMap: + name: {{ include "tzkt.fullname" . }}-api-appsettings + name: {{ include "tzkt.fullname" . }}-api-appsettings + {{- end }} + {{- if .Values.sync.appSettings }} + - configMap: + name: {{ include "tzkt.fullname" . }}-sync-appsettings + name: {{ include "tzkt.fullname" . }}-sync-appsettings + {{- end }} diff --git a/charts/tzkt/values.yaml b/charts/tzkt/values.yaml new file mode 100644 index 0000000..2ec2369 --- /dev/null +++ b/charts/tzkt/values.yaml @@ -0,0 +1,117 @@ +# Default values for tzkt. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +tezos_k8s_images: + utils: ghcr.io/tacoinfra/tezos-k8s-utils:main + +## @section tzkt api configuration +## +api: + ## tzkt api image parameters + image: + repository: bakingbad/tzkt-api + tag: 1.13.2 + ## Specify a imagePullPolicy + ## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' + ## ref: http://kubernetes.io/docs/concepts/containers/images/#pre-pulled-images + ## + pullPolicy: IfNotPresent + ## Optionally specify an array of imagePullSecrets. + ## Secrets must be manually created in the namespace. + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## e.g: + ## pullSecrets: + ## - myRegistryKeySecretName + ## + pullSecrets: [] + ## @param port for tzkt api service + port: 5000 + ## @param log level for tzkt api + logLevel: Information + ## @param appSettings Custom appSettings to run api, + ## e.g: + ## appSettings: | + ## { + ## "Cache": { + ## "LoadRate": 0.75, + ## "MaxAccounts": 32000 + ## }, + ## .... + ## "ResponseCache": { + ## "CacheSize": 256 + ## }, + ## .... + ## } + appSettings: {} + +## @section tzkt sync configuration +## +sync: + ## tzkt sync image parameters + image: + repository: bakingbad/tzkt-sync + tag: 1.13.2 + ## Specify a imagePullPolicy + ## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' + ## ref: http://kubernetes.io/docs/concepts/containers/images/#pre-pulled-images + ## + pullPolicy: IfNotPresent + ## Optionally specify an array of imagePullSecrets. + ## Secrets must be manually created in the namespace. + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## e.g: + ## pullSecrets: + ## - myRegistryKeySecretName + ## + pullSecrets: [] + ## @param tezos endpoint to point for indexing, + tezosNodeEndpoint: 'https://rpc.tzkt.io/mainnet/' + ## @param log level for tzkt sync + logLevel: Information + ## @param appSettings Custom appSettings to run api, + ## e.g: + ## appSettings: | + ## { + ## "Protocols": { + ## "Diagnostics": false, + ## "Validation": true, + ## "Fallback": null + ## }, + ## "TezosNode": { + ## "Endpoint": "https://rpc.tzkt.io/mainnet/", + ## "Timeout": 60 + ## }, + ## "Quotes": { + ## "Async": true, + ## "Provider": { + ## "Name": "TzktQuotes" + ## } + ## }, + ## .... + ## } + appSettings: {} + +service: + type: ClusterIP + port: 5000 + +## External Database Configuration +## +externalDatabase: + ## @param externalDatabase.host External Database server host + ## + host: localhost + ## @param externalDatabase.port External Database server port + ## + port: 5432 + ## @param externalDatabase.user External Database username + ## + user: "tzkt" + ## @param externalDatabase.password External Database user password + ## + password: "" + ## @param externalDatabase.database External Database database name + ## + database: "tzkt_db" + ## @param externalDatabase.commandTimeout Timeout of the DB command + commandTimeout: "600"