Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

feat(helm): render extra Kubernetes objects from an extraObjects list

Maurice3b42ffa67b81
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index fb2191fed..65aacc1a5 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -1224,6 +1224,14 @@ jobs:
--set service.port=8080 \
--set-json 'httpRoute={"enabled":true,"parentRefs":[{"name":"gateway","namespace":"gateway-system","sectionName":"https"}],"hostnames":["trek.example.com"],"paths":["/","/api"],"annotations":{"example.com/note":"custom route"},"timeouts":{"request":"0s","backendRequest":"0s"}}' \
> "$out/http-route-variants.yaml"
+ helm template trek charts/trek \
+ --set-json 'extraObjects=[{"apiVersion":"batch/v1","kind":"CronJob","metadata":{"name":"{{ include \"trek.fullname\" . }}-backup-copy"},"spec":{"schedule":"0 3 * * *","jobTemplate":{"spec":{"template":{"spec":{"restartPolicy":"OnFailure","containers":[{"name":"copy","image":"busybox:1.36","command":["ls","/data/backups"],"volumeMounts":[{"name":"data","mountPath":"/data","readOnly":true}]}],"volumes":[{"name":"data","persistentVolumeClaim":{"claimName":"{{ include \"trek.fullname\" . }}-data","readOnly":true}}]}}}}}},"apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: {{ .Release.Name }}-notes\ndata:\n release: {{ .Release.Name | quote }}\n"]' \
+ > "$out/extra-objects.yaml"
+ # kubeconform accepts a name that still reads {{ ... }}, so check that both forms went through tpl.
+ if grep -n '{{' "$out/extra-objects.yaml"; then
+ echo "::error::extraObjects left a template unrendered"
+ exit 1
+ fi
- name: Check the manifests against the Kubernetes schemas
# The pinned Gateway API schema adds HTTPRoute validation without skipping unknown resources.
diff --git a/charts/README.md b/charts/README.md
index 48726dcb5..c752bc5b4 100644
--- a/charts/README.md
+++ b/charts/README.md
@@ -60,3 +60,4 @@ See `values.yaml` for more options.
- Set `env.OIDC_DISCOVERY_URL` to override the auto-constructed OIDC discovery endpoint. Required for providers (e.g. Authentik) that expose it at a non-standard path.
- `podSecurityContext` defaults to `fsGroup: 1000` with `fsGroupChangePolicy: OnRootMismatch`, and `securityContext` (the container's) is empty. The container then starts as root, hands `/app/data` and `/app/uploads` to `node` (uid 1000) if the directory or anything directly inside it is not owned by `node` yet, and drops to `node`. Deeper files are not checked. Only the owning user is changed (plus a `root` group), so a different `fsGroup` stays in place. A volume that refuses `chown` (NFS with `root_squash`) logs a warning instead; set `runAsUser: 1000` then. To run as `node` from the start, for example under the `restricted` Pod Security Standard, set `podSecurityContext.runAsUser: 1000` and `runAsGroup: 1000`; the image then skips that step and the privilege drop. See the example in `values.yaml`.
- Use `extraVolumes` and `extraVolumeMounts` to add your own volumes to the pod. To give the booking import more KItinerary extractors, mount a ConfigMap at `/usr/local/share/kitinerary/extractors`, with one `.json` and one `.js` key for each extractor; see the example in `values.yaml`.
+- Use `extraObjects` to render further Kubernetes objects next to the chart's own, for example a backup `CronJob`. Each item is a map or a string of YAML, and `{{ }}` in it is evaluated, so `{{ .Release.Name }}` works. A backup job should copy TREK's own backups from `backups/` on the data volume and mount it read only, since that volume also holds the encryption key. The archives carry `.encryption_key` too unless `ENCRYPTION_KEY` is set, so protect the copy's destination like the data volume.
diff --git a/charts/trek/templates/extra-objects.yaml b/charts/trek/templates/extra-objects.yaml
new file mode 100644
index 000000000..a5d4147dd
--- /dev/null
+++ b/charts/trek/templates/extra-objects.yaml
@@ -0,0 +1,8 @@
+{{- range .Values.extraObjects }}
+---
+{{- if kindIs "string" . }}
+{{ tpl . $ }}
+{{- else }}
+{{ tpl (toYaml .) $ }}
+{{- end }}
+{{- end }}
diff --git a/charts/trek/values.yaml b/charts/trek/values.yaml
index cb95d2833..baa1d2e06 100644
--- a/charts/trek/values.yaml
+++ b/charts/trek/values.yaml
@@ -338,6 +338,29 @@ extraVolumes: []
# readOnly: true
extraVolumeMounts: []
+# Further Kubernetes objects the chart renders next to its own, for example a Job, a
+# CronJob or a ConfigMap. Each item is rendered as written, either as a map or as a
+# string of YAML, and {{ }} in it is evaluated, so {{ include "trek.fullname" . }} or
+# {{ .Release.Name }} work, in both forms. Write literal braces as {{ "{{" }}.
+# A backup job must only read the data volume: it also holds the encryption key and the
+# server's secrets, and a second writer corrupts travel.db. Rather than copying the live
+# travel.db, copy TREK's own backups (Admin, Backup, automatic backups) from backups/ in
+# that volume. Those archives carry .encryption_key too (unless ENCRYPTION_KEY is set),
+# so protect the job's destination like the data volume itself.
+# extraObjects:
+# - apiVersion: v1
+# kind: ConfigMap
+# metadata:
+# name: '{{ include "trek.fullname" . }}-extra'
+# data:
+# note: hello
+# - |
+# apiVersion: v1
+# kind: ConfigMap
+# metadata:
+# name: {{ .Release.Name }}-notes
+extraObjects: []
+
resources:
requests:
cpu: 100m
diff --git a/wiki/Install-Helm.md b/wiki/Install-Helm.md
index 9977ca474..843feb414 100644
--- a/wiki/Install-Helm.md
+++ b/wiki/Install-Helm.md
@@ -228,6 +228,8 @@ persistence:
> **Warning:** A `ReadWriteMany` data volume is only safe for pods that read it. SQLite needs every process that writes `travel.db` on the same host, so a second writer over a network filesystem corrupts the database. Keep `updateStrategy: Recreate` either way.
+Such a backup job can ship with the release: `extraObjects` takes a list of further Kubernetes objects (a `CronJob`, a `ConfigMap`, anything the cluster knows) and renders each one as written, as a map or as a string of YAML. `{{ }}` in them is evaluated, so `{{ include "trek.fullname" . }}-data` names the data claim; this holds for both forms, so write literal braces as `{{ "{{" }}`. Mount the data volume read only: besides `travel.db` it holds the encryption key and the server's secrets. Copy the archives TREK writes itself (**Admin Panel > Backup**, with **Auto-Backup** on) from `backups/` in that volume rather than the live `travel.db`, which a copy can catch halfway through a write. Those archives contain `.encryption_key` as well (unless the key comes from `ENCRYPTION_KEY`), so protect wherever the job copies them to like the data volume itself.
+
### Security Context
```yaml