commit fe56675f01ddecc2296ee81d45a7e6b20de50f2b Author: Jörn Ahlers Date: Mon Mar 10 12:00:35 2025 +0100 init diff --git a/.helmignore b/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/.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/Chart.lock b/Chart.lock new file mode 100644 index 0000000..418574f --- /dev/null +++ b/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: mariadb + repository: https://charts.bitnami.com/bitnami + version: 11.5.7 +digest: sha256:4254008103034bb3ed9b3816a071a1aed1aacc049f9f993e56111fd82a574c3a +generated: "2025-03-10T11:06:09.8384115+01:00" diff --git a/Chart.yaml b/Chart.yaml new file mode 100644 index 0000000..fbc84ae --- /dev/null +++ b/Chart.yaml @@ -0,0 +1,11 @@ +apiVersion: v2 +name: librebooking +description: A Helm chart for Kubernetes +type: application +version: 0.1.0 + +dependencies: + - name: mariadb + condition: mariadb.enabled + repository: https://charts.bitnami.com/bitnami + version: 20.x \ No newline at end of file diff --git a/templates/NOTES.txt b/templates/NOTES.txt new file mode 100644 index 0000000..c46c427 --- /dev/null +++ b/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.librebooking.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "librebooking.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.librebooking.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "librebooking.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "librebooking.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.librebooking.service.port }} +{{- else if contains "ClusterIP" .Values.librebooking.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "librebooking.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/templates/_helpers.tpl b/templates/_helpers.tpl new file mode 100644 index 0000000..1bcdd72 --- /dev/null +++ b/templates/_helpers.tpl @@ -0,0 +1,83 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "librebooking.name" -}} +{{- default .Chart.Name .Values.librebooking.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 "librebooking.fullname" -}} +{{- if .Values.librebooking.fullnameOverride }} +{{- .Values.librebooking.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.librebooking.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 "librebooking.mariadb.fullname" -}} +{{- printf "%s-mariadb" .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "librebooking.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "librebooking.labels" -}} +helm.sh/chart: {{ include "librebooking.chart" . }} +{{ include "librebooking.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "librebooking.selectorLabels" -}} +app.kubernetes.io/name: {{ include "librebooking.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "librebooking.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "librebooking.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{/* +Return the MariaDB Secret Name +*/}} +{{- define "librebooking.databaseSecretName" -}} +{{- if .Values.mariadb.enabled }} + {{- if .Values.mariadb.auth.existingSecret -}} + {{- printf "%s" .Values.mariadb.auth.existingSecret -}} + {{- else -}} + {{- printf "%s" (include "librebooking.mariadb.fullname" .) -}} + {{- end -}} +{{- else if .Values.externalDatabase.existingSecret -}} + {{- printf "%s" .Values.externalDatabase.existingSecret -}} +{{- else -}} + {{- printf "%s-db-secrets" (include "librebooking.fullname" .) -}} +{{- end -}} +{{- end -}} \ No newline at end of file diff --git a/templates/deployment.yaml b/templates/deployment.yaml new file mode 100644 index 0000000..e460e5a --- /dev/null +++ b/templates/deployment.yaml @@ -0,0 +1,127 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "librebooking.fullname" . }} + labels: + {{- include "librebooking.labels" . | nindent 4 }} +spec: + selector: + matchLabels: + {{- include "librebooking.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "librebooking.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.librebooking.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "librebooking.serviceAccountName" . }} + {{- with .Values.podSecurityContext }} + securityContext: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + {{- with .Values.securityContext }} + securityContext: + {{- toYaml . | nindent 12 }} + {{- end }} + image: "{{ .Values.librebooking.image.repository }}:{{ .Values.librebooking.image.tag }}" + imagePullPolicy: {{ .Values.librebooking.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.librebooking.service.port }} + protocol: TCP + {{- with .Values.livenessProbe }} + livenessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.readinessProbe }} + readinessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.resources }} + resources: + {{- toYaml . | nindent 12 }} + {{- end }} + volumeMounts: + - name: storage + mountPath: "/config/" + {{- if .Values.persistence.subPath }} + subPath: {{ .Values.persistence.subPath }} + {{- end }} + env: + - name: LB_DB_HOST + {{- if eq .Values.mariadb.enabled true }} + value: {{ include "librebooking.mariadb.fullname" . }} + {{- else }} + value: {{ .Values.externalDatabase.host }} + {{- end }} + - name: LB_DB_USER + {{- if eq .Values.mariadb.enabled true }} + value: {{ .Values.mariadb.auth.username }} + {{- else }} + {{- if .Values.externalDatabase.existingSecretConfig.usernameField }} + valueFrom: + secretKeyRef: + name: {{ include "librebooking.databaseSecretName" . }} + key: {{ .Values.externalDatabase.existingSecretConfig.usernameField }} + {{- else}} + value: {{ .Values.externalDatabase.username }} + {{- end }} + {{- end }} + - name: LB_DB_USER_PWD + valueFrom: + secretKeyRef: + name: {{ include "librebooking.databaseSecretName" . }} + {{- if .Values.mariadb.enabled }} + key: mariadb-password + {{- else }} + key: {{ .Values.externalDatabase.existingSecretConfig.passwordField }} + {{- end }} + - name: LB_DB_NAME + {{- if eq .Values.mariadb.enabled true }} + value: {{ .Values.mariadb.auth.database }} + {{- else }} + {{- if .Values.externalDatabase.existingSecretConfig.databaseField }} + valueFrom: + secretKeyRef: + name: {{ include "librebooking.databaseSecretName" . }} + key: {{ .Values.externalDatabase.existingSecretConfig.databaseField}} + {{- else }} + value: {{ .Values.externalDatabase.database }} + {{- end }} + {{- end }} + - name: LB_INSTALL_PWD + value: '{{ .Values.librebooking.installPW }}' + - name: LB_LOG_LEVEL + value: '{{ .Values.librebooking.loglevel }}' + - name: LB_LOG_SQL + value: '{{ .Values.mariadb.loglevel }}' + - name: TZ + value: '{{ .Values.librebooking.TZ }}' + {{- with .Values.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- 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/templates/hpa.yaml b/templates/hpa.yaml new file mode 100644 index 0000000..517c263 --- /dev/null +++ b/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "librebooking.fullname" . }} + labels: + {{- include "librebooking.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "librebooking.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/templates/ingress.yaml b/templates/ingress.yaml new file mode 100644 index 0000000..ca03f01 --- /dev/null +++ b/templates/ingress.yaml @@ -0,0 +1,43 @@ +{{- if .Values.ingress.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "librebooking.fullname" . }} + labels: + {{- include "librebooking.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- with .Values.ingress.className }} + ingressClassName: {{ . }} + {{- 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 }} + {{- with .pathType }} + pathType: {{ . }} + {{- end }} + backend: + service: + name: {{ include "librebooking.fullname" $ }} + port: + number: {{ $.Values.librebooking.service.port }} + {{- end }} + {{- end }} +{{- end }} diff --git a/templates/pvc.yaml b/templates/pvc.yaml new file mode 100644 index 0000000..b5ef6af --- /dev/null +++ b/templates/pvc.yaml @@ -0,0 +1,32 @@ +{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }} +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ template "librebooking.fullname" . }} + labels: + {{- include "librebooking.labels" . | nindent 4 }} + {{- with .Values.persistence.annotations }} + annotations: +{{ toYaml . | indent 4 }} + {{- end }} + {{- with .Values.persistence.finalizers }} + finalizers: +{{ toYaml . | indent 4 }} + {{- end }} +spec: + accessModes: + {{- range .Values.persistence.accessModes }} + - {{ . | quote }} + {{- end }} + resources: + requests: + storage: {{ .Values.persistence.size | quote }} + {{- if .Values.persistence.storageClassName }} + storageClassName: {{ .Values.persistence.storageClassName }} + {{- end -}} + {{- with .Values.persistence.selectorLabels }} + selector: + matchLabels: +{{ toYaml . | indent 6 }} + {{- end }} +{{- end -}} \ No newline at end of file diff --git a/templates/service.yaml b/templates/service.yaml new file mode 100644 index 0000000..2e69e3f --- /dev/null +++ b/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "librebooking.fullname" . }} + labels: + {{- include "librebooking.labels" . | nindent 4 }} +spec: + type: {{ .Values.librebooking.service.type }} + ports: + - port: {{ .Values.librebooking.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "librebooking.selectorLabels" . | nindent 4 }} diff --git a/templates/serviceaccount.yaml b/templates/serviceaccount.yaml new file mode 100644 index 0000000..f74c53d --- /dev/null +++ b/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "librebooking.serviceAccountName" . }} + labels: + {{- include "librebooking.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/templates/tests/test-connection.yaml b/templates/tests/test-connection.yaml new file mode 100644 index 0000000..c213736 --- /dev/null +++ b/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "librebooking.fullname" . }}-test-connection" + labels: + {{- include "librebooking.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "librebooking.fullname" . }}:{{ .Values.librebooking.service.port }}'] + restartPolicy: Never diff --git a/values.yaml b/values.yaml new file mode 100644 index 0000000..34224b5 --- /dev/null +++ b/values.yaml @@ -0,0 +1,185 @@ +# Default values for librebooking. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +librebooking: + image: + repository: librebooking/librebooking + pullPolicy: IfNotPresent + tag: "2.8.6.2" + + # This is for the secrets for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + imagePullSecrets: [] + # This is to override the chart name. + nameOverride: "" + fullnameOverride: "" + + service: + # This sets the service type more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types + type: ClusterIP + # This sets the ports more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#field-spec-ports + port: 80 + + #https://github.com/LibreBooking/docker/blob/develop/RUN.md + installPW: '' + loglevel: 'none' + TZ: 'Europe/Berlin' + +## MariaDB chart configuration +mariadb: + enabled: true + #https://github.com/LibreBooking/docker/blob/develop/RUN.md + loglevel: 'false' + # for all possible configuration values, see: + # https://github.com/bitnami/charts/blob/master/bitnami/mariadb/values.yaml + auth: + existingSecret: null + # MariaDB root password + rootPassword: "" + # MariaDB custom database + database: librebooking + # MariaDB custom user name + username: librebooking + # MariaDB custom user password + password: test + storageClass: longhorn + size: 10Gi + +## Use an externally provisioned database instance +## Ignored when mariadb.enabled is set to true +externalDatabase: + # External Database server host + host: mariadb.example.com + # External Database server port + port: 3306 + # External Database username (use existingSecretConfig.usernameField to load from secret) + username: librebooking + # External Database user password + # (ignored when existingSecret is set, use existingSecretConfig.passwordField to change key) + password: null + # External Database database name (use existingSecretConfig.databaseField to load from secret) + database: librebooking + # Use an existing secret for retrieving the database password. + # The secret must contain the field "db-password" (field name configurable via existingSecretConfig.passwordField) + existingSecret: null + existingSecretConfig: + passwordField: db-password + usernameField: null + databaseField: null + + +# This section builds out the service account more information can be found here: https://kubernetes.io/docs/concepts/security/service-accounts/ +serviceAccount: + # Specifies whether a service account should be created + create: true + # Automatically mount a ServiceAccount's API credentials? + automount: 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: "" + +# This is for setting Kubernetes Annotations to a Pod. +# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ +podAnnotations: {} +# This is for setting Kubernetes Labels to a Pod. +# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ +podLabels: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +# This is for setting up a service more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/ + + +# This block is for setting up the ingress for more information can be found here: https://kubernetes.io/docs/concepts/services-networking/ingress/ +ingress: + enabled: true + 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 + +# This is to setup the liveness and readiness probes more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/ +livenessProbe: + httpGet: + path: / + port: http +readinessProbe: + httpGet: + path: / + port: http + +## Enable persistence using Persistent Volume Claims +## ref: http://kubernetes.io/docs/user-guide/persistent-volumes/ +## Used for LimeSurvey Uploads +persistence: + # Enable persistence with PVC. If false, uses emptyDir instead. + enabled: true + storageClassName: longhorn + accessModes: + - ReadWriteOnce + size: 10Gi + annotations: {} + finalizers: + - kubernetes.io/pvc-protection + selectorLabels: {} + subPath: "" + existingClaim: null + +# This section is for setting up autoscaling more information can be found here: https://kubernetes.io/docs/concepts/workloads/autoscaling/ +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# Additional volumes on the output Deployment definition. +volumes: [] +# - name: foo +# secret: +# secretName: mysecret +# optional: false + +# Additional volumeMounts on the output Deployment definition. +volumeMounts: [] +# - name: foo +# mountPath: "/etc/foo" +# readOnly: true + +nodeSelector: {} + +tolerations: [] + +affinity: {}