From b0229e2e2c265e55cdb1307da7744e476fc12eb7 Mon Sep 17 00:00:00 2001 From: Jan-Niklas Weghorn Date: Sun, 8 Oct 2023 17:33:58 +0200 Subject: [PATCH] add trilium and joplin --- charts/joplin/.helmignore | 23 ++++ charts/joplin/Chart.lock | 6 + charts/joplin/Chart.yaml | 11 ++ charts/joplin/templates/NOTES.txt | 22 ++++ charts/joplin/templates/_helpers.tpl | 62 +++++++++++ charts/joplin/templates/deployment.yaml | 94 ++++++++++++++++ charts/joplin/templates/hpa.yaml | 32 ++++++ charts/joplin/templates/ingress.yaml | 61 ++++++++++ charts/joplin/templates/service.yaml | 15 +++ charts/joplin/templates/serviceaccount.yaml | 12 ++ .../templates/tests/test-connection.yaml | 15 +++ charts/joplin/values.yaml | 104 ++++++++++++++++++ charts/trilium/.helmignore | 23 ++++ charts/trilium/Chart.yaml | 9 ++ charts/trilium/templates/NOTES.txt | 22 ++++ charts/trilium/templates/_helpers.tpl | 62 +++++++++++ charts/trilium/templates/hpa.yaml | 32 ++++++ charts/trilium/templates/ingress.yaml | 61 ++++++++++ charts/trilium/templates/service.yaml | 15 +++ charts/trilium/templates/serviceaccount.yaml | 12 ++ charts/trilium/templates/statefulset.yaml | 91 +++++++++++++++ .../templates/tests/test-connection.yaml | 15 +++ charts/trilium/values.yaml | 83 ++++++++++++++ 23 files changed, 882 insertions(+) create mode 100644 charts/joplin/.helmignore create mode 100644 charts/joplin/Chart.lock create mode 100644 charts/joplin/Chart.yaml create mode 100644 charts/joplin/templates/NOTES.txt create mode 100644 charts/joplin/templates/_helpers.tpl create mode 100644 charts/joplin/templates/deployment.yaml create mode 100644 charts/joplin/templates/hpa.yaml create mode 100644 charts/joplin/templates/ingress.yaml create mode 100644 charts/joplin/templates/service.yaml create mode 100644 charts/joplin/templates/serviceaccount.yaml create mode 100644 charts/joplin/templates/tests/test-connection.yaml create mode 100644 charts/joplin/values.yaml create mode 100644 charts/trilium/.helmignore create mode 100644 charts/trilium/Chart.yaml create mode 100644 charts/trilium/templates/NOTES.txt create mode 100644 charts/trilium/templates/_helpers.tpl create mode 100644 charts/trilium/templates/hpa.yaml create mode 100644 charts/trilium/templates/ingress.yaml create mode 100644 charts/trilium/templates/service.yaml create mode 100644 charts/trilium/templates/serviceaccount.yaml create mode 100644 charts/trilium/templates/statefulset.yaml create mode 100644 charts/trilium/templates/tests/test-connection.yaml create mode 100644 charts/trilium/values.yaml diff --git a/charts/joplin/.helmignore b/charts/joplin/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/joplin/.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/joplin/Chart.lock b/charts/joplin/Chart.lock new file mode 100644 index 0000000..f7d0aa5 --- /dev/null +++ b/charts/joplin/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: postgresql + repository: https://charts.bitnami.com/bitnami + version: 12.12.10 +digest: sha256:3e50f191dcf868228a07a26896bd4759db58461fac5fe593ebadd95d18c4e8e1 +generated: "2023-09-29T17:17:39.213895045+02:00" diff --git a/charts/joplin/Chart.yaml b/charts/joplin/Chart.yaml new file mode 100644 index 0000000..29f8d0d --- /dev/null +++ b/charts/joplin/Chart.yaml @@ -0,0 +1,11 @@ +apiVersion: v2 +name: joplin +description: A Note Taking App +type: application +version: 0.1.0 +appVersion: "2.13.1-beta" +dependencies: + - condition: postgresql.enabled + name: postgresql + repository: https://charts.bitnami.com/bitnami + version: 12.x.x diff --git a/charts/joplin/templates/NOTES.txt b/charts/joplin/templates/NOTES.txt new file mode 100644 index 0000000..81727e1 --- /dev/null +++ b/charts/joplin/templates/NOTES.txt @@ -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 "joplin.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 "joplin.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "joplin.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 "joplin.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 }} diff --git a/charts/joplin/templates/_helpers.tpl b/charts/joplin/templates/_helpers.tpl new file mode 100644 index 0000000..97ad52e --- /dev/null +++ b/charts/joplin/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "joplin.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 "joplin.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 "joplin.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "joplin.labels" -}} +helm.sh/chart: {{ include "joplin.chart" . }} +{{ include "joplin.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "joplin.selectorLabels" -}} +app.kubernetes.io/name: {{ include "joplin.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "joplin.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "joplin.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/joplin/templates/deployment.yaml b/charts/joplin/templates/deployment.yaml new file mode 100644 index 0000000..9aaf65c --- /dev/null +++ b/charts/joplin/templates/deployment.yaml @@ -0,0 +1,94 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "joplin.fullname" . }} + labels: + {{- include "joplin.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "joplin.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "joplin.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "joplin.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 }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + # livenessProbe: + # httpGet: + # path: /api/ping + # port: http + # httpHeaders: + # - name: Host + # value: {{ .Values.joplin.baseUrl }}:{{ .Values.service.port }} + # readinessProbe: + # httpGet: + # path: /api/ping + # port: http + # httpHeaders: + # - name: Host + # value: {{ .Values.joplin.baseUrl }}:{{ .Values.service.port }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + env: + - name: APP_PORT + value: {{ .Values.service.port | quote }} + - name: TZ + value: {{ .Values.joplin.tz }} + - name: APP_BASE_URL + value: {{ .Values.joplin.baseUrl }} + - name: DB_CLIENT + value: {{ .Values.joplin.db.type }} + - name: POSTGRES_HOST + value: {{ .Values.joplin.db.host }} + - name: POSTGRES_PORT + value: {{ .Values.joplin.db.port | quote }} + - name: POSTGRES_DATABASE + value: {{ .Values.joplin.db.database }} + - name: POSTGRES_USER + value: {{ .Values.joplin.db.user }} + - name: POSTGRES_PASSWORD + {{- if .Values.joplin.db.existingSecret }} + valueFrom: + secretKeyRef: + name: {{ .Values.joplin.db.existingSecret }} + key: {{ .Values.joplin.db.secretKeys.passwordKey }} + {{- else }} + value: {{ .Values.joplin.db.password }} + {{- end }} + + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/joplin/templates/hpa.yaml b/charts/joplin/templates/hpa.yaml new file mode 100644 index 0000000..130680e --- /dev/null +++ b/charts/joplin/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "joplin.fullname" . }} + labels: + {{- include "joplin.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "joplin.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/joplin/templates/ingress.yaml b/charts/joplin/templates/ingress.yaml new file mode 100644 index 0000000..28358bf --- /dev/null +++ b/charts/joplin/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "joplin.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.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: {{ $fullName }} + labels: + {{- include "joplin.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.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: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/joplin/templates/service.yaml b/charts/joplin/templates/service.yaml new file mode 100644 index 0000000..84215e5 --- /dev/null +++ b/charts/joplin/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "joplin.fullname" . }} + labels: + {{- include "joplin.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "joplin.selectorLabels" . | nindent 4 }} diff --git a/charts/joplin/templates/serviceaccount.yaml b/charts/joplin/templates/serviceaccount.yaml new file mode 100644 index 0000000..dc89750 --- /dev/null +++ b/charts/joplin/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "joplin.serviceAccountName" . }} + labels: + {{- include "joplin.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/joplin/templates/tests/test-connection.yaml b/charts/joplin/templates/tests/test-connection.yaml new file mode 100644 index 0000000..b15dbba --- /dev/null +++ b/charts/joplin/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "joplin.fullname" . }}-test-connection" + labels: + {{- include "joplin.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "joplin.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/joplin/values.yaml b/charts/joplin/values.yaml new file mode 100644 index 0000000..84c7378 --- /dev/null +++ b/charts/joplin/values.yaml @@ -0,0 +1,104 @@ +# Default values for joplin. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: joplin/server + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 22300 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} + + +postgresql: + enabled: true + +joplin: + extraEnv: [] + tz: Europe/Berlin + baseUrl: https://example.com + db: + type: pg + host: "" + port: 5432 + database: joplin + user: "" + password: "" + existingSecret: "" + secretKeys: + passwordKey: password + + + diff --git a/charts/trilium/.helmignore b/charts/trilium/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/trilium/.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/trilium/Chart.yaml b/charts/trilium/Chart.yaml new file mode 100644 index 0000000..51c144e --- /dev/null +++ b/charts/trilium/Chart.yaml @@ -0,0 +1,9 @@ +apiVersion: v2 +name: trilium +description: A Helm chart for trilium notes. +type: application +version: 0.1.0 +appVersion: "0.60.4" +home: https://gitlab.com/oecis/charts/-/tree/main/charts/trilium +sources: +- https://github.com/zadam/trilium diff --git a/charts/trilium/templates/NOTES.txt b/charts/trilium/templates/NOTES.txt new file mode 100644 index 0000000..477bbf2 --- /dev/null +++ b/charts/trilium/templates/NOTES.txt @@ -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 "trilium.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 "trilium.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "trilium.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 "trilium.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 }} diff --git a/charts/trilium/templates/_helpers.tpl b/charts/trilium/templates/_helpers.tpl new file mode 100644 index 0000000..39f05d4 --- /dev/null +++ b/charts/trilium/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "trilium.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 "trilium.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 "trilium.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "trilium.labels" -}} +helm.sh/chart: {{ include "trilium.chart" . }} +{{ include "trilium.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "trilium.selectorLabels" -}} +app.kubernetes.io/name: {{ include "trilium.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "trilium.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "trilium.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/trilium/templates/hpa.yaml b/charts/trilium/templates/hpa.yaml new file mode 100644 index 0000000..25b2803 --- /dev/null +++ b/charts/trilium/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "trilium.fullname" . }} + labels: + {{- include "trilium.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "trilium.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/trilium/templates/ingress.yaml b/charts/trilium/templates/ingress.yaml new file mode 100644 index 0000000..7c138bd --- /dev/null +++ b/charts/trilium/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "trilium.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.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: {{ $fullName }} + labels: + {{- include "trilium.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.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: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/trilium/templates/service.yaml b/charts/trilium/templates/service.yaml new file mode 100644 index 0000000..7bbb48b --- /dev/null +++ b/charts/trilium/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "trilium.fullname" . }} + labels: + {{- include "trilium.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "trilium.selectorLabels" . | nindent 4 }} diff --git a/charts/trilium/templates/serviceaccount.yaml b/charts/trilium/templates/serviceaccount.yaml new file mode 100644 index 0000000..b965d84 --- /dev/null +++ b/charts/trilium/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "trilium.serviceAccountName" . }} + labels: + {{- include "trilium.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/trilium/templates/statefulset.yaml b/charts/trilium/templates/statefulset.yaml new file mode 100644 index 0000000..c93a4c0 --- /dev/null +++ b/charts/trilium/templates/statefulset.yaml @@ -0,0 +1,91 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "trilium.fullname" . }} + labels: + {{- include "trilium.labels" . | nindent 4 }} +spec: + serviceName: {{ template "trilium.fullname" . }}-headless + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "trilium.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "trilium.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "trilium.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ default .Chart.AppVersion .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: TRILIUM_DATA_DIR + value: "{{ .Values.dataDir }}" + {{- if not (empty .Values.trilium.extraEnv) }} + {{- toYaml .Values.trilium.extraEnv | nindent 10 }} + {{- end }} + ports: + - name: http + containerPort: 8080 + protocol: TCP + livenessProbe: + httpGet: + path: / + port: 8080 + readinessProbe: + httpGet: + path: / + port: 8080 + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: trilium-data + mountPath: "{{ .Values.dataDir }}" + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} +{{- if .Values.persistentVolume.enabled }} + volumeClaimTemplates: + - metadata: + name: trilium-data + {{- if .Values.persistentVolume.annotations }} + annotations: +{{ toYaml .Values.persistentVolume.annotations | indent 10 }} + {{- end }} + spec: + accessModes: +{{ toYaml .Values.persistentVolume.accessModes | indent 10 }} + resources: + requests: + storage: "{{ .Values.persistentVolume.size }}" + {{- if .Values.persistentVolume.storageClass }} + {{- if (eq "-" .Values.persistentVolume.storageClass) }} + storageClassName: "" + {{- else }} + storageClassName: "{{ .Values.persistentVolume.storageClass }}" + {{- end }} + {{- end }} +{{- else }} + volumes: + - name: trilium-data + emptyDir: {} +{{- end }} diff --git a/charts/trilium/templates/tests/test-connection.yaml b/charts/trilium/templates/tests/test-connection.yaml new file mode 100644 index 0000000..8cb3405 --- /dev/null +++ b/charts/trilium/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "trilium.fullname" . }}-test-connection" + labels: + {{- include "trilium.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "trilium.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/trilium/values.yaml b/charts/trilium/values.yaml new file mode 100644 index 0000000..13d99ac --- /dev/null +++ b/charts/trilium/values.yaml @@ -0,0 +1,83 @@ +replicaCount: 1 + +image: + repository: zadam/trilium + tag: "" + pullPolicy: IfNotPresent + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + create: true + annotations: {} + # If not set and create is true, a name is generated using the fullname template + name: + +podSecurityContext: {} + # fsGroup: 10000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # runAsNonRoot: true + # runAsUser: 10000 + # allowPrivilegeEscalation: false + +service: + type: ClusterIP + port: 8080 + +dataDir: /srv/trilium-data + +persistentVolume: + enabled: false + accessModes: + - ReadWriteOnce + annotations: {} + size: 2Gi + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +trilium: + extraEnv: []