diff --git a/apps/base/forgejo/kustomization.yaml b/apps/base/forgejo/kustomization.yaml index df58884..6413743 100644 --- a/apps/base/forgejo/kustomization.yaml +++ b/apps/base/forgejo/kustomization.yaml @@ -10,6 +10,10 @@ resources: - deployment.yaml - service.yaml - runner-configmap.yaml + # Static PVs/PVCs pinned to rpi: dynamic local-path cannot provision there + # (its helper pod is hardcoded to siriussec). Must sort before the runner + # Deployments that consume the claims. + - runner-dind-storage.yaml - runner-arm64.yaml - runner-amd64.yaml - runner-deploy-arm64.yaml diff --git a/apps/base/forgejo/runner-arm64.yaml b/apps/base/forgejo/runner-arm64.yaml index 0f8b1bd..9aec81c 100644 --- a/apps/base/forgejo/runner-arm64.yaml +++ b/apps/base/forgejo/runner-arm64.yaml @@ -12,6 +12,7 @@ spec: matchLabels: app: forgejo-runner arch: arm64 + # RWO PVC: never two pods on one data-root. strategy: type: Recreate template: @@ -27,49 +28,100 @@ spec: operator: Equal value: network effect: PreferNoSchedule - securityContext: - supplementalGroups: [984] + # No supplementalGroups: there is no host docker socket and no host + # docker gid to match any more. The only daemon this runner talks to is + # the privileged `dind` sidecar below. containers: + # In-pod Docker daemon. Same shape as forgejo-runner-amd64: privileged, + # socket on an emptyDir shared with the runner, data-root on the PVC. + # The container MUST be named `dind`, not `docker`/`dockerd`: the + # nightly prune (prune-cronjob.yaml) discovers daemons by + # `app=forgejo-runner` plus a container literally named `dind`, and + # silently prunes nothing for any other name while still reporting + # success. + - name: dind + image: docker:27-dind + imagePullPolicy: IfNotPresent + command: + - sh + - -c + - | + dockerd --host=unix:///var/run/docker.sock --tls=false --mtu=1420 & + pid=$! + i=0 + while [ "$i" -lt 30 ]; do + if [ -S /var/run/docker.sock ]; then + chmod 666 /var/run/docker.sock + break + fi + i=$((i+1)) + sleep 1 + done + wait "$pid" + securityContext: + privileged: true + volumeMounts: + - name: dind-run + mountPath: /var/run + - name: data + mountPath: /var/lib/docker + subPath: docker + resources: + # Measured peak RSS of a real ci.yml-shaped Rust job inside dind on + # this Pi: 3.10 GiB (docs/arm64-runner-dind.md §2.6). The previous + # 512Mi limit OOM-killed the daemon on the first build; 4Gi copies + # the amd64 runner, which runs the same load shape. + requests: + cpu: 200m + memory: 512Mi + limits: + memory: 4Gi - name: runner # code.forgejo.org/forgejo/runner is genuinely multi-arch and works on # both the amd64 (siriussec) and arm64 (rpi) runners. Do NOT swap this # for alex3305/forgejo-runner-dind:* on the arm64 runner: that image's # arm64 manifest ships an x86-64 forgejo-runner binary, so the Pi dies - # with "exec format error" and the pi-runner (the only runner declaring + # with "exec format error" and the pi runner (the only runner declaring # the bare `docker` label) goes offline, stalling every `runs-on: docker` # job in onionwire/siriusdevops-contact. image: code.forgejo.org/forgejo/runner:5.0.1 imagePullPolicy: IfNotPresent + # uid 1000 in this image vs a `660 root:docker` dind socket: the dind + # container's one-shot chmod 666 can race a dockerd restart and the + # runner's wait loop only checks that the socket exists, so it would + # crashloop on "permission denied". Running as root is what the amd64 + # runner proved deterministic (2eff85b). + securityContext: + runAsUser: 0 command: - - forgejo-runner - - --config - - /config/config.toml - - daemon + - sh + - -c + - | + set -e + i=0 + while [ "$i" -lt 60 ]; do + if [ -S /var/run/docker.sock ]; then + break + fi + i=$((i+1)) + sleep 2 + done + exec forgejo-runner --config /config/config.toml daemon env: - name: DOCKER_HOST value: unix:///var/run/docker.sock - securityContext: - privileged: true - runAsUser: 0 - runAsGroup: 0 volumeMounts: - - name: docker-sock - mountPath: /var/run/docker.sock - - name: docker-static - mountPath: /usr/bin/docker - readOnly: true - - name: cli-plugins - mountPath: /usr/local/lib/docker/cli-plugins - readOnly: true - name: config-toml mountPath: /config/config.toml subPath: arm64.toml - - name: runner-ini - mountPath: /config/runner.ini - - name: cache - mountPath: /opt/siriusdevops/runner/cache - - name: siriusdevops - mountPath: /opt/siriusdevops + # runner.ini + actions cache live on the same PVC as the dind + # data-root (subPath docker), so one Retain PV holds the whole + # runner identity. Copied from the Pi host before first start — + # never registered here, the uuid must survive. + - name: data + mountPath: /data + - name: dind-run + mountPath: /var/run resources: requests: cpu: 50m @@ -77,30 +129,11 @@ spec: limits: memory: 512Mi volumes: - - name: docker-sock - hostPath: - path: /var/run/docker.sock - type: Socket - - name: docker-static - hostPath: - path: /usr/local/bin/docker-static - type: File - - name: cli-plugins - hostPath: - path: /opt/siriusdevops/runner/cli-plugins - type: DirectoryOrCreate - name: config-toml configMap: name: forgejo-runner-config - - name: runner-ini - hostPath: - path: /opt/siriusdevops/runner/config/runner.ini - type: File - - name: cache - hostPath: - path: /opt/siriusdevops/runner/cache - type: DirectoryOrCreate - - name: siriusdevops - hostPath: - path: /opt/siriusdevops - type: Directory + - name: data + persistentVolumeClaim: + claimName: forgejo-runner-arm64-dind + - name: dind-run + emptyDir: {} diff --git a/apps/base/forgejo/runner-configmap.yaml b/apps/base/forgejo/runner-configmap.yaml index 9110668..5c2f132 100644 --- a/apps/base/forgejo/runner-configmap.yaml +++ b/apps/base/forgejo/runner-configmap.yaml @@ -8,7 +8,10 @@ data: log: level: info runner: - file: /config/runner.ini + # runner.ini lives on the runner's data PVC now (was a hostPath file), so + # the registration survives the move to in-cluster dind with the same + # uuid. Nothing in the Deployment registers a runner. + file: /data/runner.ini # capacity 1: ci.yml builds every job's Rust target into ONE shared named # volume (onionwire-target-ci, mounted at /target). Two jobs writing that # volume concurrently clobber each other's freshly-linked test binaries, @@ -18,16 +21,25 @@ data: # runs of the same group on this runner (446 + 447 overlapped). capacity: 1 timeout: 1h - cache: /opt/siriusdevops/runner/cache + cache: /data/cache cache: enabled: true - dir: /opt/siriusdevops/runner/cache + dir: /data/cache container: privileged: true - # No docker_host here: setting it makes the runner inject the host socket - # bind into the job container itself, which collides with the explicit - # -v /var/run/docker.sock in options ("Duplicate mount point"). - options: -v /usr/local/bin/docker-static:/usr/bin/docker:ro -v /opt/siriusdevops/runner/cli-plugins:/usr/local/lib/docker/cli-plugins:ro -v /var/run/docker.sock:/var/run/docker.sock --memory 3g --memory-swap 3g + # No docker_host here: setting it makes the runner inject the socket bind + # into the job container itself, which collides with the explicit + # -v /var/run/docker.sock in options ("Duplicate mount point"). The + # options bind is the deliberate choice — nested `docker create/start` in + # ci.yml, fuzz.yml and release.yml depends on it. + # + # The docker CLI/plugins come out of the `dind` sidecar's own filesystem + # (docker:27-dind ships /usr/local/bin/docker, docker-buildx, + # docker-compose), not the Pi host's docker-static. Paths resolve inside + # the dind container, which is what the daemon bind-mounts from. This + # keeps `docker buildx` working without installing a CLI in five + # workflows. + options: -v /usr/local/bin/docker:/usr/bin/docker:ro -v /usr/local/libexec/docker/cli-plugins:/usr/local/lib/docker/cli-plugins:ro -v /var/run/docker.sock:/var/run/docker.sock --memory 3g --memory-swap 3g valid_volumes: - "**" # Dedicated runner for site deploys. It declares ONLY the `deploy-arm64` @@ -36,13 +48,19 @@ data: # can never occupy the Pi's `docker` runner, whose capacity 1 exists to # serialize onionwire jobs sharing the onionwire-target-ci volume. # - # It runs on the Pi because deploy-site.yml needs Pi-local resources: - # 127.0.0.1:5000 (registry), 127.0.0.1:3900 (Garage) via `--network host`, - # and the host docker socket to build the arm64 site image. + # It runs on the Pi because deploy-site.yml needs Pi-local resources: the Pi + # registry and Garage are now addressed over the WireGuard hub IP + # (10.10.0.1:5000, 10.10.0.1:3900) instead of loopback, because 127.0.0.1 + # inside a pod is the pod. Its own `dind` sidecar builds the arm64 site image; + # no host Docker is involved. deploy-arm64.toml: | log: level: info runner: + # Copied onto the data PVC from /opt/siriusdevops/runner-deploy/data on + # the Pi host before first start. The require-registration init container + # refuses to start without it (registering would burn the single-use + # token and create a second action_runner row). file: /data/runner.ini capacity: 1 timeout: 30m @@ -54,11 +72,13 @@ data: privileged: true # Same injection as arm64.toml: the job container is node:20-bullseye, # which has no docker CLI and no buildx, and deploy-site.yml needs both. - # buildx is the host's cli-plugins binary and binfmt/QEMU is registered on - # the Pi host, so amd64 cross-builds work here exactly as on the arm64 - # runner. --memory caps the job container only (sibling `docker run` - # containers a workflow spawns are outside the runner's control). - options: -v /usr/local/bin/docker-static:/usr/bin/docker:ro -v /opt/siriusdevops/runner/cli-plugins:/usr/local/lib/docker/cli-plugins:ro -v /var/run/docker.sock:/var/run/docker.sock --memory 3g --memory-swap 3g + # Both come from the dind sidecar's own filesystem. binfmt/QEMU is + # registered kernel-globally on the Pi (the POC pod's + # /proc/sys/fs/binfmt_misc was empty yet an amd64 build ran as x86_64), + # so the `--platform linux/amd64` cross build works inside the pod. + # --memory caps the job container only (sibling `docker run` containers a + # workflow spawns are outside the runner's control). + options: -v /usr/local/bin/docker:/usr/bin/docker:ro -v /usr/local/libexec/docker/cli-plugins:/usr/local/lib/docker/cli-plugins:ro -v /var/run/docker.sock:/var/run/docker.sock --memory 3g --memory-swap 3g valid_volumes: - "**" diff --git a/apps/base/forgejo/runner-deploy-arm64.yaml b/apps/base/forgejo/runner-deploy-arm64.yaml index 3c55816..dd70ba7 100644 --- a/apps/base/forgejo/runner-deploy-arm64.yaml +++ b/apps/base/forgejo/runner-deploy-arm64.yaml @@ -12,6 +12,9 @@ # cheap; the labels are disjoint in both directions, so neither class can # starve the other. Keep capacity 1: a deploy must not overlap itself (the Pi # registry tag :latest and the k8s restartedAt patch are last-writer-wins). +# +# Since the arm64 dind cutover this runner has its own in-pod daemon too, so a +# deploy no longer shares the Pi's host Docker with anything. apiVersion: apps/v1 kind: Deployment metadata: @@ -43,80 +46,106 @@ spec: operator: Equal value: network effect: PreferNoSchedule - securityContext: - supplementalGroups: [984] initContainers: - # Self-registration, like the amd64 runner. runner.ini lives on the Pi - # host (/opt/siriusdevops/runner-deploy/data) so a pod restart reuses the - # existing registration instead of burning a single-use runner token. - - name: register - # Must be the multi-arch code.forgejo.org image: alex3305/ - # forgejo-runner-dind ships an x86-64 binary in its arm64 manifest and - # dies with "exec format error" on the Pi. + # Registration guard, NOT a registration step. The runner's identity + # (`runner.ini`, action_runner id 14 / uuid a41aad73-…) is copied onto + # the PVC from the Pi host before the first start. The previous version + # of this init container registered a *new* runner whenever the file was + # missing, which burns a single-use token and leaves a second + # action_runner row polling under a new uuid. Refuse instead: a missing + # file is an operator error, not something to paper over. + - name: require-registration image: code.forgejo.org/forgejo/runner:5.0.1 imagePullPolicy: IfNotPresent - # The hostPath /data dir is created root:root by kubelet, and the - # runner image's default user cannot write runner.ini into it. securityContext: runAsUser: 0 - runAsGroup: 0 command: - sh - -c - | set -e - if [ -s /data/runner.ini ]; then - echo already-registered - exit 0 + if [ ! -s /data/runner.ini ]; then + echo "runner.ini missing on the data PVC — refusing to register a second uuid" >&2 + echo "restore it: ssh rpi sudo install -m600 -o root -g root /opt/siriusdevops/runner-deploy/data/runner.ini /opt/local-path-provisioner/forgejo-runner-deploy-arm64-dind/runner.ini" >&2 + exit 1 fi - forgejo-runner register --no-interactive \ - --instance https://forgejo.siriusdevops.com \ - --token "$RUNNER_TOKEN" \ - --name pi-deploy-arm64 \ - --labels 'deploy-arm64:docker://node:20-bullseye' \ - --config /config/config.toml - env: - - name: RUNNER_TOKEN - valueFrom: - secretKeyRef: - name: forgejo-runner-deploy-arm64-token - key: token + echo "registration present: $(grep -o '\"uuid\": \"[^\"]*\"' /data/runner.ini)" volumeMounts: - - name: config-toml - mountPath: /config/config.toml - subPath: deploy-arm64.toml - name: data mountPath: /data containers: + - name: dind + image: docker:27-dind + imagePullPolicy: IfNotPresent + command: + - sh + - -c + - | + dockerd --host=unix:///var/run/docker.sock --tls=false --mtu=1420 & + pid=$! + i=0 + while [ "$i" -lt 30 ]; do + if [ -S /var/run/docker.sock ]; then + chmod 666 /var/run/docker.sock + break + fi + i=$((i+1)) + sleep 1 + done + wait "$pid" + securityContext: + privileged: true + volumeMounts: + - name: dind-run + mountPath: /var/run + - name: data + mountPath: /var/lib/docker + subPath: docker + resources: + # Deliberately smaller than the shared runner's 4Gi. A deploy is two + # nginx-based site images (112-143 MB each) plus buildx's + # docker-container driver and one `--platform linux/amd64` cross + # build under qemu; nothing like the Rust ci.yml job that peaked at + # 3.10 GiB. The Pi has 7.0 GiB available and capacity 1 per runner + # bounds each runner but nothing bounds both: 4Gi + 2Gi limits leave + # ~1 GiB for kubelet/Cilium/cloudflared/host Docker even if a CI run + # and a deploy overlap, and an OOM here fails one deploy visibly. + # (A 4Gi deploy limit would let two runners claim every byte.) + requests: + cpu: 100m + memory: 256Mi + limits: + memory: 2Gi - name: runner image: code.forgejo.org/forgejo/runner:5.0.1 imagePullPolicy: IfNotPresent + securityContext: + runAsUser: 0 command: - - forgejo-runner - - --config - - /config/config.toml - - daemon + - sh + - -c + - | + set -e + i=0 + while [ "$i" -lt 60 ]; do + if [ -S /var/run/docker.sock ]; then + break + fi + i=$((i+1)) + sleep 2 + done + exec forgejo-runner --config /config/config.toml daemon env: - name: DOCKER_HOST value: unix:///var/run/docker.sock - securityContext: - privileged: true - runAsUser: 0 - runAsGroup: 0 volumeMounts: - - name: docker-sock - mountPath: /var/run/docker.sock - - name: docker-static - mountPath: /usr/bin/docker - readOnly: true - - name: cli-plugins - mountPath: /usr/local/lib/docker/cli-plugins - readOnly: true - name: config-toml mountPath: /config/config.toml subPath: deploy-arm64.toml - name: data mountPath: /data + - name: dind-run + mountPath: /var/run resources: requests: cpu: 50m @@ -124,22 +153,11 @@ spec: limits: memory: 512Mi volumes: - - name: docker-sock - hostPath: - path: /var/run/docker.sock - type: Socket - - name: docker-static - hostPath: - path: /usr/local/bin/docker-static - type: File - - name: cli-plugins - hostPath: - path: /opt/siriusdevops/runner/cli-plugins - type: DirectoryOrCreate - name: config-toml configMap: name: forgejo-runner-config - name: data - hostPath: - path: /opt/siriusdevops/runner-deploy/data - type: DirectoryOrCreate + persistentVolumeClaim: + claimName: forgejo-runner-deploy-arm64-dind + - name: dind-run + emptyDir: {} diff --git a/apps/base/forgejo/runner-dind-storage.yaml b/apps/base/forgejo/runner-dind-storage.yaml new file mode 100644 index 0000000..2d366d5 --- /dev/null +++ b/apps/base/forgejo/runner-dind-storage.yaml @@ -0,0 +1,122 @@ +--- +# Static storage for the arm64 runners' in-cluster dind daemons. +# +# Why static PVs and not the default `local-path` StorageClass: the +# provisioner's helper pod is hardcoded to siriussec +# (infrastructure/storage/local-path-storage.yaml, helper-pod nodeSelector) and +# for a local filesystem it never sets spec.nodeName, so a `local-path` PVC +# consumed by a pod on rpi stays Pending forever ("NodeAffinity failed"). +# Measured 2026-10-27 in a throwaway namespace; see +# docs/arm64-runner-dind.md §6.1. +# +# `persistentVolumeReclaimPolicy: Retain` is deliberate: the runner's +# registration (`runner.ini`, uuid of the Forgejo action_runner row) lives in +# this directory. Deleting the PVC must never delete the identity — a re- +# registered runner burns a single-use token and leaves an orphaned +# action_runner row behind. +# +# Sizes come from measured steady state (docs/arm64-runner-dind.md §4): +# shared runner 146.5 GiB steady -> 200Gi request (named CI volumes) +# deploy runner ~0.3 GiB steady -> 40Gi request (image + buildx generations) +# 240 GiB of the Pi's 390 GiB free. A static PV does not enforce the request — +# the 70 % node-filesystem alert in monitoring/controllers/home/prune-alerts.yaml +# is the real cap. +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: local-static +# No provisioner: every PV with this class is hand-made, so a typo'd claim +# hangs in Pending instead of silently landing somewhere unexpected. +provisioner: kubernetes.io/no-provisioner +volumeBindingMode: WaitForFirstConsumer +reclaimPolicy: Retain +--- +apiVersion: v1 +kind: PersistentVolume +metadata: + name: forgejo-runner-arm64-dind + labels: + app: forgejo-runner + arch: arm64 +spec: + capacity: + storage: 200Gi + accessModes: + - ReadWriteOnce + persistentVolumeReclaimPolicy: Retain + storageClassName: local-static + volumeMode: Filesystem + hostPath: + # Same filesystem/tree the local-path provisioner uses, so df and the + # existing node-exporter alerting see it as ordinary node disk. + path: /opt/local-path-provisioner/forgejo-runner-arm64-dind + type: DirectoryOrCreate + nodeAffinity: + required: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - rpi +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: forgejo-runner-arm64-dind + namespace: forgejo + labels: + app: forgejo-runner + arch: arm64 +spec: + accessModes: + - ReadWriteOnce + storageClassName: local-static + volumeName: forgejo-runner-arm64-dind + resources: + requests: + storage: 200Gi +--- +apiVersion: v1 +kind: PersistentVolume +metadata: + name: forgejo-runner-deploy-arm64-dind + labels: + app: forgejo-runner + role: deploy +spec: + capacity: + storage: 40Gi + accessModes: + - ReadWriteOnce + persistentVolumeReclaimPolicy: Retain + storageClassName: local-static + volumeMode: Filesystem + hostPath: + path: /opt/local-path-provisioner/forgejo-runner-deploy-arm64-dind + type: DirectoryOrCreate + nodeAffinity: + required: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - rpi +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: forgejo-runner-deploy-arm64-dind + namespace: forgejo + labels: + app: forgejo-runner + role: deploy +spec: + accessModes: + - ReadWriteOnce + storageClassName: local-static + volumeName: forgejo-runner-deploy-arm64-dind + resources: + requests: + storage: 40Gi diff --git a/monitoring/controllers/home/prune-alerts.yaml b/monitoring/controllers/home/prune-alerts.yaml index 2d71ab0..e63800f 100644 --- a/monitoring/controllers/home/prune-alerts.yaml +++ b/monitoring/controllers/home/prune-alerts.yaml @@ -127,6 +127,43 @@ spec: raise the PVC, or clear the dind data-root deliberately (see the DiskPressure runbook in the home-k8s skill) — do not wipe it while the runner pod is up. + - name: dind-disk-cap + rules: + # Pi-specific cap, added with the arm64 dind cutover (kanban + # t_0da0a1cc). The two arm64 runners now hold 240 GiB of dind PVCs + # (200Gi shared + 40Gi deploy) on rpi's single root filesystem, which + # is the same disk the kubelet lives on. A static hostPath PV does NOT + # enforce its claim, and the `RunnerDindPvc*` rules cannot fire for it + # (no kubelet_volume_stats_* series on this cluster), so this node + # filesystem rule is the real growth cap: 70 % of 917 G leaves ~275 G, + # i.e. reachable while there is still room to run the prune job. + # `NodeFilesystemFillingUp` below stays at 85 % as the backstop. + - alert: RpiDindDataRootFillingUp + expr: | + ( + 1 - ( + node_filesystem_avail_bytes{mountpoint="/", fstype=~"ext4|xfs|btrfs", instance=~"10.10.0.1:.*"} + / + node_filesystem_size_bytes{mountpoint="/", fstype=~"ext4|xfs|btrfs", instance=~"10.10.0.1:.*"} + ) + ) * on (instance) group_left (nodename) node_uname_info{nodename="rpi"} > 0.70 + for: 30m + labels: + severity: warning + annotations: + summary: >- + rpi root filesystem is {{ $value | humanizePercentage }} full + (dind CI data-roots live here) + description: >- + The arm64 runners' dind data-roots (PVCs forgejo-runner-arm64-dind + 200Gi and forgejo-runner-deploy-arm64-dind 40Gi) share rpi's only + filesystem with the kubelet. Nothing enforces those claim sizes. + Attribute the growth with + `kubectl -n forgejo exec -c dind -- docker system df -v` + (the nightly prune job prints this for every daemon and never + deletes named volumes), then reclaim with + `kubectl -n forgejo create job --from=cronjob/forgejo-runner-prune prune-manual-$(date +%s)`. + See docs/arm64-runner-dind.md §4.4. - name: disk-capacity rules: - alert: NodeFilesystemFillingUp