Split Tornjak Frontend into separate subchart (#179)

Signed-off-by: Mariusz Sabath <[email protected]>
Signed-off-by: Marco Franssen <[email protected]>
Co-authored-by: Marco Franssen <[email protected]>
This commit is contained in:
Mariusz Sabath
2023-05-16 19:31:38 +02:00
committed by Marco Franssen
co-authored by Marco Franssen
parent 6d221263fb
commit da186c5f53
21 changed files with 478 additions and 95 deletions
@@ -0,0 +1,25 @@
Installed {{ .Chart.Name }}…
Name: {{ include "tornjak-frontend.name" . }}
Fullname: {{ include "tornjak-frontend.fullname" . }}
Your release is named: {{ .Release.Name }}
Namespace: {{ include "tornjak-frontend.namespace" . }}
Tornjak UI (Frontend)
image: {{ template "tornjak-frontend.image" (dict "appVersion" $.Chart.AppVersion "image" .Values.image) }}
pull policy: {{ .Values.image.pullPolicy }}
Configured with Tornjak API (Backend): {{ include "tornjak-frontend.apiURL" . }}
### WARNING ###
This Tornjak is configured without authentication and it is intended for
testing only. Please do not use this version in production.
You can use port forwarding to access UI:
kubectl -n {{ include "tornjak-frontend.namespace" . }} port-forward service/{{ include "tornjak-frontend.fullname" . }} {{ .Values.service.port }}:3000
Open browser to: http://localhost:{{ .Values.service.port }}
To learn more about the release, try:
$ helm status {{ .Release.Name }}
$ helm get all {{ .Release.Name }}
@@ -0,0 +1,109 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "tornjak-frontend.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 "tornjak-frontend.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 }}
{{/*
Allow the release namespace to be overridden for multi-namespace deployments in combined charts
*/}}
{{- define "tornjak-frontend.namespace" -}}
{{- if .Values.namespaceOverride -}}
{{- .Values.namespaceOverride -}}
{{- else -}}
{{- .Release.Namespace -}}
{{- end -}}
{{- end -}}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "tornjak-frontend.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- define "tornjak-frontend.cluster-domain" -}}
{{- if ne (len (dig "k8s" "clusterDomain" "" .Values.global)) 0 }}
{{- .Values.global.k8s.clusterDomain }}
{{- else }}
{{- .Values.clusterDomain }}
{{- end }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "tornjak-frontend.labels" -}}
helm.sh/chart: {{ include "tornjak-frontend.chart" . }}
{{ include "tornjak-frontend.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "tornjak-frontend.selectorLabels" -}}
app.kubernetes.io/name: {{ include "tornjak-frontend.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "tornjak-frontend.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "tornjak-frontend.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
{{/*
Create an image name
*/}}
{{- define "tornjak-frontend.image" -}}
{{- if eq (substr 0 7 .image.version) "sha256:" -}}
{{- printf "%s/%s@%s" .image.registry .image.repository .image.version -}}
{{- else if .appVersion -}}
{{- printf "%s/%s:%s" .image.registry .image.repository (default .appVersion .image.version) -}}
{{- else if
.Values.tornjakFrontend.image.version -}}
{{- printf "%s/%s:%s" .Values.tornjakFrontend.image.registry .Values.tornjakFrontend.image.repository .Values.tornjakFrontend.image.version -}}
{{- else -}}
{{- printf "%s/%s" .Values.tornjakFrontend.image.registry .Values.tornjakFrontend.image.repository -}}
{{- end -}}
{{- end }}
{{/*
Create URL for accessing Tornjak APIs
*/}}
{{- define "tornjak-frontend.apiURL" -}}
{{- if .Values.apiServerURL -}}
{{- .Values.apiServerURL -}}
{{- else }}
{{- $feurl := print "http://localhost:" .Values.service.port }}
{{- $feurl }}
{{- end }}
{{- end }}
@@ -0,0 +1,46 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "tornjak-frontend.fullname" . }}
namespace: {{ include "tornjak-frontend.namespace" . }}
labels:
{{- include "tornjak-frontend.labels" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels:
{{- include "tornjak-frontend.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "tornjak-frontend.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "tornjak-frontend.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ include "tornjak-frontend.fullname" . }}
image: {{ template "tornjak-frontend.image" (dict "appVersion" $.Chart.AppVersion "image" .Values.image) }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
ports:
- name: http
containerPort: 3000
protocol: TCP
env:
- name: REACT_APP_API_SERVER_URI
value: {{ include "tornjak-frontend.apiURL" . }}
startupProbe:
httpGet:
scheme: HTTP
port: {{ .Values.service.port }}
failureThreshold: 6
initialDelaySeconds: 60
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 10
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
namespace: {{ include "tornjak-frontend.namespace" . }}
name: {{ include "tornjak-frontend.fullname" . }}
{{- with .Values.service.annotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "tornjak-frontend.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
selector:
{{- include "tornjak-frontend.selectorLabels" . | nindent 4 }}
ports:
- name: {{ include "tornjak-frontend.fullname" . }}
port: {{ .Values.service.port }}
targetPort: http
@@ -0,0 +1,13 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "tornjak-frontend.serviceAccountName" . }}
namespace: {{ include "tornjak-frontend.namespace" . }}
labels:
{{- include "tornjak-frontend.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
@@ -0,0 +1,21 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "tornjak-frontend.fullname" . }}-test-connection"
namespace: {{ include "tornjak-frontend.namespace" . }}
labels:
{{- include "tornjak-frontend.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
spec:
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 4 }}
containers:
- name: curl-tornjak-frontend
image: cgr.dev/chainguard/bash:latest
command: ['curl']
args: ['-k', '-s', '-f', 'http://{{ include "tornjak-frontend.fullname" . }}.{{ include "tornjak-frontend.namespace" . }}.svc.{{ include "tornjak-frontend.cluster-domain" . }}:{{ .Values.service.port }}']
securityContext:
{{- toYaml .Values.securityContext | nindent 8 }}
restartPolicy: Never