cnpg: widen operator leader-election window + adopt the operator into Flux

Shared-NVMe contention on the T480, not a uniformly slow disk: etcd WAL fsync
has 158 samples >8.192s over 41d while 99.9% land <=32ms, and all 8 hours with
>=2s stalls have CI build I/O on the same PM991 NVMe (worst single stall
10.39s, dind data-root and forgejo-data share /dev/nvme0n1p3 with the WAL).
Each stall blows the operator's 5s lease-renewal HTTP timeout and
controller-runtime fatals with "leader election lost" (223 restarts in 45d).
Lease 60s / renew 45s rides out a 10.4s stall instead of restarting the
operator; safe at replicas: 1, there is no second holder to split-brain
against. CNPG's flags are integer seconds and it has no resource-lock-timeout
flag, unlike the Cilium operator.

The operator was installed by hand, so a kubectl patch would be lost on the
next reinstall. Vendor the pinned 1.30.0 release manifest under
infrastructure/databases/base and own it with its own Flux Kustomization
(prune: false -- the bundle carries the 11 CNPG CRDs, and pruning those would
delete every Cluster). The patch also declares the pre-existing live deltas
that upstream does not ship: the overlay API env (10.10.0.2:6443), the
500m/512Mi limits and the 3min startup probe -- adopting upstream raw would
have silently reverted all three.
This commit is contained in:
Lance Walters 2026-10-26 15:38:42 -04:00
commit d5d1d2882a
4 changed files with 20929 additions and 1 deletions

View file

@ -0,0 +1,19 @@
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: databases
namespace: flux-system
spec:
interval: 10m0s
retryInterval: 1m
timeout: 5m
sourceRef:
kind: GitRepository
name: flux-system
path: ./infrastructure/databases/base
# The CloudNativePG operator bundle contains its 11 CRDs. Those must never be
# pruned automatically: dropping them would delete every Cluster/Database
# object (and the Forgejo and portal Postgres clusters with them). Same
# reasoning as gateway-api-crds. Reverting the operator Deployment args is a
# git change, not a prune.
prune: false

View file

@ -1,3 +1,15 @@
# CloudNativePG operator, pinned at 1.30.0.
#
# The operator was installed by hand at some point and Flux did not own it, so
# a kubectl patch was lost on every reinstall. The upstream release manifest is
# vendored verbatim (sha256 f8bede43fe4ee0d478c2355b204a36876b2ae4faac60f2a9452280b293da3b88,
# https://github.com/cloudnative-pg/cloudnative-pg/releases/download/v1.30.0/cnpg-1.30.0.yaml)
# and patched only for the deltas that already existed live plus the widened
# leader-election window. Do not upgrade the version in this directory without
# a separate, tested change: the CRDs are in this bundle.
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources: []
resources:
- upstream/cnpg-1.30.0.yaml
patches:
- path: patch-controller-manager.yaml

View file

@ -0,0 +1,51 @@
# Live-state delta for the CloudNativePG operator, kept deliberate.
#
# Everything below is a hand-applied change that exists on the running
# cnpg-controller-manager but is NOT in the upstream 1.30.0 release manifest.
# Adopting upstream raw would silently revert them, so they are declared here
# as the operator's real configuration.
#
# Leader election: single-node etcd on the T480's PM991 NVMe stalls WAL fsync
# for multiple seconds during heavy Forgejo dind builds. The apiserver stops
# answering, client-go's 5s lease-renewal HTTP timeout expires, and
# controller-runtime fatals with "leader election lost" (223 restarts / 45d).
# Lease 60s / renew 45s rides out a stall instead of restarting the operator.
# Safe with replicas: 1 -- there is no second holder to split-brain against.
# NOTE: these flags are integer SECONDS, not Go durations.
apiVersion: apps/v1
kind: Deployment
metadata:
name: cnpg-controller-manager
namespace: cnpg-system
spec:
template:
spec:
containers:
- name: manager
args:
- controller
- --leader-elect
- --leader-lease-duration=60
- --leader-renew-deadline=45
- --max-concurrent-reconciles=10
- --config-map-name=cnpg-controller-manager-config
- --secret-name=cnpg-controller-manager-config
- --webhook-port=9443
# The pod talks to the API over the WireGuard overlay address
# (10.10.0.2:6443); the in-cluster 10.96.0.1 Service VIP is not
# reachable from this namespace (see k8s-api firewall on the T480).
env:
- name: KUBERNETES_SERVICE_HOST
value: "10.10.0.2"
- name: KUBERNETES_SERVICE_PORT
value: "6443"
# Upstream ships 100m/200Mi, which is tight enough that the operator
# was starved on this box. Raised by hand; keep it.
resources:
limits:
cpu: 500m
memory: 512Mi
# Upstream gives the manager 6*5s = 30s to answer /readyz, which is
# shorter than a real NVMe fsync stall. 36*5s = 3min.
startupProbe:
failureThreshold: 36

File diff suppressed because it is too large Load diff