Skip to content

Commit

Permalink
[T-14416]: portal typescript chart (#61)
Browse files Browse the repository at this point in the history
* [T-14416]: fleshing out initial helm chart for portal

* [T-144616]: add env file config

* [T-14416]: some minor tweaks

* [T-14416]: reference central dockerhub image

* [T-14416]: more tweaks to chart with ext secrets config

* [T-14416]: fix chart-test helm repos for influxdb2

* [T-14416]: default values

* [T-14416]: more tweaks to get the base chart passing

* [T-14416]: disable redis and influx and mongo default

* fix chart deps

* fix linting issues

* get default vars working

* adds in mongodb, influx and redis

* change influx subchart params to work correctly

* updated chart lockfile

* adds pre-commit

* remove yammlint from precommit for now

closes T-14416
  • Loading branch information
Wesley Charles Blake authored Nov 3, 2022
1 parent 7935f6d commit 78eeec2
Show file tree
Hide file tree
Showing 18 changed files with 685 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
docker-secret.yaml
.idea
.DS_Store
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
# - id: check-yaml
- id: check-added-large-files
23 changes: 23 additions & 0 deletions charts/pokt-portal/.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/
12 changes: 12 additions & 0 deletions charts/pokt-portal/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
dependencies:
- name: redis
repository: https://charts.bitnami.com/bitnami
version: 17.3.7
- name: influxdb2
repository: https://helm.influxdata.com/
version: 2.1.1
- name: mongodb
repository: https://charts.bitnami.com/bitnami
version: 13.3.0
digest: sha256:645a760a28f1fda2b3e7903022b77f115053ba78101b8ec785ff14d02a2d2aa5
generated: "2022-11-02T19:46:44.046796+02:00"
59 changes: 59 additions & 0 deletions charts/pokt-portal/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
apiVersion: v2
name: pokt-portal
description: A Helm chart for deploying the POKT Portal API services
maintainers:
- name: WesleyCharlesBlake
url: https://github.com/WesleyCharlesBlake/
- name: pokt-foundation
url: https://github.com/pokt-foundation/charts

# 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: "0.0.1"

dependencies:
- name: redis
version: "17.3.7"
repository: "https://charts.bitnami.com/bitnami"
condition: redis.enabled
- name: influxdb2
version: "2.1.1"
repository: "https://helm.influxdata.com/"
condition: influxdb2.enabled
- name: mongodb
version: "13.3.0"
repository: "https://charts.bitnami.com/bitnami"
condition: mongodb.enabled
# - name: pokt-relay-meter
# version: "0.0.1"
# repository: "https://pokt-foundation.github.io/charts"
# condition: relayMeter.enabled
# - name: pokt-rate-limiter
# version: "0.0.1"
# repository: "https://pokt-foundation.github.io/charts"
# condition: rateLimiter.enabled
# - name: pokt-portal-workers
# version: "0.0.1"
# repository: "https://pokt-foundation.github.io/charts"
# condition: workers.enabled
# - name: pokt-go-mev-proxy
# version: "0.0.1"
# repository: "https://pokt-foundation.github.io/charts"
# condition: goMevProxy.enabled
22 changes: 22 additions & 0 deletions charts/pokt-portal/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -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 "pokt-portal.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 "pokt-portal.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "pokt-portal.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 "pokt-portal.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 }}
82 changes: 82 additions & 0 deletions charts/pokt-portal/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "pokt-portal.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 "pokt-portal.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 "pokt-portal.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

{{/*
Selector labels
*/}}
{{- define "pokt-portal.selectorLabels" -}}
app.kubernetes.io/name: {{ include "pokt-portal.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

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

{{/*
Create env vars from a values.env
*/}}


{{- define "helpers.list-env-variables"}}
{{- $secretName := printf "%s-vars" .Release.Name -}}
{{- range $key, $val := .Values.env.secret }}
- name: {{ $key }}
valueFrom:
secretKeyRef:
name: {{ $secretName }}
key: {{ $key }}
{{- end}}
{{- range $key, $val := .Values.env.normal }}
- name: {{ $key }}
value: {{ $val | quote }}
{{- end}}
{{- end }}
74 changes: 74 additions & 0 deletions charts/pokt-portal/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "pokt-portal.fullname" . }}
labels:
{{- include "pokt-portal.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "pokt-portal.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "pokt-portal.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "pokt-portal.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: ["npm", "run", "start"]
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
{{- if .Values.probes.enabled }}
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
{{- end }}
env:
{{- if not .Values.externalSecrets.enabled }}
{{- include "helpers.list-env-variables" . | indent 12 }}
{{- end }}
{{- if .Values.externalSecrets.enabled }}
envFrom:
- secretRef:
name: {{ include "pokt-portal.fullname" . }}-es
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
19 changes: 19 additions & 0 deletions charts/pokt-portal/templates/external-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- if .Values.externalSecrets.enabled -}}
kind: ExternalSecret
apiVersion: external-secrets.io/v1beta1
metadata:
name: {{ include "pokt-portal.fullname" . }}
spec:
refreshInterval: "60s"
secretStoreRef:
name: {{ include "pokt-portal.fullname" . }}-ss
kind: SecretStore
target:
name: {{ include "pokt-portal.fullname" . }}-es
deletionPolicy: "Delete"

dataFrom:
- extract:
key: {{ .Values.externalSecrets.key}}
decodingStrategy: Auto
{{- end -}}
28 changes: 28 additions & 0 deletions charts/pokt-portal/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "pokt-portal.fullname" . }}
labels:
{{- include "pokt-portal.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "pokt-portal.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
Loading

0 comments on commit 78eeec2

Please sign in to comment.