Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
9 changes: 9 additions & 0 deletions deploy/chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
16 changes: 4 additions & 12 deletions deploy/chart/templates/backup.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
{{- 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:
name: utopia-db
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
Expand Down
4 changes: 3 additions & 1 deletion deploy/chart/templates/data-pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
9 changes: 8 additions & 1 deletion deploy/chart/templates/database.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion deploy/chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -78,13 +83,15 @@ 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 } }
- name: UTOPIA_GOOGLE_DRIVE_CLIENT_SECRET
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 }
Expand Down
2 changes: 2 additions & 0 deletions deploy/chart/templates/externalsecrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -83,3 +84,4 @@ spec:
- secretKey: dockerconfigjson
remoteRef: { key: {{ .Values.secrets.ghcrPullSecret }} }
{{- end }}
{{- end }}
12 changes: 10 additions & 2 deletions deploy/chart/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions deploy/chart/templates/networkpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions deploy/chart/templates/pdb.yaml
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -9,3 +10,4 @@ spec:
minAvailable: 1
selector:
matchLabels: { app: utopia }
{{- end }}
69 changes: 51 additions & 18 deletions deploy/chart/values.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
# 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
tag: latest
# 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

Expand All @@ -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 }
Expand All @@ -26,28 +37,37 @@ 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 }
parameters:
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
Expand Down Expand Up @@ -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
Expand Down
Loading
Loading