Skip to content

Commit

Permalink
add knowledge chart
Browse files Browse the repository at this point in the history
  • Loading branch information
ddecrulle committed Dec 4, 2023
1 parent 04e5565 commit ca1e79c
Show file tree
Hide file tree
Showing 19 changed files with 818 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/knowledge/.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/
13 changes: 13 additions & 0 deletions charts/knowledge/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v2
name: knowledge
description: A Helm chart for Knowledge API, UI and DB

dependencies:
- name: mongodb
condition: mongodb.enabled
version: 13.15.3
repository: https://charts.bitnami.com/bitnami

type: application
version: 0.5.1
appVersion: "1.16.0"
1 change: 1 addition & 0 deletions charts/knowledge/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO
143 changes: 143 additions & 0 deletions charts/knowledge/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{{/*
Expand the name of the chart.
*/}}


{{- define "knowledge.api.name" -}}
{{- .Values.api.nameOverride | default (printf "%s-api" .Chart.Name ) }}
{{- end }}

{{- define "knowledge.ui.name" -}}
{{- .Values.ui.nameOverride | default (printf "%s-ui" .Chart.Name ) }}
{{- 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 "knowledge.api.fullname" -}}
{{- if .Values.api.fullnameOverride }}
{{- .Values.api.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default (printf "%s-api" .Chart.Name ) .Values.api.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{- define "knowledge.ui.fullname" -}}
{{- if .Values.ui.fullnameOverride }}
{{- .Values.ui.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default (printf "%s-ui" .Chart.Name ) .Values.ui.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}


{{- define "knowledge.mongodb.fullname" -}}
{{- if .Values.mongodb.fullnameOverride -}}
{{- .Values.mongodb.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.mongodb.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 "knowledge.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{- define "knowledge.api.chart" -}}
{{- printf "knowledge-api" -}}
{{- end -}}

{{- define "knowledge.ui.chart" -}}
{{- printf "knowledge-ui" -}}
{{- end -}}

{{/*
Common labels
*/}}

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

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

{{/*
Selector labels
*/}}

{{- define "knowledge.api.selectorLabels" -}}
app.kubernetes.io/name: {{ include "knowledge.api.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{- define "knowledge.ui.selectorLabels" -}}
app.kubernetes.io/name: {{ include "knowledge.ui.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}


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

{{- define "knowledge.ui.serviceAccountName" -}}
{{- if .Values.ui.serviceAccount.create }}
{{- default (include "knowledge.ui.fullname" .) .Values.ui.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.ui.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Create list of mongo host
*/}}
{{- define "mongoList" -}}
{{- $replicaCount := int .Values.mongodb.replicaCount }}
{{- $portNumber := int .Values.mongodb.service.ports.mongodb }}
{{- $fullname := include "knowledge.mongodb.fullname" . }}
{{- $mongoList := list }}
{{- range $e, $i := until $replicaCount }}
{{- $mongoList = append $mongoList (printf "%s-%d.%s-headless:%d" $fullname $i $fullname $portNumber) }}
{{- end }}
{{- printf "%s" (join "," $mongoList) -}}
{{- end }}
17 changes: 17 additions & 0 deletions charts/knowledge/templates/api/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if .Values.api.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "knowledge.api.fullname" . }}
labels:
app: {{ template "knowledge.api.name" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
{{- if .Values.api.env }}
{{- range $key, $value := .Values.api.env }}
{{ $key }}: {{ $value | quote }}
{{- end -}}
{{- end -}}
{{- end -}}
87 changes: 87 additions & 0 deletions charts/knowledge/templates/api/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{{- if .Values.api.enabled -}}
{{- $mongodbFullname := include "knowledge.mongodb.fullname" . }}
{{- $secretName := printf "%s-discovery" $mongodbFullname -}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "knowledge.api.fullname" . }}
labels:
{{- include "knowledge.api.labels" . | nindent 4 }}
spec:
{{- if not .Values.api.autoscaling.enabled }}
replicas: {{ .Values.api.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "knowledge.api.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
checksum/config: {{ include (print $.Template.BasePath "/api/configmap.yaml") . | sha256sum }}
labels:
{{- include "knowledge.api.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.api.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "knowledge.api.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.api.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.api.securityContext | nindent 12 }}
image: "{{ .Values.api.image.repository }}:{{ .Values.api.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.api.image.pullPolicy }}
envFrom:
- configMapRef:
name: {{ template "knowledge.api.fullname" . }}
env:
- name: MONGODB_URI
valueFrom:
secretKeyRef:
name: {{$secretName}}
key: mongodb-uri
- name: MONGODB_DATABASE
valueFrom:
secretKeyRef:
name: {{$secretName}}
key: mongodb-database
ports:
- name: http
containerPort: 8080
protocol: TCP
livenessProbe:
failureThreshold: 3
httpGet:
path: /api/healthcheck
port: http
scheme: HTTP
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 2
readinessProbe:
failureThreshold: 3
httpGet:
path: /api/healthcheck
port: http
scheme: HTTP
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
resources:
{{- toYaml .Values.api.resources | nindent 12 }}
{{- with .Values.api.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.api.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.api.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end -}}
28 changes: 28 additions & 0 deletions charts/knowledge/templates/api/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if and .Values.api.autoscaling.enabled .Values.api.enabled}}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "knowledge.api.fullname" . }}
labels:
{{- include "knowledge.api.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "knowledge.api.fullname" . }}
minReplicas: {{ .Values.api.autoscaling.minReplicas }}
maxReplicas: {{ .Values.api.autoscaling.maxReplicas }}
metrics:
{{- if .Values.api.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.api.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.api.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.api.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
61 changes: 61 additions & 0 deletions charts/knowledge/templates/api/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{{- if and .Values.api.enabled .Values.api.ingress.enabled -}}
{{- $fullNameApi := include "knowledge.api.fullname" . -}}
{{- $apiSvcPort := .Values.api.service.port -}}
{{- if and .Values.api.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.api.ingress.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.api.ingress.annotations "kubernetes.io/ingress.class" .Values.api.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: {{ $fullNameApi }}
labels:
{{- include "knowledge.api.labels" . | nindent 4 }}
{{- with .Values.api.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if and .Values.api.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.api.ingress.className }}
{{- end }}
{{- if .Values.api.ingress.tls }}
tls:
{{- range .Values.api.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.api.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: {{ $fullNameApi }}
port:
number: {{ $apiSvcPort }}
{{- else }}
serviceName: {{ $fullNameApi }}
servicePort: {{ $apiSvcPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
Loading

0 comments on commit ca1e79c

Please sign in to comment.