From fa34ee8a4080dcc2656b81b6f76ee045fc20e541 Mon Sep 17 00:00:00 2001 From: Bertrand THOMAS Date: Fri, 17 Jul 2026 01:32:29 +0200 Subject: [PATCH 1/7] Update keeptrack and sidelab charts --- charts/keeptrack/Chart.yaml | 2 +- charts/keeptrack/README.md | 27 ++++++++++++ charts/keeptrack/templates/deployment.yaml | 20 ++++++++- charts/keeptrack/values.yaml | 32 +++++++++++--- charts/sidelab/.helmignore | 6 ++- charts/sidelab/Chart.yaml | 2 +- charts/sidelab/README.md | 9 ++-- charts/sidelab/templates/NOTES.txt | 4 +- charts/sidelab/templates/_helpers.tpl | 30 +++++++------- charts/sidelab/templates/configmap.yaml | 18 +++++--- charts/sidelab/templates/networkpolicy.yaml | 10 +++++ charts/sidelab/templates/rbac.yaml | 14 +++---- charts/sidelab/values.yaml | 46 ++++++++++++--------- 13 files changed, 160 insertions(+), 60 deletions(-) diff --git a/charts/keeptrack/Chart.yaml b/charts/keeptrack/Chart.yaml index 908529b..a5a82d7 100644 --- a/charts/keeptrack/Chart.yaml +++ b/charts/keeptrack/Chart.yaml @@ -3,7 +3,7 @@ name: keeptrack description: Helm chart for Keeptrack type: application version: 0.2.1 -appVersion: "2.0" +appVersion: "2.1" home: https://github.com/devpro/keeptrack sources: - https://github.com/devpro/keeptrack diff --git a/charts/keeptrack/README.md b/charts/keeptrack/README.md index 98655dc..e07dd05 100644 --- a/charts/keeptrack/README.md +++ b/charts/keeptrack/README.md @@ -44,6 +44,33 @@ Notable ones: for platforms that mandate the Kubernetes Pod Security Standards "restricted" profile. Disabled by default; validate in a non-production environment first. +## Scaling & high availability + +Both deployments support `replicaCount > 1`, by design of the app itself rather than of any particular ingress (no sticky sessions / cookie affinity required anywhere - +it works identically behind a Cloudflare tunnel, Traefik, ingress-nginx, or a plain `Service`). + +**`webapi`** (requires app image >= the release that introduced the MongoDB-backed job store): fully stateless per request. +Background-job progress (TV Time import, reference-data "sync now") is stored in MongoDB so any replica can answer a poll, +and the daily reference-data sync elects a single runner through a MongoDB lease, so scaling out never multiplies TMDB/RAWG/Discogs traffic. + +Just raise `webapi.replicaCount`. + +**`blazorapp`** (Blazor Server): two settings make multiple replicas work, both on by the time you scale: + +1. `blazorapp.dataProtection.enabled: true` (plus its MongoDB connection, typically the same secret as `webapi.db`) - shares the cookie-encryption key ring across replicas. + Without it, a login cookie issued by one pod is unreadable by the others and users bounce between logged-in and logged-out. + Worth enabling even at 1 replica: sessions then survive pod restarts. +2. `blazorapp.webSocketsOnly: true` (the default) - + each Blazor circuit runs on one long-lived WebSocket and therefore naturally sticks to the pod that owns its in-memory state, with no load-balancer affinity needed. + Whatever sits in front only has to pass WebSockets through (Cloudflare tunnels and every mainstream ingress do). + +Known limitation (inherent to Blazor Server, not fixable by this chart): a circuit lives in the memory of exactly one pod. +When that pod dies or is replaced during a rollout, browsers connected to it reconnect and reload the page they were on +(no user data is lost - the app saves edits as they are made). +Extra replicas therefore add capacity and availability for new connections; they don't make an individual session survive the loss of its pod. +After a transient network blip (pod still alive), the client's reconnect attempts re-roll across replicas until one lands on the right pod, +which at small replica counts succeeds within the default retry budget. + ## Development Look at the [Contributing guide](CONTRIBUTING.md). diff --git a/charts/keeptrack/templates/deployment.yaml b/charts/keeptrack/templates/deployment.yaml index a528cca..a016cd9 100644 --- a/charts/keeptrack/templates/deployment.yaml +++ b/charts/keeptrack/templates/deployment.yaml @@ -95,7 +95,7 @@ spec: value: {{ $.Values.dotnet.logLevels.default | quote }} - name: Logging__LogLevel__Microsoft.AspNetCore value: {{ $.Values.dotnet.logLevels.framework | quote }} - - name: Logging__LogLevel__Devpro + - name: Logging__LogLevel__Keeptrack value: {{ $.Values.dotnet.logLevels.application | quote }} - name: Features__IsHttpsRedirectionEnabled value: {{ $.Values.dotnet.httpsRedirectionEnabled | quote }} @@ -104,6 +104,22 @@ spec: {{- if eq .role "frontend" }} - name: WebApi__BaseUrl value: "http://{{ $.Values.webapi.name }}" + - name: Features__IsWebSocketsOnlyEnabled + value: {{ .webSocketsOnly | quote }} + {{- if .dataProtection.enabled }} + {{- if .dataProtection.connectionStringSecretKeyRef }} + - name: DataProtection__MongoDb__ConnectionString + valueFrom: + secretKeyRef: + name: {{ .dataProtection.connectionStringSecretKeyRef.name }} + key: {{ .dataProtection.connectionStringSecretKeyRef.key }} + {{- else }} + - name: DataProtection__MongoDb__ConnectionString + value: {{ .dataProtection.connectionString | quote }} + {{- end }} + - name: DataProtection__MongoDb__DatabaseName + value: {{ .dataProtection.databaseName | quote }} + {{- end }} {{- if $.Values.firebase.webApp.apiKeySecretKeyRef }} - name: Firebase__WebAppConfiguration__ApiKey valueFrom: @@ -193,6 +209,8 @@ spec: value: {{ .db.databaseName | quote }} - name: Features__IsReferenceSyncEnabled value: {{ .referenceData.isSyncEnabled | quote }} + - name: Features__FreeTierItemLimit + value: {{ .freeTierItemLimit | quote }} {{- if .referenceData.bookProvider }} - name: ReferenceData__BookProvider value: {{ .referenceData.bookProvider | quote }} diff --git a/charts/keeptrack/values.yaml b/charts/keeptrack/values.yaml index 3b7083e..ad9f792 100644 --- a/charts/keeptrack/values.yaml +++ b/charts/keeptrack/values.yaml @@ -8,7 +8,7 @@ healthEndpoint: /health tls: secretName: keeptrack-blazorapp-tls - tag: 2.0.29367732118 # ref. https://hub.docker.com/r/devprofr/keeptrack-blazorapp/tags + tag: 2.1.29541631973 # ref. https://hub.docker.com/r/devprofr/keeptrack-blazorapp/tags replicaCount: 1 resources: {} # limits: @@ -22,6 +22,25 @@ # value: "yyyy" additionalPodLabels: {} host: "" + # Blazor Server scale-out support - see README "Scaling & high availability". + # Persists the app's Data Protection key ring (which encrypts the auth cookie and antiforgery tokens) + # in MongoDB, so every replica can decrypt what any other replica issued. REQUIRED before setting replicaCount > 1; + # recommended even at 1 replica (sessions then survive pod restarts). + dataProtection: + enabled: false + # important when enabled: connectionString or connectionStringSecretKeyRef must be provided + # (typically the same secret as webapi.db) + # connectionStringSecretKeyRef: + # name: "" + # key: "" + # connectionString: "" + databaseName: "keeptrack" + # Forces the Blazor Server circuit onto a single WebSocket with no negotiate round-trip, so a circuit + # naturally sticks to the replica that owns its state - + # no load-balancer cookie affinity needed, which makes replicaCount > 1 work behind anything that passes WebSockets through (cloudflared, Traefik, plain Services). + # Only set to false if a proxy in front can't pass WebSockets; + # such a deployment must then stay at replicaCount 1. + webSocketsOnly: true webapi: enabled: true @@ -35,10 +54,14 @@ webapi: secretName: keeptrack-webapi-tls host: "" replicaCount: 1 - tag: 2.0.29367732118 # ref. https://hub.docker.com/r/devprofr/keeptrack-webapi/tags + tag: 2.1.29541631973 # ref. https://hub.docker.com/r/devprofr/keeptrack-webapi/tags resources: {} extraEnv: [] additionalPodLabels: {} + # how many items a signed-in account WITHOUT the Firebase "member"/"admin" role may create per free-tier collection (movies, TV shows); + # such accounts have no access to the other collections at all - + # grant `role: member` via the Firebase Admin SDK to unlock everything (see the app's CONTRIBUTING.md) + freeTierItemLimit: 20 db: # important: connectionString or connectionStringSecretKeyRef must be provided # connectionStringSecretKeyRef: @@ -46,9 +69,8 @@ webapi: # key: "" # connectionString: "someconnstring" databaseName: "keeptrack" - # optional: third-party providers used to enrich movies/TV shows/video games/books/albums with - # posters, synopsis, cast and episode data. Leaving a key empty just means that provider's - # enrichment silently fails (401/403 from the provider) - the rest of the app is unaffected. + # optional: third-party providers used to enrich movies/TV shows/video games/books/albums with posters, synopsis, cast and episode data. + # Leaving a key empty just means that provider's enrichment silently fails (401/403 from the provider) - the rest of the app is unaffected. referenceData: # overrides the app's own default ("OpenLibrary") - see WebApi's AppConfiguration.BookReferenceProvider bookProvider: "" diff --git a/charts/sidelab/.helmignore b/charts/sidelab/.helmignore index d359a7a..d13bc8e 100644 --- a/charts/sidelab/.helmignore +++ b/charts/sidelab/.helmignore @@ -1,8 +1,10 @@ -# Patterns to ignore when building packages. -.DS_Store +.DS_Store .git/ .gitignore .helmignore *.orig *.swp *.bak +values.mine.yaml +temp*.yaml +kubeconfig diff --git a/charts/sidelab/Chart.yaml b/charts/sidelab/Chart.yaml index cd30a2d..b36908d 100644 --- a/charts/sidelab/Chart.yaml +++ b/charts/sidelab/Chart.yaml @@ -4,7 +4,7 @@ description: > Self-hosted interactive lab platform. Deploys the Sidelab launcher, which manages lab sessions as ephemeral Kubernetes Pods inside tenant-scoped namespaces. type: application -version: 0.1.1 +version: 0.1.2 appVersion: "0.1.0" keywords: - sidelab diff --git a/charts/sidelab/README.md b/charts/sidelab/README.md index c9681d5..015eed1 100644 --- a/charts/sidelab/README.md +++ b/charts/sidelab/README.md @@ -3,7 +3,8 @@ Helm chart for [Sidelab](https://github.com/devpro-training/sidelab) — a self-hosted interactive lab platform. Deploys the Sidelab launcher, which manages lab sessions as ephemeral Kubernetes Pods inside tenant-scoped namespaces. -Supports SQLite (zero-dependency, quick look/demo) or MongoDB (recommended for anything you keep — external, or a bundled disposable instance for a demo) as the database backend, and NodePort or Ingress for exposing lab sessions. +Supports SQLite (zero-dependency, quick look/demo) or MongoDB (recommended for anything you keep — external, or a bundled disposable instance for a demo) +as the database backend, and NodePort or Ingress for exposing lab sessions. `values.yaml` is the source of truth for every option — it's fully commented, including Traefik/cert-manager/Let's Encrypt examples. ## Quick Start @@ -23,7 +24,8 @@ Install the application: helm upgrade --install sidelab devpro/sidelab -f values.yaml --namespace sidelab --create-namespace ``` -Nothing above is strictly required — `helm upgrade --install sidelab devpro/sidelab --namespace sidelab --create-namespace` alone works too: SQLite + NodePort + auto-generated secrets, no external dependencies. +One value is always required: `image.repository` — the chart is public but the sidelab images are not published to a public registry. +Everything else has working defaults: SQLite + NodePort + auto-generated secrets, no external dependencies. See [CONTRIBUTING.md](CONTRIBUTING.md) for ready-to-use `values.mine.yaml` snippets covering the other use cases (MongoDB, Ingress + cert-manager, the bundled MongoDB demo chart). ## Uninstall @@ -33,7 +35,8 @@ helm uninstall sidelab -n sidelab kubectl delete namespace sidelab ``` -The auto-generated `-auth` Secret (admin password) and the data PVC are deleted along with the namespace — back up `database.mongo.url`'s target or the PVC first if you need to keep the data. +The auto-generated `-auth` Secret (admin password) and the data PVC are deleted along with the namespace — +back up `database.mongo.url`'s target or the PVC first if you need to keep the data. ## Going further diff --git a/charts/sidelab/templates/NOTES.txt b/charts/sidelab/templates/NOTES.txt index 04693b9..64651c3 100644 --- a/charts/sidelab/templates/NOTES.txt +++ b/charts/sidelab/templates/NOTES.txt @@ -25,12 +25,14 @@ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ First login ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - Username: {{ .Values.auth.adminUsername }} {{- if .Values.auth.existingSecret }} + Username: (value of the "ADMIN_USERNAME" key in Secret/{{ .Values.auth.existingSecret }}) Password: (value of the "ADMIN_PASSWORD" key in Secret/{{ .Values.auth.existingSecret }}) {{- else if .Values.auth.adminPassword }} + Username: {{ .Values.auth.adminUsername }} Password: (value of auth.adminPassword you supplied) {{- else }} + Username: {{ .Values.auth.adminUsername }} Password: auto-generated on first install — retrieve it with: kubectl get secret -n {{ .Release.Namespace }} {{ include "sidelab.authSecretName" . }} \ diff --git a/charts/sidelab/templates/_helpers.tpl b/charts/sidelab/templates/_helpers.tpl index 8845906..e2f8e6d 100644 --- a/charts/sidelab/templates/_helpers.tpl +++ b/charts/sidelab/templates/_helpers.tpl @@ -1,4 +1,4 @@ -{{/* +{{/* Expand the name of the chart. */}} {{- define "sidelab.name" -}} @@ -101,8 +101,8 @@ Image tag — falls back to .Chart.AppVersion. {{- end }} {{/* -Dashboard hostname. ingress.host wins; otherwise derived from the shared -top-level `domain` value as "sidelab.". Empty if neither is set. +Dashboard hostname. ingress.host wins; otherwise derived from the shared top-level `domain` value as "sidelab.". +Empty if neither is set. */}} {{- define "sidelab.ingressHost" -}} {{- if .Values.ingress.host -}} @@ -113,8 +113,8 @@ top-level `domain` value as "sidelab.". Empty if neither is set. {{- end }} {{/* -Lab session wildcard domain. launcher.labDomain wins; otherwise derived from -the shared top-level `domain` value as "labs.". Empty if neither is set. +Lab session wildcard domain. launcher.labDomain wins; otherwise derived from the shared top-level `domain` value as "labs.". +Empty if neither is set. */}} {{- define "sidelab.labDomain" -}} {{- if .Values.launcher.labDomain -}} @@ -125,11 +125,11 @@ the shared top-level `domain` value as "labs.". Empty if neither is set. {{- end }} {{/* -MongoDB connection string. database.mongo.url wins; otherwise, if the bundled -mongodb subchart is enabled, derived from its default standalone Service name -("-mongodb", per the alias in Chart.yaml and the Bitnami chart's -own naming convention) and mongodb.auth.rootPassword. Only called from -secret.yaml when database.mongo.existingSecret is not set. +MongoDB connection string. +database.mongo.url wins; +otherwise, if the bundled mongodb subchart is enabled, derived from its default standalone Service name +("-mongodb", per the alias in Chart.yaml and the Bitnami chart's own naming convention) and mongodb.auth.rootPassword. +Only called from secret.yaml when database.mongo.existingSecret is not set. */}} {{- define "sidelab.mongoUrl" -}} {{- if .Values.database.mongo.url -}} @@ -140,10 +140,9 @@ secret.yaml when database.mongo.existingSecret is not set. {{- end }} {{/* -JWT secret — auth.jwtSecret wins; otherwise reused from the existing Secret on -upgrade (via lookup), or freshly generated on first install. `lookup` returns -nothing outside a real cluster (e.g. `helm template`), so offline rendering -always generates a fresh value — expected, and harmless for a dry render. +JWT secret — auth.jwtSecret wins; otherwise reused from the existing Secret on upgrade (via lookup), or freshly generated on first install. +`lookup` returns nothing outside a real cluster (e.g. `helm template`), so offline rendering always generates a fresh value — +expected, and harmless for a dry render. Only called from secret.yaml when auth.existingSecret is not set. */}} {{- define "sidelab.jwtSecret" -}} @@ -180,6 +179,9 @@ Only called from secret.yaml when auth.existingSecret is not set. Validate required values and emit a clear error message. */}} {{- define "sidelab.validateValues" -}} +{{- if not .Values.image.repository }} +{{- fail "image.repository is required." }} +{{- end }} {{- if and (eq .Values.database.backend "mongo") (not .Values.database.mongo.url) (not .Values.database.mongo.existingSecret) (not .Values.mongodb.enabled) }} {{- fail "database.backend=mongo needs one of: database.mongo.url, database.mongo.existingSecret, or mongodb.enabled=true." }} {{- end }} diff --git a/charts/sidelab/templates/configmap.yaml b/charts/sidelab/templates/configmap.yaml index 57e16af..2daa943 100644 --- a/charts/sidelab/templates/configmap.yaml +++ b/charts/sidelab/templates/configmap.yaml @@ -27,9 +27,10 @@ data: K8S_INGRESS_TEMPLATE: "/app/config/ingress-template.yaml" {{- end }} K8S_NAMESPACE_PREFIX: {{ .Values.launcher.namespacePrefix | quote }} - {{- if .Values.launcher.knownNamespaces }} - K8S_KNOWN_NAMESPACES: {{ .Values.launcher.knownNamespaces | quote }} - {{- end }} + # Orphan cleanup and the restart delete-by-label fallback only scan the + # namespaces listed here — the app has no discovery of its own, so always set + # at least the seeded admin tenant's namespace. + K8S_KNOWN_NAMESPACES: {{ .Values.launcher.knownNamespaces | default (printf "%s-admin" .Values.launcher.namespacePrefix) | quote }} --- {{- if and (eq .Values.launcher.labAccess "ingress") (not .Values.launcher.ingressTemplateConfigMap) }} # Default Ingress template for lab session Pods, modeled on @@ -59,11 +60,16 @@ data: app: sidelab-lab sidelab.io/session: "{{"{{"}}SESSION_ID{{"}}"}}" sidelab.io/tenant: "{{"{{"}}TENANT{{"}}"}}" - {{- $issuer := index .Values.ingress.annotations "cert-manager.io/cluster-issuer" }} - {{- if $issuer }} annotations: + # Long-lived WebSockets (terminal, VNC) — ingress-nginx otherwise drops + # them after its 60s default proxy-read-timeout. Traefik ignores these. + nginx.ingress.kubernetes.io/proxy-read-timeout: "3600" + nginx.ingress.kubernetes.io/proxy-send-timeout: "3600" + nginx.ingress.kubernetes.io/proxy-http-version: "1.1" + {{- $issuer := index .Values.ingress.annotations "cert-manager.io/cluster-issuer" }} + {{- if $issuer }} cert-manager.io/cluster-issuer: {{ $issuer | quote }} - {{- end }} + {{- end }} spec: {{- if .Values.ingress.className }} ingressClassName: {{ .Values.ingress.className | quote }} diff --git a/charts/sidelab/templates/networkpolicy.yaml b/charts/sidelab/templates/networkpolicy.yaml index c0a4d6d..c8ab492 100644 --- a/charts/sidelab/templates/networkpolicy.yaml +++ b/charts/sidelab/templates/networkpolicy.yaml @@ -32,6 +32,16 @@ spec: ports: - port: {{ .Values.service.port }} protocol: TCP + # Allow lab pods in tenant namespaces (sidelab-) — they call the + # launcher back for token validation on lab login and on session finish. + # The launcher labels every namespace it creates with this. + - from: + - namespaceSelector: + matchLabels: + app.kubernetes.io/managed-by: sidelab + ports: + - port: {{ .Values.service.port }} + protocol: TCP {{- range .Values.networkPolicy.additionalIngressNamespaces }} - from: - namespaceSelector: diff --git a/charts/sidelab/templates/rbac.yaml b/charts/sidelab/templates/rbac.yaml index 8fd3075..481d204 100644 --- a/charts/sidelab/templates/rbac.yaml +++ b/charts/sidelab/templates/rbac.yaml @@ -1,7 +1,6 @@ -{{- if .Values.rbac.create }} -# The launcher needs cluster-scoped permissions because it creates lab Pods in -# dynamically-named tenant namespaces (sidelab-). A namespaced Role -# would require pre-creating one per tenant namespace, which defeats the purpose. +{{- if .Values.rbac.create }} +# The launcher needs cluster-scoped permissions because it creates lab Pods in dynamically-named tenant namespaces (sidelab-). +# A namespaced Role would require pre-creating one per tenant namespace, which defeats the purpose. apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: @@ -12,7 +11,7 @@ rules: # Namespace management — creates sidelab- on first lab start - apiGroups: [""] resources: ["namespaces"] - verbs: ["get", "list", "create"] + verbs: ["get", "create"] # Lab Pod lifecycle - apiGroups: [""] @@ -24,10 +23,11 @@ rules: resources: ["services"] verbs: ["get", "list", "create", "delete"] - # Per-session Secrets holding private git PATs — created and deleted per session + # Per-session Secrets holding private git PATs — created and deleted per session, never read back. + # No get/list here: on a ClusterRole that would mean read access to every Secret in the cluster. - apiGroups: [""] resources: ["secrets"] - verbs: ["get", "list", "create", "delete"] + verbs: ["create", "delete"] # Lab Ingress resources (when K8S_LAB_ACCESS=ingress) - apiGroups: ["networking.k8s.io"] diff --git a/charts/sidelab/values.yaml b/charts/sidelab/values.yaml index dddcb65..cdbdb7e 100644 --- a/charts/sidelab/values.yaml +++ b/charts/sidelab/values.yaml @@ -1,12 +1,14 @@ # ── Domain ──────────────────────────────────────────────────────────────────── -# Single source of truth for hostnames, so you don't repeat your domain in -# multiple places. Leave the two derived values below empty to use it: -# ingress.host defaults to "sidelab." (the dashboard) +# Single source of truth for hostnames, so you don't repeat your domain in multiple places. +# Leave the two derived values below empty to use it: +# ingress.host defaults to "sidelab." (the dashboard) # launcher.labDomain defaults to "labs." (lab sessions, wildcard) # Only used when left empty — set ingress.host / launcher.labDomain directly to override. domain: "" image: + # -- Required: the chart is public but the sidelab images are not published to a public registry. + # The chart fails fast at render time when unset. repository: pullPolicy: IfNotPresent # -- Defaults to .Chart.AppVersion when empty. @@ -18,30 +20,30 @@ imagePullSecrets: [] nameOverride: "" fullnameOverride: "" -# Session state (active sessions, port allocations, expiry timers) is kept -# in-memory by the launcher process — it is NOT shared across replicas and -# does NOT survive a restart. Keep this at 1 regardless of database backend; +# Session state (active sessions, port allocations, expiry timers) is kept in-memory by the launcher process — +# it is NOT shared across replicas and does NOT survive a restart. +# Keep this at 1 regardless of database backend; # this is a known upstream limitation, not a SQLite-specific one. replicaCount: 1 # ── Auth ────────────────────────────────────────────────────────────────────── auth: # -- JWT secret used to sign lab tokens and session cookies. - # Leave empty to auto-generate a strong random value on first install — it is - # then kept stable across upgrades (read back from the existing Secret). - # The app itself refuses to start in production with an unset/default secret, - # so this is not optional in practice — just easy to leave to the chart. + # Leave empty to auto-generate a strong random value on first install — it is then kept stable across upgrades (read back from the existing Secret). + # The app itself refuses to start in production with an unset/default secret, so this is not optional in practice — just easy to leave to the chart. jwtSecret: "" # Initial admin credentials — only used to seed the database when it's empty. adminUsername: "admin" - # -- Leave empty to auto-generate a strong random password on first install - # (kept stable across upgrades). Retrieve it with the command printed by - # `helm install`/`helm upgrade` (see NOTES.txt). + # -- Leave empty to auto-generate a strong random password on first install (kept stable across upgrades). + # Retrieve it with the command printed by `helm install`/`helm upgrade` (see NOTES.txt). adminPassword: "" # -- Use your own pre-created Secret instead of the two fields above. # Keys expected: JWT_SECRET, ADMIN_USERNAME, ADMIN_PASSWORD. + # GitOps note (ArgoCD/Flux): those tools render templates offline, where the auto-generate-then-reuse trick above can't look up the existing Secret — + # so every sync would rotate JWT_SECRET, logging everyone out and making stored repo tokens undecryptable. + # Under GitOps, always set this (or auth.jwtSecret). existingSecret: "" # ── Database ──────────────────────────────────────────────────────────────────── @@ -49,10 +51,8 @@ database: # -- Options: sqlite, mongo. # sqlite is the zero-dependency default — good for a quick look or a demo. # mongo is the recommended backend for anything you intend to keep around; - # point it at your own MongoDB (Atlas or self-hosted) via database.mongo.url, - # or flip on the bundled chart below for a disposable demo instance. - # There are no schema migrations on either backend (see the app's CLAUDE.md) — - # an in-place upgrade across a schema change needs a fresh database. + # point it at your own MongoDB (Atlas or self-hosted) via database.mongo.url, or flip on the bundled chart below for a disposable demo instance. + # There are no schema migrations on either backend (see the app's CLAUDE.md) — an in-place upgrade across a schema change needs a fresh database. backend: "sqlite" sqlite: @@ -149,8 +149,12 @@ launcher: # gets namespace "sidelab-admin" with the default prefix. namespacePrefix: "sidelab" - # -- Comma-separated list of namespaces to scan for orphan cleanup on startup. - # Leave empty — the launcher discovers them from the namespace prefix above. + # -- Comma-separated list of tenant namespaces the launcher scans for orphan + # cleanup on startup and for terminating sessions it lost track of across a + # restart (delete-by-label fallback). The app does NOT discover these itself — + # left empty, the chart defaults to "-admin" (the seeded + # admin tenant). List every tenant namespace here once you add tenants, + # e.g. "sidelab-admin,sidelab-acme". knownNamespaces: "" # Note: the git-clone init container used for git-sourced courses always runs @@ -254,6 +258,10 @@ podDisruptionBudget: minAvailable: 1 # ── Network Policies ───────────────────────────────────────────────────────────── +# Lab pods calling back into the launcher (token validation, session finish) are +# always allowed: the policy admits any namespace labeled +# app.kubernetes.io/managed-by=sidelab, which the launcher sets on every tenant +# namespace it creates. networkPolicy: enabled: false # -- Namespace the ingress controller runs in, allowed to reach the dashboard Service. From c97d84f63b0b0482588f8b9f935ecd6e1285a4c9 Mon Sep 17 00:00:00 2001 From: Bertrand THOMAS Date: Fri, 17 Jul 2026 02:13:46 +0200 Subject: [PATCH 2/7] sidelab: update chart for DB-backed session state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The launcher now keeps session state in the database (shared across replicas, survives restarts and rollouts — lab pods are no longer deleted on SIGTERM), discovers tenant namespaces by label, and no longer clones courses launcher-side on the kubernetes backend. - replicaCount/autoscaling/PDB comments: multi-replica is supported with database.backend=mongo (sqlite still pins to one Pod via its ReadWriteOnce PVC); the old "lost on restart" warning was stale - Deployment strategy: RollingUpdate when persistence is disabled (mongo backend, no local state), Recreate only while the RWO PVC is in play - persistence: no longer recommended for mongo — the launcher keeps no local state at all on the kubernetes backend - knownNamespaces: now optional extras; discovery uses the app.kubernetes.io/managed-by=sidelab namespace label Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01FbDMLVo9o5rFRe9T6qqTwH --- charts/sidelab/templates/deployment.yaml | 12 ++++++-- charts/sidelab/values.yaml | 35 +++++++++++++----------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/charts/sidelab/templates/deployment.yaml b/charts/sidelab/templates/deployment.yaml index d5efc56..9f512de 100644 --- a/charts/sidelab/templates/deployment.yaml +++ b/charts/sidelab/templates/deployment.yaml @@ -8,10 +8,16 @@ metadata: spec: replicas: {{ .Values.replicaCount }} strategy: - # State is on a PVC with ReadWriteOnce (SQLite file, git course cache) and - # session tracking is in-memory — keep this Recreate, not RollingUpdate, - # so two Pods never run at once. + {{- if .Values.persistence.enabled }} + # The data PVC is ReadWriteOnce (SQLite file, git course cache), so two Pods + # must never run at once — Recreate, at the cost of brief dashboard downtime + # on upgrades. Lab sessions are unaffected either way: their Pods keep + # running and the launcher reconciles from the database on the way back up. type: Recreate + {{- else }} + # No PVC (mongo backend, no local state) — roll without downtime. + type: RollingUpdate + {{- end }} selector: matchLabels: {{- include "sidelab.selectorLabels" . | nindent 6 }} diff --git a/charts/sidelab/values.yaml b/charts/sidelab/values.yaml index cdbdb7e..f6d19df 100644 --- a/charts/sidelab/values.yaml +++ b/charts/sidelab/values.yaml @@ -20,10 +20,12 @@ imagePullSecrets: [] nameOverride: "" fullnameOverride: "" -# Session state (active sessions, port allocations, expiry timers) is kept in-memory by the launcher process — -# it is NOT shared across replicas and does NOT survive a restart. -# Keep this at 1 regardless of database backend; -# this is a known upstream limitation, not a SQLite-specific one. +# Session state lives in the database (shared across replicas, survives restarts +# and rollouts — lab pods keep running while the launcher restarts). +# More than 1 replica requires database.backend=mongo: sqlite is a single local +# file on a ReadWriteOnce PVC, which pins the launcher to one Pod regardless. +# When scaling out, also prefer launcher.labAccess=ingress — nodeport lab URLs +# are built from one node's IP. replicaCount: 1 # ── Auth ────────────────────────────────────────────────────────────────────── @@ -106,8 +108,10 @@ mongodb: persistence: # -- Enable a PersistentVolumeClaim for /app/data. - # Required for the sqlite backend. Recommended for the git course cache even - # with the mongo backend, so cloned course repos survive a Pod restart. + # Required for the sqlite backend. With the mongo backend the launcher keeps no + # local state at all (lab Pods clone courses themselves in an init container), + # so this can be disabled — which also unlocks RollingUpdate deployments and + # multiple replicas (see replicaCount above). enabled: true # -- Leave empty to use the cluster default. storageClass: "" @@ -149,12 +153,11 @@ launcher: # gets namespace "sidelab-admin" with the default prefix. namespacePrefix: "sidelab" - # -- Comma-separated list of tenant namespaces the launcher scans for orphan - # cleanup on startup and for terminating sessions it lost track of across a - # restart (delete-by-label fallback). The app does NOT discover these itself — - # left empty, the chart defaults to "-admin" (the seeded - # admin tenant). List every tenant namespace here once you add tenants, - # e.g. "sidelab-admin,sidelab-acme". + # -- Extra tenant namespaces for orphan cleanup and the delete-by-label + # fallback, comma-separated. Normally leave empty: the launcher discovers + # tenant namespaces itself via the app.kubernetes.io/managed-by=sidelab label + # it puts on every namespace it creates. Only needed for namespaces created + # by hand without that label, e.g. "sidelab-legacy". knownNamespaces: "" # Note: the git-clone init container used for git-sourced courses always runs @@ -241,9 +244,8 @@ readinessProbe: failureThreshold: 3 # ── Autoscaling ────────────────────────────────────────────────────────────────── -# Not supported: session state is in-memory per Pod (see replicaCount above). -# Left here, off, only so a future multi-replica launcher doesn't need a chart -# rewrite — do not enable this today. +# Only valid with database.backend=mongo and persistence.enabled=false — the same +# conditions as replicaCount > 1 (see above). Never enable it on sqlite. autoscaling: enabled: false minReplicas: 1 @@ -252,7 +254,8 @@ autoscaling: # ── Pod Disruption Budget ──────────────────────────────────────────────────────── # Off by default: with replicaCount 1, a PDB with minAvailable=1 blocks voluntary -# node drains from ever evicting the Pod. Only turn this on if that's what you want. +# node drains from ever evicting the Pod. Makes sense once you run 2+ replicas +# on the mongo backend (see replicaCount above). podDisruptionBudget: enabled: false minAvailable: 1 From eae8ea18a4915274ad79f8331f277edaf2d237cd Mon Sep 17 00:00:00 2001 From: Bertrand THOMAS Date: Sat, 18 Jul 2026 00:37:14 +0200 Subject: [PATCH 3/7] Fix errors in charts/terraform-backend-mongodb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Critical fixes (chart is now functional) - deployment.yaml: DB connection vars renamed to DatabaseSettings__ConnectionString/DatabaseSettings__DatabaseName (matches ApplicationConfiguration.cs), with new webapi.db.connectionStringSecretKeyRef support - Application__IsSwaggerEnabled → Features__IsScalarEnabled; values.yaml field renamed enableSwagger → enableScalar - Added dotnet.httpsRedirectionEnabled (defaults false, wired to Features__IsHttpsRedirectionEnabled) Medium fixes - OTel toggle now sets the real OTEL_* env vars the auto-instrumentation agent reads (OTEL_TRACES_EXPORTER=none/otlp, OTEL_EXPORTER_OTLP_ENDPOINT, etc.) instead of dead config keys - Logging__LogLevel__Farseer → Logging__LogLevel__Devpro - webapi.tag now pins to 1.2.3 (matches Chart.yaml appVersion) instead of latest Hardening, brought in line with keeptrack - New templates/serviceaccount.yaml + security.serviceAccount.create, automountServiceAccountToken: false - security.hardened.enabled (seccomp, drop-all capabilities, read-only rootfs + /tmp emptyDir) - imagePullSecrets support - _helpers.tpl now defines commonLabels, applied across Deployment/Service/Ingress/ServiceAccount - ingress.yaml now gates on .host being set (was rendering a bogus tfbackend.random Ingress if enabled without an override) - Filled in NOTES.txt - Chart.yaml: bumped to 0.2.0, appVersion corrected to 1.2.3, added home/sources/keywords - CONTRIBUTING.md/values.mine.yaml: renamed fields, fixed stale /swagger reference → /scalar Verified with helm lint and helm template across default values, hardened+serviceAccount+imagePullSecrets+OTel-enabled+secretKeyRef, and ingress-without-host scenarios — all render correctly and match the app's actual config surface. --- .../terraform-backend-mongodb/CONTRIBUTING.md | 9 +- charts/terraform-backend-mongodb/Chart.yaml | 10 +- .../templates/NOTES.txt | 29 ++++++ .../templates/_helpers.tpl | 17 ++++ .../templates/deployment.yaml | 96 +++++++++++++++---- .../templates/ingress.yaml | 6 +- .../templates/service.yaml | 1 + .../templates/serviceaccount.yaml | 14 +++ charts/terraform-backend-mongodb/values.yaml | 39 +++++++- 9 files changed, 189 insertions(+), 32 deletions(-) create mode 100644 charts/terraform-backend-mongodb/templates/serviceaccount.yaml diff --git a/charts/terraform-backend-mongodb/CONTRIBUTING.md b/charts/terraform-backend-mongodb/CONTRIBUTING.md index 77046d1..8de50c5 100644 --- a/charts/terraform-backend-mongodb/CONTRIBUTING.md +++ b/charts/terraform-backend-mongodb/CONTRIBUTING.md @@ -30,8 +30,9 @@ Create a `values.mine.yaml` file: ```yaml dotnet: environment: Development - enableSwagger: true - enableOpenTelemetry: false + enableScalar: true + openTelemetry: + enabled: false ingress: enabled: true className: traefik @@ -56,10 +57,10 @@ helm upgrade --install tfbackend . \ --namespace tfbackend --create-namespace ``` -Open application Swagger in a browser. +Open the Scalar API reference in a browser. ```bash -echo https://tfbckmdb.console.$SANDBOX_ID.instruqt.io/swagger +echo https://tfbckmdb.console.$SANDBOX_ID.instruqt.io/scalar ``` Create admin: diff --git a/charts/terraform-backend-mongodb/Chart.yaml b/charts/terraform-backend-mongodb/Chart.yaml index a8456b1..9bbce39 100644 --- a/charts/terraform-backend-mongodb/Chart.yaml +++ b/charts/terraform-backend-mongodb/Chart.yaml @@ -2,8 +2,14 @@ apiVersion: v2 name: terraform-backend-mongodb description: Helm chart for Terraform Backend MongoDB type: application -version: 0.1.2 -appVersion: "1.2.0" +version: 0.2.0 +appVersion: "1.2.3" +home: https://github.com/devpro/terraform-backend-mongodb +sources: + - https://github.com/devpro/terraform-backend-mongodb +keywords: + - terraform + - mongodb dependencies: - name: mongodb version: 18.1.10 # MongoDB 8.2.2 diff --git a/charts/terraform-backend-mongodb/templates/NOTES.txt b/charts/terraform-backend-mongodb/templates/NOTES.txt index e69de29..8208289 100644 --- a/charts/terraform-backend-mongodb/templates/NOTES.txt +++ b/charts/terraform-backend-mongodb/templates/NOTES.txt @@ -0,0 +1,29 @@ +Terraform Backend MongoDB has been deployed. + +{{- if .Values.ingress.enabled }} +{{- if .Values.webapi.enabled }} +Web API: + https://{{ .Values.webapi.host }} +{{- end }} +{{- else }} +Ingress is disabled - reach the app via `kubectl port-forward` or your own ingress/gateway pointed +at the {{ .Values.webapi.name }} Service. +{{- end }} + +{{- if not .Values.mongodb.enabled }} + +MongoDB is not managed by this chart (mongodb.enabled=false) - make sure webapi.db.connectionString +(or webapi.db.connectionStringSecretKeyRef) points at a reachable, already-provisioned instance. +{{- end }} + +Check the rollout: + kubectl get pods -n {{ .Release.Namespace }} -l app.kubernetes.io/instance={{ .Release.Name }} + +Create a user (there is no in-app way to do this - see CONTRIBUTING.md): + MONGODB_URI= ./tfbeadm create-user + +{{- if not .Values.security.hardened.enabled }} + +Note: security.hardened.enabled is false. Turn it on once validated in this environment to run with +a read-only root filesystem, all Linux capabilities dropped, and the default seccomp profile. +{{- end }} diff --git a/charts/terraform-backend-mongodb/templates/_helpers.tpl b/charts/terraform-backend-mongodb/templates/_helpers.tpl index e69de29..d68c5d3 100644 --- a/charts/terraform-backend-mongodb/templates/_helpers.tpl +++ b/charts/terraform-backend-mongodb/templates/_helpers.tpl @@ -0,0 +1,17 @@ +{{/* +Recommended Kubernetes labels (https://helm.sh/docs/chart_best_practices/labels/), added on top of +the app-specific `app` / `app.kubernetes.io/name` labels every template already sets directly. +These are informational only - never add them to a Deployment's spec.selector.matchLabels, which +is immutable and would break `helm upgrade` for existing releases. +Call with a dict: (dict "app" . "root" $) where "." is the current webapi values entry. +*/}} +{{- define "terraform-backend-mongodb.commonLabels" -}} +helm.sh/chart: {{ printf "%s-%s" .root.Chart.Name .root.Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +app.kubernetes.io/version: {{ .root.Chart.AppVersion | quote }} +app.kubernetes.io/managed-by: {{ .root.Release.Service }} +app.kubernetes.io/instance: {{ .root.Release.Name }} +app.kubernetes.io/part-of: terraform-backend-mongodb +{{- if .app.role }} +app.kubernetes.io/component: {{ .app.role }} +{{- end }} +{{- end -}} diff --git a/charts/terraform-backend-mongodb/templates/deployment.yaml b/charts/terraform-backend-mongodb/templates/deployment.yaml index cb67347..5c39a1e 100644 --- a/charts/terraform-backend-mongodb/templates/deployment.yaml +++ b/charts/terraform-backend-mongodb/templates/deployment.yaml @@ -10,6 +10,7 @@ metadata: labels: app: {{ .name }} app.kubernetes.io/name: {{ .name }} + {{- include "terraform-backend-mongodb.commonLabels" (dict "app" . "root" $) | nindent 4 }} spec: replicas: {{ .replicaCount }} strategy: @@ -23,6 +24,7 @@ spec: labels: app: {{ $name }} app.kubernetes.io/name: {{ $name }} + {{- include "terraform-backend-mongodb.commonLabels" (dict "app" . "root" $) | nindent 8 }} {{- if .additionalPodLabels }} {{- toYaml .additionalPodLabels | nindent 8 }} {{- end }} @@ -35,6 +37,21 @@ spec: - key: "kubernetes.io/arch" operator: In values: ["amd64"] + {{- if $.Values.security.serviceAccount.create }} + serviceAccountName: {{ .name }} + {{- else }} + serviceAccountName: default + {{- end }} + automountServiceAccountToken: false + {{- with $.Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- if $.Values.security.hardened.enabled }} + securityContext: + seccompProfile: + type: RuntimeDefault + {{- end }} containers: - name: {{ .name }} image: {{ .image }}:{{ .tag }} @@ -58,7 +75,21 @@ spec: runAsUser: 1654 # "app" user runAsGroup: 1654 # "app" group allowPrivilegeEscalation: false + {{- if $.Values.security.hardened.enabled }} + readOnlyRootFilesystem: true + capabilities: + drop: ["ALL"] + {{- end }} + {{- if $.Values.security.hardened.enabled }} + volumeMounts: + - name: tmp + mountPath: /tmp + {{- end }} env: + {{- if $.Values.security.hardened.enabled }} + - name: HOME + value: /tmp + {{- end }} {{- if .extraEnv }} {{- toYaml .extraEnv | nindent 12 }} {{- end }} @@ -67,33 +98,56 @@ spec: fieldRef: apiVersion: v1 fieldPath: status.hostIP - # TODO: only add this variables when needed and manage http calls - name: ASPNETCORE_ENVIRONMENT value: "{{ $.Values.dotnet.environment }}" - name: Logging__LogLevel__Default - value: {{ $.Values.dotnet.logLevels.default }} + value: {{ $.Values.dotnet.logLevels.default | quote }} - name: Logging__LogLevel__Microsoft.AspNetCore - value: {{ $.Values.dotnet.logLevels.framework }} - - name: Logging__LogLevel__Farseer - value: {{ $.Values.dotnet.logLevels.application }} - {{- if $.Values.dotnet.enableSwagger }} - - name: Application__IsSwaggerEnabled - value: "true" + value: {{ $.Values.dotnet.logLevels.framework | quote }} + - name: Logging__LogLevel__Devpro + value: {{ $.Values.dotnet.logLevels.application | quote }} + - name: Features__IsHttpsRedirectionEnabled + value: {{ $.Values.dotnet.httpsRedirectionEnabled | quote }} + - name: Features__IsScalarEnabled + value: {{ $.Values.dotnet.enableScalar | quote }} + {{- if $.Values.dotnet.openTelemetry.enabled }} + - name: OTEL_SERVICE_NAME + value: {{ $.Values.dotnet.openTelemetry.serviceName | default .name | quote }} + - name: OTEL_TRACES_EXPORTER + value: "otlp" + - name: OTEL_METRICS_EXPORTER + value: "otlp" + - name: OTEL_LOGS_EXPORTER + value: "otlp" + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: {{ $.Values.dotnet.openTelemetry.endpoint | quote }} + - name: OTEL_EXPORTER_OTLP_PROTOCOL + value: {{ $.Values.dotnet.openTelemetry.protocol | quote }} + {{- else }} + - name: OTEL_TRACES_EXPORTER + value: "none" + - name: OTEL_METRICS_EXPORTER + value: "none" + - name: OTEL_LOGS_EXPORTER + value: "none" {{- end }} - {{- if $.Values.dotnet.enableOpenTelemetry }} - - name: Application__IsOpenTelemetryEnabled - value: "true" - - name: OpenTelemetry__CollectorEndpoint - value: "http://$(HOST_IP):4317" - {{- end }} - {{- if .db }} - - name: ConnectionStrings__MongoDb - value: {{ .db.connectionString }} - - name: MongoDb__ConnectionStringName - value: "MongoDb" - - name: MongoDb__DatabaseName - value: {{ .db.databaseName }} + {{- if .db.connectionStringSecretKeyRef }} + - name: DatabaseSettings__ConnectionString + valueFrom: + secretKeyRef: + name: {{ .db.connectionStringSecretKeyRef.name }} + key: {{ .db.connectionStringSecretKeyRef.key }} + {{- else }} + - name: DatabaseSettings__ConnectionString + value: {{ .db.connectionString | quote }} {{- end }} + - name: DatabaseSettings__DatabaseName + value: {{ .db.databaseName | quote }} restartPolicy: Always + {{- if $.Values.security.hardened.enabled }} + volumes: + - name: tmp + emptyDir: {} + {{- end }} {{- end }} {{ end }} diff --git a/charts/terraform-backend-mongodb/templates/ingress.yaml b/charts/terraform-backend-mongodb/templates/ingress.yaml index 002a815..63f7ef9 100644 --- a/charts/terraform-backend-mongodb/templates/ingress.yaml +++ b/charts/terraform-backend-mongodb/templates/ingress.yaml @@ -1,12 +1,16 @@ {{- $applications := list .Values.webapi -}} {{ range $applications }} {{- $name := .name -}} -{{- if and $.Values.ingress.enabled .enabled -}} +{{- if and $.Values.ingress.enabled .enabled .host -}} --- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: {{ $name }} + labels: + app: {{ $name }} + app.kubernetes.io/name: {{ $name }} + {{- include "terraform-backend-mongodb.commonLabels" (dict "app" . "root" $) | nindent 4 }} {{- with $.Values.ingress.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/charts/terraform-backend-mongodb/templates/service.yaml b/charts/terraform-backend-mongodb/templates/service.yaml index 27e5b7d..3a0316d 100644 --- a/charts/terraform-backend-mongodb/templates/service.yaml +++ b/charts/terraform-backend-mongodb/templates/service.yaml @@ -8,6 +8,7 @@ metadata: labels: app: {{ .name }} app.kubernetes.io/name: {{ .name }} + {{- include "terraform-backend-mongodb.commonLabels" (dict "app" . "root" $) | nindent 4 }} name: {{ .name }} spec: type: ClusterIP diff --git a/charts/terraform-backend-mongodb/templates/serviceaccount.yaml b/charts/terraform-backend-mongodb/templates/serviceaccount.yaml new file mode 100644 index 0000000..d44aa1c --- /dev/null +++ b/charts/terraform-backend-mongodb/templates/serviceaccount.yaml @@ -0,0 +1,14 @@ +{{- if .Values.security.serviceAccount.create }} +{{- $applications := list .Values.webapi -}} +{{ range $applications }} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ .name }} + labels: + app: {{ .name }} + app.kubernetes.io/name: {{ .name }} + {{- include "terraform-backend-mongodb.commonLabels" (dict "app" . "root" $) | nindent 4 }} +automountServiceAccountToken: false +{{ end }} +{{- end }} diff --git a/charts/terraform-backend-mongodb/values.yaml b/charts/terraform-backend-mongodb/values.yaml index 36bd8c7..5754a0f 100644 --- a/charts/terraform-backend-mongodb/values.yaml +++ b/charts/terraform-backend-mongodb/values.yaml @@ -1,15 +1,19 @@ webapi: enabled: true - host: tfbackend.random + host: "" name: tfbackend image: docker.io/devprofr/terraform-backend-mongodb # images are hosted on DockerHub: https://hub.docker.com/r/devprofr/terraform-backend-mongodb/tags - tag: latest # IMPORTANT: latest should never be used in Production + tag: "1.2.3" # pins to Chart.yaml appVersion - avoid floating tags (e.g. latest) in Production replicaCount: 1 port: 80 containerPort: 8080 healthEndpoint: /health db: + # important: connectionString or connectionStringSecretKeyRef must be provided + # connectionStringSecretKeyRef: + # name: "" + # key: "" connectionString: "someconnstring" databaseName: "somedb" extraEnv: [] @@ -32,8 +36,34 @@ dotnet: default: Information framework: Information application: Information - enableSwagger: false - enableOpenTelemetry: false + enableScalar: false + # false by default: the app redirects to HTTPS internally, which fights a TLS-terminating ingress + # that forwards plain HTTP to the pod. + httpsRedirectionEnabled: false + # The app image always ships with .NET auto-instrumentation baked in (see Dockerfile); these settings + # only control the standard OTEL_* exporter env vars the agent reads - they don't turn the agent itself + # on or off. When disabled, exporters are set to "none" so the agent doesn't try to reach a collector. + openTelemetry: + enabled: false + # defaults to webapi.name when empty + serviceName: "" + # OTLP collector endpoint, e.g. http://otel-collector:4318 + endpoint: "" + protocol: "http/protobuf" + +# optional: image registry credentials, e.g. for a private mirror of the image above +imagePullSecrets: [] + # - name: my-registry-secret + +security: + serviceAccount: + create: false + # Hardened container settings for platforms that mandate the Kubernetes Pod Security Standards "restricted" profile (or an equivalent CIS benchmark policy): + # seccompProfile, dropping all Linux capabilities, and a read-only root filesystem. Disabled by default - + # readOnlyRootFilesystem needs to be validated against each environment before being turned on broadly + # (it redirects HOME to an emptyDir-backed /tmp so .NET's own writes keep working). + hardened: + enabled: false ingress: enabled: false @@ -57,3 +87,4 @@ mongodb: tag: latest # IMPORTANT: latest should never be used in Production auth: {} # rootPassword: "" + # existingSecret: "" From 1545c14cd8c2541b15379323b99a34193e340d08 Mon Sep 17 00:00:00 2001 From: Bertrand THOMAS Date: Sat, 18 Jul 2026 00:38:37 +0200 Subject: [PATCH 4/7] Create Helm chart for liveship MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modeled on sidelab (closest shape: single app + optional bundled MongoDB) with keeptrack conventions where relevant: - Full template set: deployment, service, ingress, configmap, secrets, serviceaccount, HPA, PDB, NOTES.txt, plus README, CONTRIBUTING, ci/ci-values.yaml for ct lint. - Image: defaults to ghcr.io/devpro/liveship per your note; values and README document that imagePullSecrets is required while the GHCR package is private. - Secrets: NEXTAUTH_SECRET and ENCRYPTION_KEY auto-generate on first install and are reused across upgrades (sidelab's lookup pattern). The generated key is guaranteed 64-hex (randAlphaNum 64 | sha256sum), and a user-supplied key is validated at render time. The GitOps rotation warning is stronger here than sidelab's, since a rotated ENCRYPTION_KEY makes stored connection credentials permanently undecryptable — NOTES.txt tells you to back it up. - Database: database.uri / database.existingSecret / bundled Bitnami mongodb subchart (same 18.6.16 dependency; the tgz was copied from sidelab because Bitnami's registry 401s on that version now — noted in CONTRIBUTING). database.name defaults to terraform_backend so it shares data with terraform-backend-mongodb out of the box. - NEXTAUTH_URL is derived from the ingress host+TLS automatically (wrong value breaks login, so the chart owns it), overridable via auth.url. - Probes hit /login — the app has no health endpoint (see below). - Verified: helm lint clean, full renders inspected, all four fail-fast validations produce clear messages, yamllint output byte-for-byte matches sidelab's warnings (so CI will pass), helm dependency list reports ok. --- charts/liveship/.helmignore | 9 + charts/liveship/CONTRIBUTING.md | 64 +++++ charts/liveship/Chart.lock | 6 + charts/liveship/Chart.yaml | 25 ++ charts/liveship/README.md | 61 +++++ charts/liveship/ci/ci-values.yaml | 2 + charts/liveship/templates/NOTES.txt | 86 +++++++ charts/liveship/templates/_helpers.tpl | 181 ++++++++++++++ charts/liveship/templates/configmap.yaml | 16 ++ charts/liveship/templates/deployment.yaml | 109 ++++++++ charts/liveship/templates/hpa.yaml | 23 ++ charts/liveship/templates/ingress.yaml | 35 +++ charts/liveship/templates/pdb.yaml | 14 ++ charts/liveship/templates/secret.yaml | 29 +++ charts/liveship/templates/service.yaml | 19 ++ charts/liveship/templates/serviceaccount.yaml | 13 + charts/liveship/values.yaml | 235 ++++++++++++++++++ 17 files changed, 927 insertions(+) create mode 100644 charts/liveship/.helmignore create mode 100644 charts/liveship/CONTRIBUTING.md create mode 100644 charts/liveship/Chart.lock create mode 100644 charts/liveship/Chart.yaml create mode 100644 charts/liveship/README.md create mode 100644 charts/liveship/ci/ci-values.yaml create mode 100644 charts/liveship/templates/NOTES.txt create mode 100644 charts/liveship/templates/_helpers.tpl create mode 100644 charts/liveship/templates/configmap.yaml create mode 100644 charts/liveship/templates/deployment.yaml create mode 100644 charts/liveship/templates/hpa.yaml create mode 100644 charts/liveship/templates/ingress.yaml create mode 100644 charts/liveship/templates/pdb.yaml create mode 100644 charts/liveship/templates/secret.yaml create mode 100644 charts/liveship/templates/service.yaml create mode 100644 charts/liveship/templates/serviceaccount.yaml create mode 100644 charts/liveship/values.yaml diff --git a/charts/liveship/.helmignore b/charts/liveship/.helmignore new file mode 100644 index 0000000..bfaad30 --- /dev/null +++ b/charts/liveship/.helmignore @@ -0,0 +1,9 @@ +.git/ +.gitignore +.helmignore +*.orig +*.swp +*.bak +values.mine.yaml +temp*.yaml +kubeconfig diff --git a/charts/liveship/CONTRIBUTING.md b/charts/liveship/CONTRIBUTING.md new file mode 100644 index 0000000..3443a5e --- /dev/null +++ b/charts/liveship/CONTRIBUTING.md @@ -0,0 +1,64 @@ +# Contribution guide + +## Update chart dependencies + +Add the Bitnami Helm repository: + +```bash +helm repo add bitnami https://charts.bitnami.com/bitnami +helm repo update +``` + +Look for existing versions: + +```bash +helm search repo -l mongodb --versions +``` + +Manually edit `Chart.yaml` with the version. + +Update `Chart.lock` and fetch the archive into `charts/` (gitignored, rebuilt from `Chart.lock` by anyone who needs it): + +```bash +helm dependency update . +``` + +Note: Bitnami's index currently redirects some downloads to `oci://registry-1.docker.io/bitnamicharts`, which can fail with a 401 for older versions. +The same `mongodb-18.6.16.tgz` is used by the sidelab and keeptrack charts — copying it from a sibling `charts/` directory is a valid workaround as long as the version matches. + +## Review the generated manifest + +```bash +helm template liveship . -f values.yaml -f values.mine.yaml --namespace liveship --debug > temp.yaml +``` + +Useful sanity checks on the output: `helm template liveship .` with nothing set must fail fast asking for a database; +`--set mongodb.enabled=true` alone must fail asking for `mongodb.auth.rootPassword`; +`--set ingress.enabled=true` without a host, or an `auth.encryptionKey` that isn't 64 hex characters, must fail with a clear message rather than render something broken. + +## Validate on a local cluster + +The image is private on GHCR for now — create the pull secret first: + +```bash +kubectl create secret docker-registry ghcr-pull -n liveship \ + --docker-server=ghcr.io --docker-username= --docker-password= +``` + +Then a minimal `values.mine.yaml` for a demo install: + +```yaml +imagePullSecrets: + - name: ghcr-pull +mongodb: + enabled: true + auth: + rootPassword: "change-me" +``` + +```bash +helm upgrade --install liveship . -f values.mine.yaml --namespace liveship --create-namespace +``` + +Follow the printed NOTES.txt to seed the first admin user and port-forward to the app. +Verify login works end-to-end (that exercises MongoDB, `NEXTAUTH_SECRET`, and `NEXTAUTH_URL` at once), then create a connection and re-open it after `kubectl rollout restart` (that exercises `ENCRYPTION_KEY` stability). diff --git a/charts/liveship/Chart.lock b/charts/liveship/Chart.lock new file mode 100644 index 0000000..bcbdd1b --- /dev/null +++ b/charts/liveship/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: mongodb + repository: https://charts.bitnami.com/bitnami + version: 18.6.16 +digest: sha256:889cbf07e49e630d28dc8a1c72fdd0465f3f0f0c1601b3be559940108bb50ab2 +generated: "2026-07-11T01:36:26.300038311+02:00" diff --git a/charts/liveship/Chart.yaml b/charts/liveship/Chart.yaml new file mode 100644 index 0000000..5b034ba --- /dev/null +++ b/charts/liveship/Chart.yaml @@ -0,0 +1,25 @@ +apiVersion: v2 +name: liveship +description: > + One platform for an organization's infrastructure, security posture, and code. + Deploys the Liveship application, which reads the same MongoDB database terraform-backend-mongodb writes to. +type: application +version: 0.1.0 +appVersion: "0.1.0" +keywords: + - liveship + - infrastructure + - kubernetes + - terraform +home: https://github.com/devpro/helm-charts +sources: + - https://github.com/devpro/liveship +dependencies: + - name: mongodb + version: 18.6.16 # MongoDB 8.2.6 + repository: https://charts.bitnami.com/bitnami + alias: mongodb + condition: mongodb.enabled +maintainers: + - name: devpro + email: bertrand@devpro.fr diff --git a/charts/liveship/README.md b/charts/liveship/README.md new file mode 100644 index 0000000..76677f5 --- /dev/null +++ b/charts/liveship/README.md @@ -0,0 +1,61 @@ +# Liveship Helm Chart + +Helm chart for [Liveship](https://github.com/devpro/liveship) — one platform for an organization's infrastructure, security posture, and code. +Deploys the Liveship application (Next.js + MongoDB), which reads the same database [terraform-backend-mongodb](../terraform-backend-mongodb) writes to — point both charts at the same MongoDB to get the Terraform state views. + +`values.yaml` is the source of truth for every option — it's fully commented. + +## Quick Start + +Add the chart repository: + +```bash +helm repo add devpro https://devpro.github.io/helm-charts +helm repo update +``` + +Create a `values.yaml` file to override [default values](values.yaml). +Two things are always required: + +- **Image pull credentials** — the `ghcr.io/devpro/liveship` image is private for now: + + ```bash + kubectl create secret docker-registry ghcr-pull -n liveship \ + --docker-server=ghcr.io --docker-username= --docker-password= + ``` + + then set `imagePullSecrets: [{name: ghcr-pull}]`. +- **A MongoDB** — one of `database.uri`, `database.existingSecret`, or `mongodb.enabled=true` (bundled demo instance; also set `mongodb.auth.rootPassword`). + The chart fails fast at render time when none is set. + +Install the application: + +```bash +helm upgrade --install liveship devpro/liveship -f values.yaml --namespace liveship --create-namespace +``` + +`NEXTAUTH_SECRET` and `ENCRYPTION_KEY` are auto-generated on first install and kept stable across upgrades. +Under GitOps (ArgoCD/Flux), set `auth.existingSecret` instead — offline rendering would rotate them on every sync, and a rotated `ENCRYPTION_KEY` makes stored connection credentials permanently undecryptable (see `values.yaml`). + +The first admin user is seeded with the `seed-admin.mjs` script from the liveship repo — `helm install` prints the exact commands (NOTES.txt). + +## Scaling & high availability + +The app is stateless and scales horizontally with no extra configuration: set `replicaCount` (or `autoscaling.enabled=true`), optionally with `podDisruptionBudget.enabled=true`. + +What makes this safe (verified against the app's source): + +- Sessions are stateless NextAuth JWT cookies — any replica can validate any user's cookie, since all replicas share the chart's single `NEXTAUTH_SECRET`. + No sticky sessions needed. +- All application state and every cache (Kubernetes resource-type discovery, git repository cache, login lockout counters) live in MongoDB, shared by all replicas. +- Stored credentials are encrypted with the shared `ENCRYPTION_KEY` env var — every replica can decrypt what any other stored. +- Nothing is written to the local filesystem, and there are no in-process background jobs to run twice. + +## Uninstall + +```bash +helm uninstall liveship -n liveship +kubectl delete namespace liveship +``` + +The auto-generated `-auth` Secret is deleted along with the namespace — its `ENCRYPTION_KEY` is the only way to decrypt stored connection credentials, so back it up first if the database outlives the release. diff --git a/charts/liveship/ci/ci-values.yaml b/charts/liveship/ci/ci-values.yaml new file mode 100644 index 0000000..2fcf3bf --- /dev/null +++ b/charts/liveship/ci/ci-values.yaml @@ -0,0 +1,2 @@ +database: + uri: mongodb://ci-dummy-mongo:27017 diff --git a/charts/liveship/templates/NOTES.txt b/charts/liveship/templates/NOTES.txt new file mode 100644 index 0000000..6528be7 --- /dev/null +++ b/charts/liveship/templates/NOTES.txt @@ -0,0 +1,86 @@ +🎉 Liveship has been deployed! + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + Application URL +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +{{- if .Values.ingress.enabled }} + {{ include "liveship.nextauthUrl" . }} +{{- if .Values.ingress.tls.enabled }} + + The TLS certificate is issued automatically by cert-manager, if configured + via a cert-manager.io/cluster-issuer annotation. Allow 1-2 minutes for it + to become ready: + + kubectl get certificate -n {{ .Release.Namespace }} -w +{{- end }} +{{- else }} + Port-forward to access the app locally: + + kubectl port-forward -n {{ .Release.Namespace }} \ + svc/{{ include "liveship.fullname" . }} 3000:{{ .Values.service.port }} + + Then open: http://localhost:3000 + (NEXTAUTH_URL defaults to exactly that, so login works out of the box — + see auth.url in values.yaml before putting this behind a real hostname.) +{{- end }} + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + First login +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + The app has no built-in signup — the first global_admin user is seeded + directly into MongoDB with the seed script from the liveship repo: + +{{- if and .Values.mongodb.enabled (not .Values.database.uri) (not .Values.database.existingSecret) }} + + kubectl port-forward -n {{ .Release.Namespace }} svc/{{ .Release.Name }}-mongodb 27017:27017 + + then, from a checkout of https://github.com/devpro/liveship: + + MONGODB_URI='mongodb://root:@localhost:27017/?authSource=admin' \ + MONGODB_DB='{{ .Values.database.name }}' \ + node scripts/seed-admin.mjs --username admin --password +{{- else }} + + From a checkout of https://github.com/devpro/liveship, pointed at the + same MongoDB this release uses: + + MONGODB_URI='' MONGODB_DB='{{ .Values.database.name }}' \ + node scripts/seed-admin.mjs --username admin --password + + Not needed if terraform-backend-mongodb (or a previous install) already + seeded users into this database — they log straight in. +{{- end }} + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + Back up the encryption key +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +{{- if .Values.auth.existingSecret }} + Managed by you, in Secret/{{ .Values.auth.existingSecret }} (key ENCRYPTION_KEY). +{{- else }} + ENCRYPTION_KEY encrypts every stored connection credential (cloud keys, + cluster tokens, registry passwords). If the Secret is lost, that data is + permanently undecryptable. Save a copy somewhere safe: + + kubectl get secret -n {{ .Release.Namespace }} {{ include "liveship.authSecretName" . }} \ + -o jsonpath='{.data.ENCRYPTION_KEY}' | base64 -d; echo +{{- end }} + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + Database +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + Database: {{ .Values.database.name }} +{{- if and .Values.mongodb.enabled (not .Values.database.uri) (not .Values.database.existingSecret) }} + Using the bundled MongoDB chart — fine for a demo, not backed up. Point + database.uri at a real MongoDB before you rely on this data. +{{- end }} + Terraform state views expect terraform-backend-mongodb writing to this + same database — point both charts at the same instance. + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + Useful commands +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + # Watch the app Pods + kubectl get pods -n {{ .Release.Namespace }} -l app.kubernetes.io/instance={{ .Release.Name }} -w + + # Tail app logs + kubectl logs -n {{ .Release.Namespace }} -l app.kubernetes.io/instance={{ .Release.Name }} -f diff --git a/charts/liveship/templates/_helpers.tpl b/charts/liveship/templates/_helpers.tpl new file mode 100644 index 0000000..a262265 --- /dev/null +++ b/charts/liveship/templates/_helpers.tpl @@ -0,0 +1,181 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "liveship.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +Truncated to 63 chars because some Kubernetes name fields have this limit. +*/}} +{{- define "liveship.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 label value (name + version). +*/}} +{{- define "liveship.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels applied to all resources. +*/}} +{{- define "liveship.labels" -}} +helm.sh/chart: {{ include "liveship.chart" . }} +{{ include "liveship.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels (used by Service and Deployment). +*/}} +{{- define "liveship.selectorLabels" -}} +app.kubernetes.io/name: {{ include "liveship.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +ServiceAccount name. +*/}} +{{- define "liveship.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "liveship.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{/* +Name of the auth Secret (NEXTAUTH_SECRET / ENCRYPTION_KEY keys). +*/}} +{{- define "liveship.authSecretName" -}} +{{- if .Values.auth.existingSecret }} +{{- .Values.auth.existingSecret }} +{{- else }} +{{- printf "%s-auth" (include "liveship.fullname" .) }} +{{- end }} +{{- end }} + +{{/* +Name of the MongoDB connection Secret (MONGODB_URI key). +*/}} +{{- define "liveship.mongoSecretName" -}} +{{- if .Values.database.existingSecret }} +{{- .Values.database.existingSecret }} +{{- else }} +{{- printf "%s-mongo" (include "liveship.fullname" .) }} +{{- end }} +{{- end }} + +{{/* +Image tag — falls back to .Chart.AppVersion. +*/}} +{{- define "liveship.imageTag" -}} +{{- .Values.image.tag | default .Chart.AppVersion }} +{{- end }} + +{{/* +External URL of the app (NEXTAUTH_URL). auth.url wins; otherwise derived from +the ingress host and TLS setting; otherwise localhost:3000, which matches the +kubectl port-forward instructions in NOTES.txt (NextAuth builds every +login/callback redirect from this value, so it has to be what the browser uses). +*/}} +{{- define "liveship.nextauthUrl" -}} +{{- if .Values.auth.url -}} +{{- .Values.auth.url -}} +{{- else if and .Values.ingress.enabled .Values.ingress.host -}} +{{- printf "http%s://%s" (ternary "s" "" .Values.ingress.tls.enabled) .Values.ingress.host -}} +{{- else -}} +http://localhost:3000 +{{- end -}} +{{- end }} + +{{/* +MongoDB connection string. +database.uri wins; +otherwise, if the bundled mongodb subchart is enabled, derived from its default standalone Service name +("-mongodb", per the alias in Chart.yaml and the Bitnami chart's own naming convention) and mongodb.auth.rootPassword. +The database itself is selected by MONGODB_DB (database.name), not the URI path. +Only called from secret.yaml when database.existingSecret is not set. +*/}} +{{- define "liveship.mongoUri" -}} +{{- if .Values.database.uri -}} +{{- .Values.database.uri -}} +{{- else if .Values.mongodb.enabled -}} +{{- printf "mongodb://root:%s@%s-mongodb:27017/?authSource=admin" .Values.mongodb.auth.rootPassword .Release.Name -}} +{{- end -}} +{{- end }} + +{{/* +NextAuth secret — auth.nextauthSecret wins; otherwise reused from the existing Secret on upgrade (via lookup), or freshly generated on first install. +`lookup` returns nothing outside a real cluster (e.g. `helm template`), so offline rendering always generates a fresh value — +expected, and harmless for a dry render. +Only called from secret.yaml when auth.existingSecret is not set. +*/}} +{{- define "liveship.nextauthSecret" -}} +{{- if .Values.auth.nextauthSecret -}} +{{- .Values.auth.nextauthSecret -}} +{{- else -}} +{{- $existing := lookup "v1" "Secret" .Release.Namespace (include "liveship.authSecretName" .) -}} +{{- if and $existing $existing.data (hasKey $existing.data "NEXTAUTH_SECRET") -}} +{{- index $existing.data "NEXTAUTH_SECRET" | b64dec -}} +{{- else -}} +{{- randAlphaNum 48 -}} +{{- end -}} +{{- end -}} +{{- end }} + +{{/* +Encryption key — same reuse-then-generate pattern as liveship.nextauthSecret above, +except the generated value must be exactly 64 hex characters (the app enforces +a 32-byte hex key): sha256sum of a random string gives exactly that. +Only called from secret.yaml when auth.existingSecret is not set. +*/}} +{{- define "liveship.encryptionKey" -}} +{{- if .Values.auth.encryptionKey -}} +{{- .Values.auth.encryptionKey -}} +{{- else -}} +{{- $existing := lookup "v1" "Secret" .Release.Namespace (include "liveship.authSecretName" .) -}} +{{- if and $existing $existing.data (hasKey $existing.data "ENCRYPTION_KEY") -}} +{{- index $existing.data "ENCRYPTION_KEY" | b64dec -}} +{{- else -}} +{{- randAlphaNum 64 | sha256sum -}} +{{- end -}} +{{- end -}} +{{- end }} + +{{/* +Validate required values and emit a clear error message. +*/}} +{{- define "liveship.validateValues" -}} +{{- if not .Values.image.repository }} +{{- fail "image.repository is required." }} +{{- end }} +{{- if and (not .Values.database.uri) (not .Values.database.existingSecret) (not .Values.mongodb.enabled) }} +{{- fail "A MongoDB is required: set one of database.uri, database.existingSecret, or mongodb.enabled=true." }} +{{- end }} +{{- if and .Values.mongodb.enabled (not .Values.database.uri) (not .Values.database.existingSecret) (not .Values.mongodb.auth.rootPassword) }} +{{- fail "mongodb.auth.rootPassword is required when mongodb.enabled=true (unless database.uri or database.existingSecret is set instead)." }} +{{- end }} +{{- if and .Values.ingress.enabled (not .Values.ingress.host) }} +{{- fail "ingress.host is required when ingress.enabled=true." }} +{{- end }} +{{- if and .Values.auth.encryptionKey (not (regexMatch "^[0-9a-fA-F]{64}$" .Values.auth.encryptionKey)) }} +{{- fail "auth.encryptionKey must be exactly 64 hex characters (openssl rand -hex 32) — the app refuses any other shape at startup." }} +{{- end }} +{{- end }} diff --git a/charts/liveship/templates/configmap.yaml b/charts/liveship/templates/configmap.yaml new file mode 100644 index 0000000..a999969 --- /dev/null +++ b/charts/liveship/templates/configmap.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "liveship.fullname" . }}-config + namespace: {{ .Release.Namespace }} + labels: + {{- include "liveship.labels" . | nindent 4 }} +data: + MONGODB_DB: {{ .Values.database.name | quote }} + # What the browser uses to reach the app — NextAuth builds login/callback + # redirects from this, so a wrong value breaks sign-in, not just links. + NEXTAUTH_URL: {{ include "liveship.nextauthUrl" . | quote }} + {{- if .Values.otel.endpoint }} + OTEL_EXPORTER_OTLP_ENDPOINT: {{ .Values.otel.endpoint | quote }} + OTEL_SERVICE_NAME: {{ .Values.otel.serviceName | quote }} + {{- end }} diff --git a/charts/liveship/templates/deployment.yaml b/charts/liveship/templates/deployment.yaml new file mode 100644 index 0000000..919fd10 --- /dev/null +++ b/charts/liveship/templates/deployment.yaml @@ -0,0 +1,109 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "liveship.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "liveship.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + strategy: + # No local state at all (see the replicaCount note in values.yaml) — + # always safe to roll without downtime. + type: RollingUpdate + selector: + matchLabels: + {{- include "liveship.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "liveship.selectorLabels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + annotations: + # forces a rollout when the rendered ConfigMap/Secret content changes, + # even if the image tag doesn't — env vars are only read at container + # start, so Kubernetes won't otherwise notice a ConfigMap/Secret edit. + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} + checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }} + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "liveship.serviceAccountName" . }} + automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }} + restartPolicy: Always + {{- if .Values.podSecurityContext }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + {{- end }} + containers: + - name: liveship + image: "{{ .Values.image.repository }}:{{ include "liveship.imageTag" . }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + {{- if .Values.containerSecurityContext }} + securityContext: + {{- toYaml .Values.containerSecurityContext | nindent 12 }} + {{- end }} + ports: + - name: http + containerPort: 3000 + protocol: TCP + envFrom: + - configMapRef: + name: {{ include "liveship.fullname" . }}-config + # The Secrets' keys match the app's env var names exactly + # (envFrom has no per-key rename). + - secretRef: + name: {{ include "liveship.authSecretName" . }} + - secretRef: + name: {{ include "liveship.mongoSecretName" . }} + {{- with .Values.extraEnv }} + env: + {{- toYaml . | nindent 12 }} + {{- end }} + livenessProbe: + {{- toYaml .Values.livenessProbe | nindent 12 }} + readinessProbe: + {{- toYaml .Values.readinessProbe | nindent 12 }} + {{- if .Values.resources }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- end }} + volumeMounts: + # Writable /tmp and Next.js runtime cache (image optimizer etc.) — + # both emptyDirs, so containerSecurityContext.readOnlyRootFilesystem + # can be enabled without further changes. Per-Pod caches, not shared + # state: nothing the app relies on across replicas or restarts. + - name: tmp + mountPath: /tmp + - name: next-cache + mountPath: /app/.next/cache + {{- with .Values.extraVolumeMounts }} + {{- toYaml . | nindent 12 }} + {{- end }} + volumes: + - name: tmp + emptyDir: {} + - name: next-cache + emptyDir: {} + {{- with .Values.extraVolumes }} + {{- 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/charts/liveship/templates/hpa.yaml b/charts/liveship/templates/hpa.yaml new file mode 100644 index 0000000..b161f66 --- /dev/null +++ b/charts/liveship/templates/hpa.yaml @@ -0,0 +1,23 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "liveship.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "liveship.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "liveship.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} +{{- end }} diff --git a/charts/liveship/templates/ingress.yaml b/charts/liveship/templates/ingress.yaml new file mode 100644 index 0000000..2c5a6c6 --- /dev/null +++ b/charts/liveship/templates/ingress.yaml @@ -0,0 +1,35 @@ +{{- if .Values.ingress.enabled }} +{{- include "liveship.validateValues" . }} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "liveship.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "liveship.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if .Values.ingress.className }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls.enabled }} + tls: + - hosts: + - {{ .Values.ingress.host | quote }} + secretName: {{ .Values.ingress.tls.secretName }} + {{- end }} + rules: + - host: {{ .Values.ingress.host | quote }} + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: {{ include "liveship.fullname" . }} + port: + name: http +{{- end }} diff --git a/charts/liveship/templates/pdb.yaml b/charts/liveship/templates/pdb.yaml new file mode 100644 index 0000000..b503b66 --- /dev/null +++ b/charts/liveship/templates/pdb.yaml @@ -0,0 +1,14 @@ +{{- if .Values.podDisruptionBudget.enabled }} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ include "liveship.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "liveship.labels" . | nindent 4 }} +spec: + minAvailable: {{ .Values.podDisruptionBudget.minAvailable }} + selector: + matchLabels: + {{- include "liveship.selectorLabels" . | nindent 6 }} +{{- end }} diff --git a/charts/liveship/templates/secret.yaml b/charts/liveship/templates/secret.yaml new file mode 100644 index 0000000..cd71341 --- /dev/null +++ b/charts/liveship/templates/secret.yaml @@ -0,0 +1,29 @@ +{{- include "liveship.validateValues" . }} +{{- if not .Values.auth.existingSecret }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "liveship.authSecretName" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "liveship.labels" . | nindent 4 }} +type: Opaque +stringData: + NEXTAUTH_SECRET: {{ include "liveship.nextauthSecret" . | quote }} + # Losing this key makes every stored connection credential undecryptable — + # see the warning on auth.encryptionKey in values.yaml. + ENCRYPTION_KEY: {{ include "liveship.encryptionKey" . | quote }} +{{- end }} +{{- if not .Values.database.existingSecret }} +--- +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "liveship.mongoSecretName" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "liveship.labels" . | nindent 4 }} +type: Opaque +stringData: + MONGODB_URI: {{ include "liveship.mongoUri" . | quote }} +{{- end }} diff --git a/charts/liveship/templates/service.yaml b/charts/liveship/templates/service.yaml new file mode 100644 index 0000000..5071233 --- /dev/null +++ b/charts/liveship/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "liveship.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "liveship.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + {{- if and (eq .Values.service.type "NodePort") .Values.service.nodePort }} + nodePort: {{ .Values.service.nodePort }} + {{- end }} + selector: + {{- include "liveship.selectorLabels" . | nindent 4 }} diff --git a/charts/liveship/templates/serviceaccount.yaml b/charts/liveship/templates/serviceaccount.yaml new file mode 100644 index 0000000..e89de37 --- /dev/null +++ b/charts/liveship/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create }} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "liveship.serviceAccountName" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "liveship.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/liveship/values.yaml b/charts/liveship/values.yaml new file mode 100644 index 0000000..c6988e1 --- /dev/null +++ b/charts/liveship/values.yaml @@ -0,0 +1,235 @@ +# ── Image ───────────────────────────────────────────────────────────────────── +image: + # The liveship image is published to GitHub Container Registry as a private + # package for now — set imagePullSecrets below with GHCR credentials + # (a PAT with read:packages) or the pull will fail with ImagePullBackOff. + repository: ghcr.io/devpro/liveship + pullPolicy: IfNotPresent + # -- Defaults to .Chart.AppVersion when empty. + tag: "" + +# -- Required while the GHCR image is private, e.g.: +# kubectl create secret docker-registry ghcr-pull \ +# --docker-server=ghcr.io --docker-username= --docker-password= +imagePullSecrets: [] + # - name: ghcr-pull + +nameOverride: "" +fullnameOverride: "" + +# The app is stateless by design: sessions are JWT cookies (NextAuth), every +# cache (Kubernetes resource-type discovery, git repository cache) lives in +# MongoDB, and nothing is written to the local filesystem. Scaling out needs +# nothing beyond raising this — all replicas just have to share the same +# NEXTAUTH_SECRET and ENCRYPTION_KEY, which the chart's single Secret already +# guarantees. See also autoscaling and podDisruptionBudget below. +replicaCount: 1 + +# ── Auth & encryption ───────────────────────────────────────────────────────── +auth: + # -- NextAuth JWT signing secret (NEXTAUTH_SECRET). + # Leave empty to auto-generate a strong random value on first install — it is then kept stable across upgrades (read back from the existing Secret). + # Rotating it logs every user out (their session cookies stop validating) but loses no data. + nextauthSecret: "" + + # -- AES-256-GCM key encrypting stored connection credentials at rest (ENCRYPTION_KEY) — cloud provider keys, cluster tokens, registry passwords. + # Must be exactly 64 hex characters (openssl rand -hex 32); the chart fails at render time otherwise. + # Leave empty to auto-generate on first install (kept stable across upgrades). + # WARNING: unlike nextauthSecret, losing or rotating this key makes every stored credential permanently undecryptable — + # every connection would have to be re-entered by hand. Back up the Secret (see NOTES.txt after install). + encryptionKey: "" + + # -- External URL of the app (NEXTAUTH_URL) — what users type in their browser. + # Leave empty to derive it from the ingress section below ("https://"), + # falling back to "http://localhost:3000" (fine for kubectl port-forward) when the ingress is disabled. + url: "" + + # -- Use your own pre-created Secret instead of the two secret fields above. + # Keys expected: NEXTAUTH_SECRET, ENCRYPTION_KEY. + # GitOps note (ArgoCD/Flux): those tools render templates offline, where the auto-generate-then-reuse trick above can't look up the existing Secret — + # so every sync would rotate both values, and a rotated ENCRYPTION_KEY makes stored credentials undecryptable (see the warning above). + # Under GitOps, always set this (or both fields explicitly). + existingSecret: "" + +# ── Database ────────────────────────────────────────────────────────────────── +# Liveship reads the same MongoDB database terraform-backend-mongodb writes to +# (tf_state, tf_state_lock, user, tenant collections) — point both charts at +# the same instance and database name to get the Terraform state views. +database: + # -- Full MongoDB connection string, e.g. mongodb+srv://user:pass@cluster.mongodb.net + # (database selection is via database.name below, not the URI path). + # Not needed if mongodb.enabled=true below — the chart wires that up for you. + uri: "" + + # -- Database name (MONGODB_DB). The app's own default; matches what + # terraform-backend-mongodb uses so the two share data out of the box. + name: "terraform_backend" + + # -- Use your own pre-created Secret instead of database.uri. + # Key expected: MONGODB_URI. Takes priority over database.uri and over the + # bundled mongodb chart below. + existingSecret: "" + +# ── Bundled MongoDB (optional, for a quick disposable demo) ─────────────────── +# Deploys https://github.com/bitnami/charts/blob/main/bitnami/mongodb/values.yaml +# as a subchart alongside the app. Off by default — prefer a real, backed-up +# MongoDB (Atlas or self-hosted) for anything you care about; this is +# uncomfortable to lose, since it's just another Pod with a PVC, not a managed +# database. +# +# When enabled, the chart auto-builds database.uri's connection string from +# mongodb.auth.rootPassword — set that one field and the wiring is automatic. +# database.uri / database.existingSecret, if set, always take priority over +# this (so you can point at an external Mongo even with an unrelated +# mongodb.enabled=true left over from testing). +mongodb: + enabled: false + architecture: standalone + auth: + enabled: true + # -- Required when mongodb.enabled=true, unless database.uri or + # database.existingSecret is set instead. + # This is intentionally not auto-generated: the same value has to reach + # both this subchart's own root user AND the app's connection string, + # and Helm cannot pass a chart-generated value into a subchart's values. + rootPassword: "" + image: + registry: docker.io + repository: bitnami/mongodb # other options: chainguard/mongodb + tag: latest # IMPORTANT: latest should never be used in production + persistence: + enabled: true + size: 4Gi + global: + security: + allowInsecureImages: true + # -- Uncomment to point the subchart at a specific cluster storage class. + # global: + # defaultStorageClass: "" + +# ── OpenTelemetry (optional) ────────────────────────────────────────────────── +otel: + # -- OTLP collector endpoint, e.g. "http://otel-collector:4318". + # Leave empty to disable tracing/log export entirely (the app checks this + # exact variable). All standard OTEL_* env vars are honoured — use extraEnv + # below for the less common ones (OTEL_EXPORTER_OTLP_HEADERS, etc.). + endpoint: "" + serviceName: "liveship" + +# ── Service ─────────────────────────────────────────────────────────────────── +service: + # -- ClusterIP, NodePort, or LoadBalancer. + type: ClusterIP + port: 3000 + # -- Only used when service.type=NodePort. Leave empty to let Kubernetes pick one. + nodePort: "" + +# ── Ingress ─────────────────────────────────────────────────────────────────── +ingress: + # -- Off by default so a first install doesn't need an ingress controller. + enabled: false + # -- e.g. "public" or "nginx" for MicroK8s' bundled ingress-nginx, "traefik" for Traefik. + className: "" + # -- Hostname for the app, e.g. "liveship.example.com". Required when enabled. + host: "" + annotations: {} + # cert-manager.io/cluster-issuer: "letsencrypt-prod" + # traefik.ingress.kubernetes.io/router.entrypoints: websecure + # traefik.ingress.kubernetes.io/router.tls: "true" + tls: + # -- Requests a certificate automatically when a cert-manager ClusterIssuer + # annotation is present above. + enabled: false + secretName: "liveship-tls" + +# ── Security ────────────────────────────────────────────────────────────────── +# The image already runs as a dedicated non-root user (uid 1001, "nextjs") — +# the contexts below are extra hardening for clusters that mandate it +# explicitly, off by default so the chart runs unmodified on a plain cluster. +podSecurityContext: {} + # runAsNonRoot: true + # runAsUser: 1001 + # runAsGroup: 1001 + # seccompProfile: + # type: RuntimeDefault + +containerSecurityContext: {} + # allowPrivilegeEscalation: false + # readOnlyRootFilesystem: true + # capabilities: + # drop: + # - ALL + +# ── Resources ───────────────────────────────────────────────────────────────── +resources: {} + # requests: + # cpu: 100m + # memory: 256Mi + # limits: + # cpu: 500m + # memory: 512Mi + +# ── Probes ──────────────────────────────────────────────────────────────────── +# The app has no dedicated /healthz route — /login is served unauthenticated +# (everything else redirects there, which probes also accept) and proves the +# server is up and rendering. +livenessProbe: + httpGet: + path: /login + port: http + initialDelaySeconds: 15 + periodSeconds: 20 + failureThreshold: 3 + +readinessProbe: + httpGet: + path: /login + port: http + initialDelaySeconds: 5 + periodSeconds: 10 + failureThreshold: 3 + +# ── Autoscaling ─────────────────────────────────────────────────────────────── +# Safe to enable as-is — see the replicaCount note above for why multiple +# replicas need no extra configuration. +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 3 + targetCPUUtilizationPercentage: 80 + +# ── Pod Disruption Budget ───────────────────────────────────────────────────── +# Off by default: with replicaCount 1, a PDB with minAvailable=1 blocks +# voluntary node drains from ever evicting the Pod. Makes sense once you run +# 2+ replicas. +podDisruptionBudget: + enabled: false + minAvailable: 1 + +# ── ServiceAccount ──────────────────────────────────────────────────────────── +serviceAccount: + create: true + annotations: {} + # -- Defaults to the chart's fullname. + name: "" + # -- The app never talks to its own cluster's API — Kubernetes clusters are + # browsed through credentials stored in the app, so the Pod needs no token. + automountServiceAccountToken: false + +# ── Scheduling ──────────────────────────────────────────────────────────────── +nodeSelector: {} +tolerations: [] +affinity: {} + +podAnnotations: {} +podLabels: {} + +# ── Extra environment variables passed to the app container ─────────────────── +# Example: +# extraEnv: +# - name: OTEL_EXPORTER_OTLP_HEADERS +# value: "authorization=Bearer xyz" +extraEnv: [] + +extraVolumes: [] +extraVolumeMounts: [] From 03dddd784707770baa4c6ace913981349572effe Mon Sep 17 00:00:00 2001 From: Bertrand THOMAS Date: Sat, 18 Jul 2026 01:23:38 +0200 Subject: [PATCH 5/7] Update terraform-backend-mongodb chart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closed all 5 remaining gaps, following the sidelab/liveship patterns: 1. Mongo URL auto-wiring — new terraform-backend-mongodb.mongoConnectionString helper (_helpers.tpl): derives mongodb://root:@-mongodb:27017/?authSource=admin when mongodb.enabled=true. values.mine.yaml/CONTRIBUTING.md simplified to drop the now-unnecessary hand-written connection string. 2. Fail-fast validation — new terraform-backend-mongodb.validateValues helper, called from secret.yaml and ingress.yaml. Placeholder defaults (someconnstring) removed; an unconfigured DB, a mongodb.enabled=true without rootPassword, or ingress.enabled=true without webapi.host now abort the render with a clear Error: instead of producing a broken manifest. 3. fullname prefixing — new helper prefixes webapi.name with the release name (unless already contained), applied to every resource name and selector label (Deployment, Service, Ingress, ServiceAccount, Secret). Two releases with default values no longer collide; the documented helm install tfbackend ... case is unchanged (release name already equals the default app name). 4. Optional nodeAffinity — moved from a hardcoded template block to webapi.affinity in values.yaml (defaults preserved: amd64-only, since the OTel native library is amd64-only), overridable/clearable per install. 5. Real Secret for the connection string — new templates/secret.yaml. By default DatabaseSettings__ConnectionString is now always sourced via secretKeyRef, never a plain env value: either the user's own pre-created Secret (connectionStringSecretKeyRef) or a Secret the chart manages itself (populated from connectionString or the Mongo auto-wiring above). Plus documentation (per your last note) — added a "Database connection" section to README.md covering all three ways to supply the DB credential, in priority order, with working examples for each (verified each snippet against helm template output). Chart version bumped to 0.3.0. Verified with helm lint/helm template: all three fail-fast error paths fire correctly, the three documented connection paths render as described, fullname prefixing works under both matching and differing release names, and clearing webapi.affinity removes the block entirely. --- .../terraform-backend-mongodb/CONTRIBUTING.md | 2 +- charts/terraform-backend-mongodb/Chart.yaml | 2 +- charts/terraform-backend-mongodb/README.md | 64 +++++++++++++++++++ .../templates/NOTES.txt | 4 ++ .../templates/_helpers.tpl | 48 ++++++++++++++ .../templates/deployment.yaml | 34 +++++----- .../templates/ingress.yaml | 15 +++-- .../templates/secret.yaml | 18 ++++++ .../templates/service.yaml | 10 +-- .../templates/serviceaccount.yaml | 6 +- charts/terraform-backend-mongodb/values.yaml | 28 +++++++- 11 files changed, 193 insertions(+), 38 deletions(-) create mode 100644 charts/terraform-backend-mongodb/templates/secret.yaml diff --git a/charts/terraform-backend-mongodb/CONTRIBUTING.md b/charts/terraform-backend-mongodb/CONTRIBUTING.md index 8de50c5..76a7248 100644 --- a/charts/terraform-backend-mongodb/CONTRIBUTING.md +++ b/charts/terraform-backend-mongodb/CONTRIBUTING.md @@ -44,7 +44,7 @@ mongodb: rootPassword: admin webapi: db: - connectionString: mongodb://root:admin@tfbackend-mongodb:27017/tfbackend_beta?authSource=admin + # connectionString is auto-wired from mongodb.auth.rootPassword above databaseName: tfbackend_beta ``` diff --git a/charts/terraform-backend-mongodb/Chart.yaml b/charts/terraform-backend-mongodb/Chart.yaml index 9bbce39..6fb12c7 100644 --- a/charts/terraform-backend-mongodb/Chart.yaml +++ b/charts/terraform-backend-mongodb/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: terraform-backend-mongodb description: Helm chart for Terraform Backend MongoDB type: application -version: 0.2.0 +version: 0.3.0 appVersion: "1.2.3" home: https://github.com/devpro/terraform-backend-mongodb sources: diff --git a/charts/terraform-backend-mongodb/README.md b/charts/terraform-backend-mongodb/README.md index de47826..2be1042 100644 --- a/charts/terraform-backend-mongodb/README.md +++ b/charts/terraform-backend-mongodb/README.md @@ -23,6 +23,70 @@ Install the application: helm upgrade --install tfbackend devpro/terraform-backend-mongodb -f values.yaml --namespace tfbackend --create-namespace ``` +## Database connection + +The chart never renders the MongoDB connection string as a plain environment variable in the +Deployment - `DatabaseSettings__ConnectionString` is always sourced from a Secret via `secretKeyRef`. +Pick one of the three ways below to provide it; they're evaluated in this priority order: +`webapi.db.connectionStringSecretKeyRef` > `webapi.db.connectionString` > the bundled `mongodb` +subchart. + +### Option 1 - your own MongoDB, connection string in a pre-created Secret (recommended for Production) + +Create the Secret yourself (`kubectl create secret`, External Secrets Operator, Sealed Secrets, or +your GitOps tool's secret management) with a key holding the full connection string, then point the +chart at it. The chart neither reads nor creates a Secret of its own in this case - the plaintext +value never appears in your values files or in Helm's release history: + +```bash +kubectl create secret generic tfbackend-db \ + --namespace tfbackend \ + --from-literal=connectionString='mongodb+srv://user:pass@cluster.mongodb.net' +``` + +```yaml +webapi: + db: + databaseName: "tfbackend" + connectionStringSecretKeyRef: + name: tfbackend-db + key: connectionString +``` + +### Option 2 - your own MongoDB, connection string as a chart value + +Point `webapi.db.connectionString` at a reachable, already-provisioned instance. The chart still puts +it in a Secret it manages (never directly in the Deployment's env) - but the plaintext value is still +visible in your values file and in `helm get values`/Helm's release history, so prefer Option 1 for +Production credentials: + +```yaml +webapi: + db: + connectionString: "mongodb+srv://user:pass@cluster.mongodb.net" + databaseName: "tfbackend" +``` + +### Option 3 - bundled MongoDB (auto-wired, good for demos/testing) + +Enable the bundled `mongodb` subchart and set its root password; the chart derives the connection +string for you and stores it in the same chart-managed Secret as Option 2. Leave +`webapi.db.connectionString`/`connectionStringSecretKeyRef` empty: + +```yaml +mongodb: + enabled: true + auth: + rootPassword: "changeme" +``` + +Not recommended for anything you care about keeping - it's just another Pod with a PVC, not a +managed/backed-up database. The exact Secret name is printed in `NOTES.txt` after install. + +If none of the three is configured, or `mongodb.enabled=true` is set without `mongodb.auth.rootPassword`, +the chart fails at render/install time with a clear error instead of deploying a Pod that can't reach +a database. + ## Going further Check the [contribution guide](CONTRIBUTING.md). diff --git a/charts/terraform-backend-mongodb/templates/NOTES.txt b/charts/terraform-backend-mongodb/templates/NOTES.txt index 8208289..3599d09 100644 --- a/charts/terraform-backend-mongodb/templates/NOTES.txt +++ b/charts/terraform-backend-mongodb/templates/NOTES.txt @@ -14,6 +14,10 @@ at the {{ .Values.webapi.name }} Service. MongoDB is not managed by this chart (mongodb.enabled=false) - make sure webapi.db.connectionString (or webapi.db.connectionStringSecretKeyRef) points at a reachable, already-provisioned instance. +{{- else }} + +MongoDB is managed by this chart (mongodb.enabled=true) - the webapi connection string was +auto-derived from mongodb.auth.rootPassword and stored in the {{ include "terraform-backend-mongodb.fullname" (dict "app" .Values.webapi "root" $) }}-db Secret. {{- end }} Check the rollout: diff --git a/charts/terraform-backend-mongodb/templates/_helpers.tpl b/charts/terraform-backend-mongodb/templates/_helpers.tpl index d68c5d3..b64b201 100644 --- a/charts/terraform-backend-mongodb/templates/_helpers.tpl +++ b/charts/terraform-backend-mongodb/templates/_helpers.tpl @@ -15,3 +15,51 @@ app.kubernetes.io/part-of: terraform-backend-mongodb app.kubernetes.io/component: {{ .app.role }} {{- end }} {{- end -}} + +{{/* +Fully-qualified resource name for an application entry (webapi). Prefixes the app's own `.name` +(e.g. "tfbackend") with the release name, unless `.name` already contains it - so two releases in the +same namespace that both leave `.name` at its default don't collide on Deployment/Service/Ingress/ +ServiceAccount names (or on their selector labels, which use the same value). +Call with a dict: (dict "app" . "root" $) where "." is the current webapi values entry. +*/}} +{{- define "terraform-backend-mongodb.fullname" -}} +{{- if contains .app.name .root.Release.Name -}} +{{- .root.Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .root.Release.Name .app.name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} + +{{/* +MongoDB connection string. +webapi.db.connectionString wins; otherwise, if the bundled mongodb subchart is enabled, derived from +its default standalone Service name ("-mongodb", per the alias in Chart.yaml and the +Bitnami chart's own naming convention) and mongodb.auth.rootPassword. +Only called from secret.yaml when webapi.db.connectionStringSecretKeyRef is not set. +*/}} +{{- define "terraform-backend-mongodb.mongoConnectionString" -}} +{{- if .Values.webapi.db.connectionString -}} +{{- .Values.webapi.db.connectionString -}} +{{- else if .Values.mongodb.enabled -}} +{{- printf "mongodb://root:%s@%s-mongodb:27017/?authSource=admin" .Values.mongodb.auth.rootPassword .Release.Name -}} +{{- end -}} +{{- end -}} + +{{/* +Validate required values and emit a clear error message instead of silently rendering a placeholder +or a broken manifest. +*/}} +{{- define "terraform-backend-mongodb.validateValues" -}} +{{- if .Values.webapi.enabled }} +{{- if and (not .Values.webapi.db.connectionString) (not .Values.webapi.db.connectionStringSecretKeyRef) (not .Values.mongodb.enabled) }} +{{- fail "A MongoDB connection is required: set webapi.db.connectionString, webapi.db.connectionStringSecretKeyRef, or mongodb.enabled=true." }} +{{- end }} +{{- if and .Values.mongodb.enabled (not .Values.webapi.db.connectionString) (not .Values.webapi.db.connectionStringSecretKeyRef) (not .Values.mongodb.auth.rootPassword) }} +{{- fail "mongodb.auth.rootPassword is required when mongodb.enabled=true (unless webapi.db.connectionString or webapi.db.connectionStringSecretKeyRef is set instead)." }} +{{- end }} +{{- if and .Values.ingress.enabled (not .Values.webapi.host) }} +{{- fail "webapi.host is required when ingress.enabled=true." }} +{{- end }} +{{- end }} +{{- end -}} diff --git a/charts/terraform-backend-mongodb/templates/deployment.yaml b/charts/terraform-backend-mongodb/templates/deployment.yaml index 5c39a1e..0fa7628 100644 --- a/charts/terraform-backend-mongodb/templates/deployment.yaml +++ b/charts/terraform-backend-mongodb/templates/deployment.yaml @@ -1,15 +1,14 @@ {{- $applications := list .Values.webapi -}} {{ range $applications }} -{{- $name := .name -}} {{- if .enabled -}} --- apiVersion: apps/v1 kind: Deployment metadata: - name: {{ .name }} + name: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} labels: - app: {{ .name }} - app.kubernetes.io/name: {{ .name }} + app: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} + app.kubernetes.io/name: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} {{- include "terraform-backend-mongodb.commonLabels" (dict "app" . "root" $) | nindent 4 }} spec: replicas: {{ .replicaCount }} @@ -17,28 +16,24 @@ spec: type: RollingUpdate selector: matchLabels: - app: {{ .name }} - app.kubernetes.io/name: {{ .name }} + app: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} + app.kubernetes.io/name: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} template: metadata: labels: - app: {{ $name }} - app.kubernetes.io/name: {{ $name }} + app: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} + app.kubernetes.io/name: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} {{- include "terraform-backend-mongodb.commonLabels" (dict "app" . "root" $) | nindent 8 }} {{- if .additionalPodLabels }} {{- toYaml .additionalPodLabels | nindent 8 }} {{- end }} spec: + {{- with .affinity }} affinity: - nodeAffinity: - requiredDuringSchedulingIgnoredDuringExecution: - nodeSelectorTerms: - - matchExpressions: - - key: "kubernetes.io/arch" - operator: In - values: ["amd64"] + {{- toYaml . | nindent 8 }} + {{- end }} {{- if $.Values.security.serviceAccount.create }} - serviceAccountName: {{ .name }} + serviceAccountName: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} {{- else }} serviceAccountName: default {{- end }} @@ -112,7 +107,7 @@ spec: value: {{ $.Values.dotnet.enableScalar | quote }} {{- if $.Values.dotnet.openTelemetry.enabled }} - name: OTEL_SERVICE_NAME - value: {{ $.Values.dotnet.openTelemetry.serviceName | default .name | quote }} + value: {{ $.Values.dotnet.openTelemetry.serviceName | default (include "terraform-backend-mongodb.fullname" (dict "app" . "root" $)) | quote }} - name: OTEL_TRACES_EXPORTER value: "otlp" - name: OTEL_METRICS_EXPORTER @@ -139,7 +134,10 @@ spec: key: {{ .db.connectionStringSecretKeyRef.key }} {{- else }} - name: DatabaseSettings__ConnectionString - value: {{ .db.connectionString | quote }} + valueFrom: + secretKeyRef: + name: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }}-db + key: connectionString {{- end }} - name: DatabaseSettings__DatabaseName value: {{ .db.databaseName | quote }} diff --git a/charts/terraform-backend-mongodb/templates/ingress.yaml b/charts/terraform-backend-mongodb/templates/ingress.yaml index 63f7ef9..11c7ca9 100644 --- a/charts/terraform-backend-mongodb/templates/ingress.yaml +++ b/charts/terraform-backend-mongodb/templates/ingress.yaml @@ -1,15 +1,16 @@ {{- $applications := list .Values.webapi -}} {{ range $applications }} -{{- $name := .name -}} -{{- if and $.Values.ingress.enabled .enabled .host -}} +{{- $app := . -}} +{{- if and $.Values.ingress.enabled .enabled -}} +{{- include "terraform-backend-mongodb.validateValues" $ }} --- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: {{ $name }} + name: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} labels: - app: {{ $name }} - app.kubernetes.io/name: {{ $name }} + app: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} + app.kubernetes.io/name: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} {{- include "terraform-backend-mongodb.commonLabels" (dict "app" . "root" $) | nindent 4 }} {{- with $.Values.ingress.annotations }} annotations: @@ -27,7 +28,7 @@ spec: pathType: Prefix backend: service: - name: {{ $name }} + name: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} port: number: {{ .port }} {{- range .ingressExtraHosts }} @@ -39,7 +40,7 @@ spec: pathType: {{ .pathType }} backend: service: - name: {{ $name }} + name: {{ include "terraform-backend-mongodb.fullname" (dict "app" $app "root" $) }} port: number: {{ .port }} {{- end }} diff --git a/charts/terraform-backend-mongodb/templates/secret.yaml b/charts/terraform-backend-mongodb/templates/secret.yaml new file mode 100644 index 0000000..cf50f48 --- /dev/null +++ b/charts/terraform-backend-mongodb/templates/secret.yaml @@ -0,0 +1,18 @@ +{{- include "terraform-backend-mongodb.validateValues" . }} +{{- $applications := list .Values.webapi -}} +{{ range $applications }} +{{- if and .enabled (not .db.connectionStringSecretKeyRef) -}} +--- +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }}-db + labels: + app: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} + app.kubernetes.io/name: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} + {{- include "terraform-backend-mongodb.commonLabels" (dict "app" . "root" $) | nindent 4 }} +type: Opaque +stringData: + connectionString: {{ include "terraform-backend-mongodb.mongoConnectionString" $ | quote }} +{{- end }} +{{ end }} diff --git a/charts/terraform-backend-mongodb/templates/service.yaml b/charts/terraform-backend-mongodb/templates/service.yaml index 3a0316d..fbbad7b 100644 --- a/charts/terraform-backend-mongodb/templates/service.yaml +++ b/charts/terraform-backend-mongodb/templates/service.yaml @@ -6,10 +6,10 @@ apiVersion: v1 kind: Service metadata: labels: - app: {{ .name }} - app.kubernetes.io/name: {{ .name }} + app: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} + app.kubernetes.io/name: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} {{- include "terraform-backend-mongodb.commonLabels" (dict "app" . "root" $) | nindent 4 }} - name: {{ .name }} + name: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} spec: type: ClusterIP ports: @@ -18,7 +18,7 @@ spec: protocol: TCP name: http selector: - app: {{ .name }} - app.kubernetes.io/name: {{ .name }} + app: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} + app.kubernetes.io/name: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} {{- end }} {{ end }} diff --git a/charts/terraform-backend-mongodb/templates/serviceaccount.yaml b/charts/terraform-backend-mongodb/templates/serviceaccount.yaml index d44aa1c..c6d945f 100644 --- a/charts/terraform-backend-mongodb/templates/serviceaccount.yaml +++ b/charts/terraform-backend-mongodb/templates/serviceaccount.yaml @@ -4,10 +4,10 @@ apiVersion: v1 kind: ServiceAccount metadata: - name: {{ .name }} + name: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} labels: - app: {{ .name }} - app.kubernetes.io/name: {{ .name }} + app: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} + app.kubernetes.io/name: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} {{- include "terraform-backend-mongodb.commonLabels" (dict "app" . "root" $) | nindent 4 }} automountServiceAccountToken: false {{ end }} diff --git a/charts/terraform-backend-mongodb/values.yaml b/charts/terraform-backend-mongodb/values.yaml index 5754a0f..7a233d1 100644 --- a/charts/terraform-backend-mongodb/values.yaml +++ b/charts/terraform-backend-mongodb/values.yaml @@ -10,12 +10,17 @@ webapi: containerPort: 8080 healthEndpoint: /health db: - # important: connectionString or connectionStringSecretKeyRef must be provided + # -- Full MongoDB connection string, e.g. mongodb://user:pass@host:27017/?authSource=admin + # Not needed if mongodb.enabled=true below - the chart wires that up for you from + # mongodb.auth.rootPassword. The chart always stores this in a Secret (never rendered as a + # plain env var in the Deployment) unless connectionStringSecretKeyRef below is set instead. + connectionString: "" + # -- Use your own pre-created Secret instead of connectionString above. + # Takes priority over connectionString and over the bundled mongodb chart below. # connectionStringSecretKeyRef: # name: "" # key: "" - connectionString: "someconnstring" - databaseName: "somedb" + databaseName: "tfbackend" extraEnv: [] # - name: xxx # value: "yyyy" @@ -29,6 +34,18 @@ webapi: # requests: # cpu: 100m # memory: 64Mi + # -- Pod affinity/anti-affinity/node-affinity rules, passed through as-is. + # Defaults to requiring amd64 nodes: the image's baked-in OpenTelemetry auto-instrumentation + # native library (see Dockerfile) is amd64-only, so an arm64 node would fail to load the + # profiler. Clear this (affinity: {}) once/if an arm64-compatible image is published. + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: "kubernetes.io/arch" + operator: In + values: ["amd64"] dotnet: environment: Production @@ -86,5 +103,10 @@ mongodb: repository: bitnami/mongodb # other options: chainguard/mongodb tag: latest # IMPORTANT: latest should never be used in Production auth: {} + # -- Required when mongodb.enabled=true, unless webapi.db.connectionString or + # webapi.db.connectionStringSecretKeyRef is set instead. This is intentionally not + # auto-generated: the same value has to reach both this subchart's own root user AND + # the webapi connection string, and Helm cannot pass a chart-generated value into a + # subchart's values. # rootPassword: "" # existingSecret: "" From e113f043a6b8ccb1ee04f6fe4deb489132d0b0fa Mon Sep 17 00:00:00 2001 From: Bertrand THOMAS Date: Sun, 19 Jul 2026 12:22:25 +0200 Subject: [PATCH 6/7] Add Google Books API token for keeptrack chart Bump chart version to 0.2.3 --- charts/keeptrack/CONTRIBUTING.md | 5 +++++ charts/keeptrack/Chart.yaml | 6 +++--- charts/keeptrack/templates/deployment.yaml | 10 ++++++++++ charts/keeptrack/values.yaml | 9 +++++++-- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/charts/keeptrack/CONTRIBUTING.md b/charts/keeptrack/CONTRIBUTING.md index 1d9dcf5..9e8b355 100644 --- a/charts/keeptrack/CONTRIBUTING.md +++ b/charts/keeptrack/CONTRIBUTING.md @@ -42,6 +42,7 @@ kubectl create secret generic keeptrack-app \ --from-literal=tmdbapikey='***' \ --from-literal=rawgapikey='***' \ --from-literal=discogstoken='***' \ + --from-literal=googlebooksApiKey='***' \ --namespace demo ``` @@ -90,6 +91,10 @@ webapi: tokenSecretKeyRef: name: keeptrack-app key: discogstoken + googlebooks: + apiKeySecretKeyRef: + name: keeptrack-app + key: googlebooksApiKey ingress: enabled: true diff --git a/charts/keeptrack/Chart.yaml b/charts/keeptrack/Chart.yaml index 8da017f..3d516fb 100644 --- a/charts/keeptrack/Chart.yaml +++ b/charts/keeptrack/Chart.yaml @@ -1,9 +1,9 @@ -apiVersion: v2 +apiVersion: v2 name: keeptrack description: Helm chart for Keeptrack type: application -version: 0.2.2 -appVersion: "2.1" +version: 0.2.3 +appVersion: "2.3" home: https://github.com/devpro/keeptrack sources: - https://github.com/devpro/keeptrack diff --git a/charts/keeptrack/templates/deployment.yaml b/charts/keeptrack/templates/deployment.yaml index a016cd9..6cece97 100644 --- a/charts/keeptrack/templates/deployment.yaml +++ b/charts/keeptrack/templates/deployment.yaml @@ -245,6 +245,16 @@ spec: - name: Discogs__Token value: {{ .referenceData.discogs.token | quote }} {{- end }} + {{- if .referenceData.googlebooks.apiKeySecretKeyRef }} + - name: GoogleBooks__ApiKey + valueFrom: + secretKeyRef: + name: {{ .referenceData.googlebooks.apiKeySecretKeyRef.name }} + key: {{ .referenceData.googlebooks.apiKeySecretKeyRef.key }} + {{- else }} + - name: GoogleBooks__ApiKey + value: {{ .referenceData.googlebooks.apiKey | quote }} + {{- end }} {{- end }} restartPolicy: Always {{- if $.Values.security.hardened.enabled }} diff --git a/charts/keeptrack/values.yaml b/charts/keeptrack/values.yaml index ad9f792..2b530ac 100644 --- a/charts/keeptrack/values.yaml +++ b/charts/keeptrack/values.yaml @@ -8,7 +8,7 @@ healthEndpoint: /health tls: secretName: keeptrack-blazorapp-tls - tag: 2.1.29541631973 # ref. https://hub.docker.com/r/devprofr/keeptrack-blazorapp/tags + tag: 2.3.29668982088 # ref. https://hub.docker.com/r/devprofr/keeptrack-blazorapp/tags replicaCount: 1 resources: {} # limits: @@ -54,7 +54,7 @@ webapi: secretName: keeptrack-webapi-tls host: "" replicaCount: 1 - tag: 2.1.29541631973 # ref. https://hub.docker.com/r/devprofr/keeptrack-webapi/tags + tag: 2.3.29668982088 # ref. https://hub.docker.com/r/devprofr/keeptrack-webapi/tags resources: {} extraEnv: [] additionalPodLabels: {} @@ -91,6 +91,11 @@ webapi: # name: "" # key: "" token: "" + googlebooks: + # apiKeySecretKeyRef: + # name: "" + # key: "" + apiKey: "" dotnet: environment: Production From ba11002d9a67358b0bc43dab33a5c23237424c91 Mon Sep 17 00:00:00 2001 From: Bertrand THOMAS Date: Sun, 19 Jul 2026 12:42:59 +0200 Subject: [PATCH 7/7] Fix error with secret MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This matches keeptrack's pattern exactly: default (no connectionStringSecretKeyRef) now renders as a plain value: env var, and secretKeyRef is opt-in only when the user supplies their own pre-created Secret. Summary of changes to charts/terraform-backend-mongodb: - templates/secret.yaml — deleted (no more auto-generated Secret, matching keeptrack) - templates/deployment.yaml — default branch now renders DatabaseSettings__ConnectionString as a plain value: instead of secretKeyRef to the deleted Secret; the opt-in connectionStringSecretKeyRef path is unchanged - templates/_helpers.tpl, templates/NOTES.txt, values.yaml, README.md — comments/docs updated to reflect the new behavior --- charts/sidelab/Chart.yaml | 2 +- charts/terraform-backend-mongodb/Chart.yaml | 4 ++-- charts/terraform-backend-mongodb/README.md | 17 ++++++++--------- .../templates/NOTES.txt | 2 +- .../templates/_helpers.tpl | 2 +- .../templates/deployment.yaml | 5 +---- .../templates/secret.yaml | 18 ------------------ charts/terraform-backend-mongodb/values.yaml | 6 +++--- 8 files changed, 17 insertions(+), 39 deletions(-) delete mode 100644 charts/terraform-backend-mongodb/templates/secret.yaml diff --git a/charts/sidelab/Chart.yaml b/charts/sidelab/Chart.yaml index b36908d..99e96da 100644 --- a/charts/sidelab/Chart.yaml +++ b/charts/sidelab/Chart.yaml @@ -4,7 +4,7 @@ description: > Self-hosted interactive lab platform. Deploys the Sidelab launcher, which manages lab sessions as ephemeral Kubernetes Pods inside tenant-scoped namespaces. type: application -version: 0.1.2 +version: 0.1.3 appVersion: "0.1.0" keywords: - sidelab diff --git a/charts/terraform-backend-mongodb/Chart.yaml b/charts/terraform-backend-mongodb/Chart.yaml index 6fb12c7..0514096 100644 --- a/charts/terraform-backend-mongodb/Chart.yaml +++ b/charts/terraform-backend-mongodb/Chart.yaml @@ -1,8 +1,8 @@ -apiVersion: v2 +apiVersion: v2 name: terraform-backend-mongodb description: Helm chart for Terraform Backend MongoDB type: application -version: 0.3.0 +version: 0.2.0 appVersion: "1.2.3" home: https://github.com/devpro/terraform-backend-mongodb sources: diff --git a/charts/terraform-backend-mongodb/README.md b/charts/terraform-backend-mongodb/README.md index 2be1042..fabc2e7 100644 --- a/charts/terraform-backend-mongodb/README.md +++ b/charts/terraform-backend-mongodb/README.md @@ -25,9 +25,9 @@ helm upgrade --install tfbackend devpro/terraform-backend-mongodb -f values.yaml ## Database connection -The chart never renders the MongoDB connection string as a plain environment variable in the -Deployment - `DatabaseSettings__ConnectionString` is always sourced from a Secret via `secretKeyRef`. -Pick one of the three ways below to provide it; they're evaluated in this priority order: +`DatabaseSettings__ConnectionString` is sourced from a Secret via `secretKeyRef` only when you point +the chart at one yourself; otherwise it's rendered as a plain environment variable. Pick one of the +three ways below to provide it; they're evaluated in this priority order: `webapi.db.connectionStringSecretKeyRef` > `webapi.db.connectionString` > the bundled `mongodb` subchart. @@ -55,10 +55,9 @@ webapi: ### Option 2 - your own MongoDB, connection string as a chart value -Point `webapi.db.connectionString` at a reachable, already-provisioned instance. The chart still puts -it in a Secret it manages (never directly in the Deployment's env) - but the plaintext value is still -visible in your values file and in `helm get values`/Helm's release history, so prefer Option 1 for -Production credentials: +Point `webapi.db.connectionString` at a reachable, already-provisioned instance. The chart renders it +directly as a plain env var - the plaintext value is visible in your values file, in `helm get +values`/Helm's release history, and in the Pod spec, so prefer Option 1 for Production credentials: ```yaml webapi: @@ -70,7 +69,7 @@ webapi: ### Option 3 - bundled MongoDB (auto-wired, good for demos/testing) Enable the bundled `mongodb` subchart and set its root password; the chart derives the connection -string for you and stores it in the same chart-managed Secret as Option 2. Leave +string for you and renders it the same way as Option 2 (plain env var). Leave `webapi.db.connectionString`/`connectionStringSecretKeyRef` empty: ```yaml @@ -81,7 +80,7 @@ mongodb: ``` Not recommended for anything you care about keeping - it's just another Pod with a PVC, not a -managed/backed-up database. The exact Secret name is printed in `NOTES.txt` after install. +managed/backed-up database. If none of the three is configured, or `mongodb.enabled=true` is set without `mongodb.auth.rootPassword`, the chart fails at render/install time with a clear error instead of deploying a Pod that can't reach diff --git a/charts/terraform-backend-mongodb/templates/NOTES.txt b/charts/terraform-backend-mongodb/templates/NOTES.txt index 3599d09..680c3a8 100644 --- a/charts/terraform-backend-mongodb/templates/NOTES.txt +++ b/charts/terraform-backend-mongodb/templates/NOTES.txt @@ -17,7 +17,7 @@ MongoDB is not managed by this chart (mongodb.enabled=false) - make sure webapi. {{- else }} MongoDB is managed by this chart (mongodb.enabled=true) - the webapi connection string was -auto-derived from mongodb.auth.rootPassword and stored in the {{ include "terraform-backend-mongodb.fullname" (dict "app" .Values.webapi "root" $) }}-db Secret. +auto-derived from mongodb.auth.rootPassword. {{- end }} Check the rollout: diff --git a/charts/terraform-backend-mongodb/templates/_helpers.tpl b/charts/terraform-backend-mongodb/templates/_helpers.tpl index b64b201..2c25f0f 100644 --- a/charts/terraform-backend-mongodb/templates/_helpers.tpl +++ b/charts/terraform-backend-mongodb/templates/_helpers.tpl @@ -36,7 +36,7 @@ MongoDB connection string. webapi.db.connectionString wins; otherwise, if the bundled mongodb subchart is enabled, derived from its default standalone Service name ("-mongodb", per the alias in Chart.yaml and the Bitnami chart's own naming convention) and mongodb.auth.rootPassword. -Only called from secret.yaml when webapi.db.connectionStringSecretKeyRef is not set. +Only called from deployment.yaml when webapi.db.connectionStringSecretKeyRef is not set. */}} {{- define "terraform-backend-mongodb.mongoConnectionString" -}} {{- if .Values.webapi.db.connectionString -}} diff --git a/charts/terraform-backend-mongodb/templates/deployment.yaml b/charts/terraform-backend-mongodb/templates/deployment.yaml index 0fa7628..cb136cb 100644 --- a/charts/terraform-backend-mongodb/templates/deployment.yaml +++ b/charts/terraform-backend-mongodb/templates/deployment.yaml @@ -134,10 +134,7 @@ spec: key: {{ .db.connectionStringSecretKeyRef.key }} {{- else }} - name: DatabaseSettings__ConnectionString - valueFrom: - secretKeyRef: - name: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }}-db - key: connectionString + value: {{ include "terraform-backend-mongodb.mongoConnectionString" $ | quote }} {{- end }} - name: DatabaseSettings__DatabaseName value: {{ .db.databaseName | quote }} diff --git a/charts/terraform-backend-mongodb/templates/secret.yaml b/charts/terraform-backend-mongodb/templates/secret.yaml deleted file mode 100644 index cf50f48..0000000 --- a/charts/terraform-backend-mongodb/templates/secret.yaml +++ /dev/null @@ -1,18 +0,0 @@ -{{- include "terraform-backend-mongodb.validateValues" . }} -{{- $applications := list .Values.webapi -}} -{{ range $applications }} -{{- if and .enabled (not .db.connectionStringSecretKeyRef) -}} ---- -apiVersion: v1 -kind: Secret -metadata: - name: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }}-db - labels: - app: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} - app.kubernetes.io/name: {{ include "terraform-backend-mongodb.fullname" (dict "app" . "root" $) }} - {{- include "terraform-backend-mongodb.commonLabels" (dict "app" . "root" $) | nindent 4 }} -type: Opaque -stringData: - connectionString: {{ include "terraform-backend-mongodb.mongoConnectionString" $ | quote }} -{{- end }} -{{ end }} diff --git a/charts/terraform-backend-mongodb/values.yaml b/charts/terraform-backend-mongodb/values.yaml index 7a233d1..1baf622 100644 --- a/charts/terraform-backend-mongodb/values.yaml +++ b/charts/terraform-backend-mongodb/values.yaml @@ -12,10 +12,10 @@ webapi: db: # -- Full MongoDB connection string, e.g. mongodb://user:pass@host:27017/?authSource=admin # Not needed if mongodb.enabled=true below - the chart wires that up for you from - # mongodb.auth.rootPassword. The chart always stores this in a Secret (never rendered as a - # plain env var in the Deployment) unless connectionStringSecretKeyRef below is set instead. + # mongodb.auth.rootPassword. Rendered as a plain env var unless connectionStringSecretKeyRef + # below is set instead. connectionString: "" - # -- Use your own pre-created Secret instead of connectionString above. + # -- Use your own pre-created Secret instead of connectionString above (rendered via secretKeyRef). # Takes priority over connectionString and over the bundled mongodb chart below. # connectionStringSecretKeyRef: # name: ""