From 41042e3c9126d119d73131036029a97fdde7a1f1 Mon Sep 17 00:00:00 2001 From: Bogdan Szabo Date: Wed, 18 Nov 2026 12:49:48 +0100 Subject: [PATCH] Chart: installs on any cloud, with node selectors, optional storage class, Drive, ingress annotations and backups --- .github/workflows/checks.yml | 17 +++++ deploy/README.md | 2 +- deploy/chart/templates/_helpers.tpl | 9 +++ deploy/chart/templates/backup.yaml | 16 ++--- deploy/chart/templates/data-pvc.yaml | 4 +- deploy/chart/templates/database.yaml | 9 ++- deploy/chart/templates/deployment.yaml | 9 ++- deploy/chart/templates/externalsecrets.yaml | 2 + deploy/chart/templates/ingress.yaml | 12 +++- deploy/chart/templates/networkpolicies.yaml | 9 ++- deploy/chart/templates/pdb.yaml | 2 + deploy/chart/values.yaml | 69 +++++++++++++++----- deploy/clusters/internal-cluster.values.yaml | 31 ++++++++- 13 files changed, 152 insertions(+), 39 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 9f0cacd62..055ffb776 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -159,6 +159,23 @@ jobs: # 那边同样有库、同样设了 UTOPIA_TEST_REQUIRE_DB。曾经放在这里是因为只有这个 job # 有库,代价是同一批测试二进制编两遍;这个 job 现在只管迁移本身能不能跑、能不能重放 + # The chart under deploy/ is applied by Argo CD on every merge to re-dev, and + # installed by others with their own values: it must lint and render with the + # defaults and with the internal cluster's values. + chart: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: azure/setup-helm@v4 + with: + version: v3.16.4 + - name: Lint + run: helm lint deploy/chart + - name: Render with the defaults + run: helm template utopia deploy/chart -n utopia > /dev/null + - name: Render with the internal cluster's values + run: helm template utopia deploy/chart -n utopia -f deploy/clusters/internal-cluster.values.yaml > /dev/null + web: runs-on: ubuntu-latest defaults: diff --git a/deploy/README.md b/deploy/README.md index d53048e1d..2ed83efc7 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -14,7 +14,7 @@ helm template utopia deploy/chart -n utopia -f deploy/clusters/internal-cluster. ## Backups and restore -`database.backup` sends a nightly base backup and continuous WAL to a GCS bucket through the barman-cloud plugin. The cluster's Kubernetes service account `utopia-db` reaches the bucket through Workload Identity; the Google service account and the bucket are defined in re-cinq/infrastructure, `projects/internal/database-backups.tf`. +`database.backup.objectStore` (a barman ObjectStore `configuration`, here GCS) sends a nightly base backup and continuous WAL through the barman-cloud plugin. The cluster's Kubernetes service account `utopia-db` reaches the bucket through Workload Identity; the Google service account and the bucket are defined in re-cinq/infrastructure, `projects/internal/database-backups.tf`. `database.restore.host` names another CNPG primary to be born from, with `pg_basebackup` over TLS as its `streaming_replica` user. While `database.restore.replica` is true the cluster streams from that primary and serves reads only. Setting it to false promotes the cluster; Utopia then runs its migrations and serves writes. Leave `host` set afterwards: CNPG reads `bootstrap` only when the cluster is created. diff --git a/deploy/chart/templates/_helpers.tpl b/deploy/chart/templates/_helpers.tpl index 03b3e48b4..be0b8e391 100644 --- a/deploy/chart/templates/_helpers.tpl +++ b/deploy/chart/templates/_helpers.tpl @@ -9,3 +9,12 @@ {{- define "utopia.url" -}} https://{{ .Values.hostname }} {{- end -}} + +{{/* nodeSelector and tolerations: the chart's own values, else global.* */}} +{{- define "utopia.scheduling" -}} +{{- $global := .Values.global | default dict -}} +{{- $rules := dict -}} +{{- with .Values.nodeSelector | default $global.nodeSelector }}{{- $_ := set $rules "nodeSelector" . }}{{- end -}} +{{- with .Values.tolerations | default $global.tolerations }}{{- $_ := set $rules "tolerations" . }}{{- end -}} +{{- if $rules }}{{ toYaml $rules }}{{- end -}} +{{- end -}} diff --git a/deploy/chart/templates/backup.yaml b/deploy/chart/templates/backup.yaml index 27383de76..86657682f 100644 --- a/deploy/chart/templates/backup.yaml +++ b/deploy/chart/templates/backup.yaml @@ -1,7 +1,7 @@ -{{- if .Values.database.backup.bucket }} +{{- if .Values.database.backup.objectStore }} # Where utopia-db keeps its base backups and WAL, through the barman-cloud -# plugin with Workload Identity. The same bucket holds the legacy server's -# backups that database.restore reads. +# plugin. `configuration` is database.backup.objectStore as written, so any +# store the plugin speaks (GCS, S3, Azure Blob) works. apiVersion: barmancloud.cnpg.io/v1 kind: ObjectStore metadata: @@ -9,15 +9,7 @@ metadata: spec: retentionPolicy: {{ .Values.database.backup.retention }} configuration: - destinationPath: gs://{{ .Values.database.backup.bucket }}/ - googleCredentials: - gkeEnvironment: true - data: - compression: gzip - jobs: 2 - wal: - compression: gzip - maxParallel: 2 + {{- toYaml .Values.database.backup.objectStore | nindent 4 }} --- apiVersion: postgresql.cnpg.io/v1 kind: ScheduledBackup diff --git a/deploy/chart/templates/data-pvc.yaml b/deploy/chart/templates/data-pvc.yaml index 99925cfc4..d7956e085 100644 --- a/deploy/chart/templates/data-pvc.yaml +++ b/deploy/chart/templates/data-pvc.yaml @@ -4,7 +4,9 @@ metadata: name: utopia-data spec: accessModes: [ReadWriteOnce] - storageClassName: {{ .Values.data.storageClass }} + {{- with .Values.data.storageClass }} + storageClassName: {{ . }} + {{- end }} resources: requests: storage: {{ .Values.data.size }} diff --git a/deploy/chart/templates/database.yaml b/deploy/chart/templates/database.yaml index e2a389be8..3962ff58b 100644 --- a/deploy/chart/templates/database.yaml +++ b/deploy/chart/templates/database.yaml @@ -15,6 +15,10 @@ metadata: spec: instances: 1 imageName: {{ .Values.database.image }} + {{- with include "utopia.scheduling" . }} + affinity: + {{- . | nindent 4 }} + {{- end }} {{- with .Values.database.backup.serviceAccount }} serviceAccountTemplate: metadata: @@ -51,7 +55,7 @@ spec: enabled: {{ .Values.database.restore.replica }} source: legacy {{- end }} - {{- if .Values.database.backup.bucket }} + {{- if .Values.database.backup.objectStore }} plugins: - name: barman-cloud.cloudnative-pg.io enabled: true @@ -70,6 +74,9 @@ spec: # Grows in place; never shrinks. storage: size: {{ .Values.database.size }} + {{- with .Values.database.storageClass }} + storageClass: {{ . }} + {{- end }} resources: {{- toYaml .Values.database.resources | nindent 4 }} postgresql: diff --git a/deploy/chart/templates/deployment.yaml b/deploy/chart/templates/deployment.yaml index 0e25404b1..2b3d2cb14 100644 --- a/deploy/chart/templates/deployment.yaml +++ b/deploy/chart/templates/deployment.yaml @@ -15,8 +15,13 @@ spec: # One replica on one disk: the node autoscaler must not move it. cluster-autoscaler.kubernetes.io/safe-to-evict: "false" spec: + {{- with .Values.image.pullSecret }} imagePullSecrets: - - name: {{ .Values.image.pullSecret }} + - name: {{ . }} + {{- end }} + {{- with include "utopia.scheduling" . }} + {{- . | nindent 6 }} + {{- end }} # The image declares no USER. The binary writes only the data volume, # which fsGroup makes writable for this uid, and /tmp for PDF and OCR work. securityContext: @@ -78,6 +83,7 @@ spec: valueFrom: { secretKeyRef: { name: utopia-oauth, key: client-id } } - name: UTOPIA_OIDC_CLIENT_SECRET valueFrom: { secretKeyRef: { name: utopia-oauth, key: client-secret } } + {{- if .Values.googleDrive.enabled }} # The Google Drive source uses the same OAuth client. - name: UTOPIA_GOOGLE_DRIVE_CLIENT_ID valueFrom: { secretKeyRef: { name: utopia-oauth, key: client-id } } @@ -85,6 +91,7 @@ spec: valueFrom: { secretKeyRef: { name: utopia-oauth, key: client-secret } } - name: UTOPIA_GOOGLE_DRIVE_REDIRECT_URI value: {{ include "utopia.url" . }}/api/v1/google-drive/callback + {{- end }} volumeMounts: - { name: data, mountPath: /app/data } - { name: tmp, mountPath: /tmp } diff --git a/deploy/chart/templates/externalsecrets.yaml b/deploy/chart/templates/externalsecrets.yaml index dc2105999..f4e6b1c1b 100644 --- a/deploy/chart/templates/externalsecrets.yaml +++ b/deploy/chart/templates/externalsecrets.yaml @@ -65,6 +65,7 @@ spec: remoteRef: { key: {{ .Values.secrets.oauthClientSecret }} } - secretKey: cookie-secret remoteRef: { key: {{ .Values.secrets.cookieSecret }} } +{{- if .Values.image.pullSecret }} --- apiVersion: external-secrets.io/v1beta1 kind: ExternalSecret @@ -83,3 +84,4 @@ spec: - secretKey: dockerconfigjson remoteRef: { key: {{ .Values.secrets.ghcrPullSecret }} } {{- end }} +{{- end }} diff --git a/deploy/chart/templates/ingress.yaml b/deploy/chart/templates/ingress.yaml index 285e647f0..72766e0a9 100644 --- a/deploy/chart/templates/ingress.yaml +++ b/deploy/chart/templates/ingress.yaml @@ -2,14 +2,22 @@ apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: utopia + {{- if or .Values.ingress.clusterIssuer .Values.ingress.externalDns .Values.ingress.annotations }} annotations: - cert-manager.io/cluster-issuer: {{ .Values.ingress.clusterIssuer }} + {{- with .Values.ingress.clusterIssuer }} + cert-manager.io/cluster-issuer: {{ . }} + {{- end }} + {{- if .Values.ingress.externalDns }} external-dns.alpha.kubernetes.io/hostname: {{ .Values.hostname }} + {{- end }} {{- with .Values.ingress.annotations }} {{- toYaml . | nindent 4 }} {{- end }} + {{- end }} spec: - ingressClassName: {{ .Values.ingress.className }} + {{- with .Values.ingress.className }} + ingressClassName: {{ . }} + {{- end }} tls: - hosts: [{{ .Values.hostname }}] secretName: utopia-tls diff --git a/deploy/chart/templates/networkpolicies.yaml b/deploy/chart/templates/networkpolicies.yaml index de66c4f1f..f05a94bce 100644 --- a/deploy/chart/templates/networkpolicies.yaml +++ b/deploy/chart/templates/networkpolicies.yaml @@ -22,7 +22,7 @@ spec: {{- end }} --- # The app's way out: DNS (both NodeLocal DNSCache and kube-dns), its database, -# and the public internet on 80 and 443. Every private and in-cluster range is +# and the public internet on 443 (and 80 with network.allowPlainHttp). Every private and in-cluster range is # excluded so an endpoint typed into the admin page cannot reach other workloads. apiVersion: networking.k8s.io/v1 kind: NetworkPolicy @@ -42,7 +42,9 @@ spec: matchLabels: { kubernetes.io/metadata.name: kube-system } podSelector: matchLabels: { k8s-app: node-local-dns } - - ipBlock: { cidr: 169.254.20.10/32 } + {{- with .Values.network.nodeLocalDnsAddress }} + - ipBlock: { cidr: {{ . }} } + {{- end }} ports: - { protocol: UDP, port: 53 } - { protocol: TCP, port: 53 } @@ -59,10 +61,13 @@ spec: - 172.16.0.0/12 - 192.168.0.0/16 - 169.254.0.0/16 + - 100.64.0.0/10 - {{ .Values.network.clusterServicesCidr }} ports: - { protocol: TCP, port: 443 } + {{- if .Values.network.allowPlainHttp }} - { protocol: TCP, port: 80 } + {{- end }} --- # The database answers the app and the CNPG operator, nobody else. apiVersion: networking.k8s.io/v1 diff --git a/deploy/chart/templates/pdb.yaml b/deploy/chart/templates/pdb.yaml index 4d667793f..d52817097 100644 --- a/deploy/chart/templates/pdb.yaml +++ b/deploy/chart/templates/pdb.yaml @@ -1,3 +1,4 @@ +{{- if .Values.podDisruptionBudget.enabled }} # Voluntary disruptions (node scale-down, upgrades) wait for a replica that # never exists, so they never happen on their own; the Recreate rollout is # the only planned restart. @@ -9,3 +10,4 @@ spec: minAvailable: 1 selector: matchLabels: { app: utopia } +{{- end }} diff --git a/deploy/chart/values.yaml b/deploy/chart/values.yaml index 85e806c3c..1303001fd 100644 --- a/deploy/chart/values.yaml +++ b/deploy/chart/values.yaml @@ -1,7 +1,13 @@ -# Defaults render a working chart; a cluster's file under deploy/clusters/ -# sets hostname, image and sizes. Secret VALUES never live here: each entry -# under `secrets` names a key in the project's Secret Manager, read through -# the External Secrets ClusterSecretStore. +# Defaults render a working chart on any Kubernetes cluster; a cluster's file +# under deploy/clusters/ sets hostname, image, sizes and whatever its cloud +# needs. Secret VALUES never live here: each entry under `secrets` names a key +# in a secret store read through External Secrets, or `secrets.external: false` +# leaves the Secrets to you. + +# Where the pods run. Either set here, or once for every chart of a release +# under `global`; a value set here wins. +nodeSelector: {} +tolerations: [] image: repository: ghcr.io/re-cinq/utopia @@ -9,7 +15,8 @@ image: # A digest pins the bytes; set it and the tag is ignored. digest: "" pullPolicy: IfNotPresent - pullSecret: ghcr-pull-secret + # Name of an image pull secret; empty when the image is public. + pullSecret: "" hostname: utopia.example.com @@ -18,6 +25,10 @@ oidc: issuer: https://accounts.google.com allowedDomains: re-cinq.com +# The Google Drive source reuses the OIDC client; it needs Google as the issuer. +googleDrive: + enabled: false + resources: requests: { cpu: 250m, memory: 512Mi } limits: { cpu: "1", memory: 2Gi } @@ -26,15 +37,19 @@ resources: # the Deployment recreates rather than rolls. data: size: 20Gi - storageClass: standard-rwo + # Empty: the cluster's default storage class. + storageClass: "" # Extra environment for the app container. Values here are plain strings. env: UTOPIA_DB_MAX_CONNECTIONS: "32" database: - image: ghcr.io/cloudnative-pg/postgresql:16-bookworm + # Pinned by digest; the digest wins over the tag. + image: ghcr.io/cloudnative-pg/postgresql:16-bookworm@sha256:bf0b0ec764b26fbb9136476ed29ad92abdc1277d0465194b8bf420f0116b974d size: 80Gi + # Empty: the cluster's default storage class. + storageClass: "" resources: requests: { cpu: "2", memory: 8Gi } limits: { cpu: "4", memory: 8Gi } @@ -42,12 +57,17 @@ database: shared_buffers: 2GB effective_cache_size: 6GB work_mem: 16MB - # Base backups nightly plus continuous WAL, into a GCS bucket the cluster's - # Kubernetes service account reaches through Workload Identity (the Google - # service account is bound in re-cinq/infrastructure, projects/internal). - # Empty bucket: no backups. + # Base backups nightly plus continuous WAL through the barman-cloud plugin. + # `objectStore` is the `configuration` of a barman ObjectStore, passed through + # as written (GCS, S3 or Azure Blob); empty: no backups. Example, GCS: + # objectStore: + # destinationPath: gs://my-bucket/ + # googleCredentials: { gkeEnvironment: true } + # data: { compression: gzip, jobs: 2 } + # wal: { compression: gzip, maxParallel: 2 } backup: - bucket: "" + objectStore: {} + # Annotation target for GKE Workload Identity; empty elsewhere. serviceAccount: "" serverName: utopia-db retention: 14d @@ -75,23 +95,36 @@ secrets: cookieSecret: lore-utopia-cookie-secret ghcrPullSecret: lore-ghcr-pull-secret +# The controller must allow request bodies up to 200 MB and long-lived connections. ingress: - className: nginx-ingress - clusterIssuer: letsencrypt-prod - annotations: - nginx.ingress.kubernetes.io/proxy-body-size: 200m - nginx.ingress.kubernetes.io/proxy-read-timeout: "3600" + # Empty: the cluster's default ingress class. + className: "" + # cert-manager ClusterIssuer; empty: no cert-manager annotation. + clusterIssuer: "" + # true: annotate the host for external-dns. + externalDns: false + # Controller-specific settings, e.g. body size and read timeout. + annotations: {} + +# The app is a single replica on one disk, so a budget of minAvailable 1 blocks +# every voluntary eviction. Turn it on to hold the node-drain for a person. +podDisruptionBudget: + enabled: false # Volume-filling alerts, for a cluster that runs the Prometheus operator. alerts: enabled: false network: - ingressControllerNamespace: ingress-nginx + ingressControllerNamespace: traefik cnpgOperatorNamespace: cnpg-system # This cluster's Service range, fenced off from the app's egress with the # private ranges, so an endpoint typed into the admin page stays outside. clusterServicesCidr: 10.0.0.0/8 + # Address of a NodeLocal DNSCache, when the cluster runs one (usually 169.254.20.10/32). + nodeLocalDnsAddress: "" + # Web sources may be plain http:// URLs, so egress allows port 80 as well as 443. + allowPlainHttp: true # In-cluster callers allowed to reach the app pod on its port. allowFrom: [] # - namespace: lore-api diff --git a/deploy/clusters/internal-cluster.values.yaml b/deploy/clusters/internal-cluster.values.yaml index 01e1e4623..9968f1610 100644 --- a/deploy/clusters/internal-cluster.values.yaml +++ b/deploy/clusters/internal-cluster.values.yaml @@ -9,18 +9,46 @@ image: repository: ghcr.io/re-cinq/utopia tag: 0.1.0-re.35 digest: sha256:737e04c76ca0cfdf061cf68acb9626d59c098502e0962590312127bd8f76fa6c + pullSecret: ghcr-pull-secret + +googleDrive: + enabled: true data: size: 20Gi + storageClass: standard-rwo + +ingress: + className: nginx-ingress + clusterIssuer: letsencrypt-prod + externalDns: true + annotations: + nginx.ingress.kubernetes.io/proxy-body-size: 200m + nginx.ingress.kubernetes.io/proxy-read-timeout: "3600" + +# One replica on one disk: the budget deliberately blocks node scale-down. +podDisruptionBudget: + enabled: true # A superseded chunk keeps its vector for a week (RC-007). Unset, nothing is cleared. env: UTOPIA_SUPERSEDED_VECTOR_DAYS: "7" database: + # Still the floating tag: pinning the digest restarts the database, so that waits for a planned window. + image: ghcr.io/cloudnative-pg/postgresql:16-bookworm size: 80Gi backup: - bucket: utopia-db-backups-re-cinq-internal + objectStore: + destinationPath: gs://utopia-db-backups-re-cinq-internal/ + googleCredentials: + gkeEnvironment: true + data: + compression: gzip + jobs: 2 + wal: + compression: gzip + maxParallel: 2 serviceAccount: utopia-db-backup@re-cinq-internal.iam.gserviceaccount.com serverName: utopia-db-internal # Migration from n8n-cluster: born from its utopia-db primary, exposed on @@ -33,6 +61,7 @@ network: ingressControllerNamespace: ingress-nginx cnpgOperatorNamespace: cnpg-system clusterServicesCidr: 10.89.0.0/22 + nodeLocalDnsAddress: 169.254.20.10/32 # lore-api mirrors each repository's spec and ADR graph into Utopia over the # cluster network (ADR-052 in re-cinq/lore). allowFrom: