Skip to content

Commit

Permalink
Initial setup to take out tzkt from tezos chart
Browse files Browse the repository at this point in the history
  • Loading branch information
puppetninja committed Mar 7, 2024
1 parent 0ef7bac commit 81feb6d
Show file tree
Hide file tree
Showing 13 changed files with 398 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dist
*.eggs
.venv*
.DS_Store
.idea
.vscode
node_modules

Expand Down
23 changes: 23 additions & 0 deletions charts/tzkt/.helmignore
Original file line number Diff line number Diff line change
@@ -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/
24 changes: 24 additions & 0 deletions charts/tzkt/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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: "v1.13.2"
Empty file added charts/tzkt/templates/NOTES.txt
Empty file.
72 changes: 72 additions & 0 deletions charts/tzkt/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -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" -}}
{{ print " " "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:%s" .Values.api.port }}
{{- end -}}
11 changes: 11 additions & 0 deletions charts/tzkt/templates/configmap-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- if .Values.api.appSettings }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "tzkt.fullname" . }}-api-app
labels:
{{- include "tzkt.labels" . | nindent 4 }}
data:
appsettings.json: |-
{{ .Values.api.appSettings | nindent 4 }}
{{- end }}
11 changes: 11 additions & 0 deletions charts/tzkt/templates/configmap-sync.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- if .Values.sync.appSettings }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "tzkt.fullname" . }}-sync-app
labels:
{{- include "tzkt.labels" . | nindent 4 }}
data:
appsettings.json: |-
{{ .Values.sync.appSettings | nindent 4 }}
{{- end }}
12 changes: 12 additions & 0 deletions charts/tzkt/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ include "tzkt.fullname" . }}-db-creds
labels:
{{- include "tzkt.labels" . | nindent 4 }}
data:
POSTGRES_HOST: {{ b64enc .Values.externalDatabase.host }}
POSTGRES_USER: {{ b64enc .Values.externalDatabase.user }}
POSTGRES_PASSWORD: {{ b64enc .Values.externalDatabase.password }}
POSTGRES_DB: {{ b64enc .Values.externalDatabase.database }}
POSTGRES_COMMAND_TIMEOUT: {{ b64enc .Values.externalDatabase.commandTimeout }}
15 changes: 15 additions & 0 deletions charts/tzkt/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
12 changes: 12 additions & 0 deletions charts/tzkt/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "tzkt.serviceAccountName" . }}
labels:
{{- include "tzkt.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
85 changes: 85 additions & 0 deletions charts/tzkt/templates/statefulset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
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 }}
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:
- 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
env:
- name: Logging__LogLevel__Default
value: {{ .Values.sync.logLevel }}
- name: TezosNode__Endpoint
value: {{ .Values.sync.tezosNodeEndpoint }}
- name: ConnectionStrings__DefaultConnection
value: {{- include "tzkt.connectionString" . }}
envFrom:
- secretRef:
name: {{ include "tzkt.fullname" . }}-db-creds
volumes:
- name: tzkt-env
emptyDir: {}
15 changes: 15 additions & 0 deletions charts/tzkt/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "tzkt.fullname" . }}-test-connection"
labels:
{{- include "tzkt.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "tzkt.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
Loading

0 comments on commit 81feb6d

Please sign in to comment.