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
8 changes: 5 additions & 3 deletions docs/CLUSTER.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/SERVICE_PATTERNS.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ This document is the project profile of the patterns (owner, 2026-11-13: a spec
| ID | Rule | Why | Check |
| :--- | :--- | :--- | :--- |
| WK1 | A long-running pod serves requests only. Work on a schedule or from a queue runs as a Job or an Argo Workflow that an event or a CronWorkflow starts. A model call runs only in a unit, never in the router. | Owner, 2026-11-11: Service work moves off the pod to Jobs, Argo Workflows and events, with Valkey. [ADR 0021](adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md), sections 1, 2 and 5. [ARCHITECTURE.md](../ARCHITECTURE.md#7-service-work-and-shared-state), section 7.7. [Kubernetes guideline](guidelines/kubernetes.md#batch-jobs), Batch Jobs. | No check yet (#4517, the tracker of the moves). |
| WK2 | Work that must run one at a time has one holder. A scheduled singleton is a CronWorkflow with `concurrencyPolicy: Forbid` and a mutex, or a CronJob with `concurrencyPolicy: Forbid`. While a singleton loop runs in a long-running pod, the pod takes a Kubernetes Lease before it runs the loop, and another replica waits. A pod that stops gives the Lease back. When a holder is killed, the Lease ends after its duration, and another pod takes it. | [ADR 0021](adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md), section 2 (mutexes, the sweep lock). [ADR 0008](adr/0008-argo-workflows-run-the-roadmap-jobs-after-a-measured-go.md): the controller runs one replica with no leader election. [Leases](https://kubernetes.io/docs/concepts/architecture/leases/); [Argo Workflows synchronization](https://argo-workflows.readthedocs.io/en/latest/synchronization/). | Argo Workflows and the CronJob controller apply the mutex and `Forbid`. The Lease handover during a rollout: no check yet (#6058). |
| WK2 | Work that must run one at a time has one holder. A scheduled singleton is a CronWorkflow with `concurrencyPolicy: Forbid` and a mutex, or a CronJob with `concurrencyPolicy: Forbid`. While a singleton loop runs in a long-running pod, the pod takes a Kubernetes Lease before it runs the loop, and another replica waits. A pod that stops gives the Lease back. When a holder is killed, the Lease ends after its duration, and another pod takes it. | [ADR 0021](adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md), section 2 (mutexes, the sweep lock). [ADR 0008](adr/0008-argo-workflows-run-the-roadmap-jobs-after-a-measured-go.md): the controller runs one replica with no leader election. [Leases](https://kubernetes.io/docs/concepts/architecture/leases/); [Argo Workflows synchronization](https://argo-workflows.readthedocs.io/en/latest/synchronization/). | Argo Workflows and the CronJob controller apply the mutex and `Forbid`. The Lease `roadmap-service-rows` of the rows of the roadmap Service: `tests/k8s/test_lease.py` (the handover, a killed holder, a lost Lease) and `tests/server/test_service_rows_lease.py` (a pod that waits, the stop on SIGTERM), over the fake of the Lease API. Live check: `kubectl -n devops get lease roadmap-service-rows` shows one holder (#6058). |
| WK3 | Each job has its own lane and its own limit of units in flight. No job waits for another job. An event wakes the lanes of the jobs that it makes due. | Owner, 2026-11-13 (#5553, #5555). [ADR 0021](adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md), section 5 (the semaphores). | `tests/server/test_server_service.py`: `test_a_webhook_runs_the_status_lane_while_the_model_lanes_round_is_blocked`. Events that wake lanes: #5555. |
| WK4 | A job checks its item out when it starts and checks it in when it ends. A job that stops keeps a state that the next unit can continue. The poll frees the check-out of a job that is missing or failed. | Owner, 2026-11-13. [ARCHITECTURE.md](../ARCHITECTURE.md#7-service-work-and-shared-state), section 7.7 (Service tasks). | `tests/roadmap/stage/test_roadmap_stage_job_entry.py`: `test_a_normal_end_stages_the_item_writes_the_result_and_clears_the_check_out`, `test_sigterm_before_the_budget_ends_exits_75_and_keeps_the_check_out`. The recovery by the poll: #5524. |

Expand All @@ -59,9 +59,9 @@ This document is the project profile of the patterns (owner, 2026-11-13: a spec

| ID | Rule | Why | Check |
| :--- | :--- | :--- | :--- |
| RL1 | A workload that serves traffic rolls with no gap. It runs 2 or more replicas with `RollingUpdate` and `maxUnavailable: 0`, and a PodDisruptionBudget. The new pod gets traffic only after its readiness probe passes. A workload that cannot do this yet gives its rollout and the reason in its product document, with the issue that removes the reason. | Owner, 2026-11-16 (#6058): rolling releases with health checks before the traffic moves. [ADR 0021](adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md), section 1. [SRE guideline](guidelines/sre.md#change-safety), Change safety. [Rolling update](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#rolling-update-deployment); [PodDisruptionBudget](https://kubernetes.io/docs/tasks/run-application/configure-pdb/). | kube-linter `no-rolling-update-strategy` and the PodDisruptionBudget checks (#6068). Live check: the hook deliveries of a release show no 5xx (#6058). |
| RL1 | A workload that serves traffic rolls with no gap. It runs 2 or more replicas with `RollingUpdate` and `maxUnavailable: 0`, and a PodDisruptionBudget. The new pod gets traffic only after its readiness probe passes. A workload that cannot do this yet gives its rollout and the reason in its product document, with the issue that removes the reason. | Owner, 2026-11-16 (#6058): rolling releases with health checks before the traffic moves. [ADR 0021](adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md), section 1. [SRE guideline](guidelines/sre.md#change-safety), Change safety. [Rolling update](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#rolling-update-deployment); [PodDisruptionBudget](https://kubernetes.io/docs/tasks/run-application/configure-pdb/). | kube-linter `no-rolling-update-strategy` and the PodDisruptionBudget checks (#6068). Live check: the hook deliveries of a release show no 5xx (#6058). Exception: the roadmap Service runs one replica with `Recreate` until the release that carries its Lease code runs (#6058), and #6107 then switches it to a surge release. It keeps one replica and no PodDisruptionBudget, so a drain of its node still stops the webhooks for a time ([docs/CLUSTER.md](CLUSTER.md#roadmap-service)). #4575 removes the exception. |
| RL2 | Each container that serves traffic has a readiness probe. A liveness probe checks only that the process makes progress, never a dependency. A container with a slow start gets a startup probe. An HTTP service serves `/readyz` and `/healthz`. | [Kubernetes guideline](guidelines/kubernetes.md#probes), Probes. [Configure Liveness, Readiness and Startup Probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/). | `tests/server/test_server_service.py`: `test_readyz_and_healthz_lifecycle`. kube-linter `no-readiness-probe`, `no-liveness-probe` (#6068). |
| RL3 | On SIGTERM, a process fails its readiness, takes no new work, and lets the work in flight end in a drain limit. The drain limit is shorter than `terminationGracePeriodSeconds`, with a margin (CL1). Use a preStop hook only when the process stops before its endpoints change. | #4485. [Twelve-Factor IX](https://12factor.net/disposability): fast start and graceful stop. [Termination of Pods](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination). | `tests/server/test_server_service.py`: `test_a_drain_lets_the_round_in_flight_end_and_starts_no_new_round`, `test_a_round_still_in_flight_after_the_drain_wait_ends_at_its_next_github_request`. |
| RL3 | On SIGTERM, a process fails its readiness, takes no new work, and lets the work in flight end in a drain limit. The drain limit is shorter than `terminationGracePeriodSeconds`, with a margin (CL1). Use a preStop hook only when the process stops before its endpoints change. | #4485. [Twelve-Factor IX](https://12factor.net/disposability): fast start and graceful stop. [Termination of Pods](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination). | `tests/server/test_server_service.py`: `test_a_drain_lets_the_round_in_flight_end_and_starts_no_new_round`, `test_a_round_still_in_flight_after_the_drain_wait_ends_at_its_next_github_request`. `tests/server/test_service_rows_lease.py`: `test_sigterm_fails_readyz_renews_the_lease_through_the_drain_and_then_gives_it_back`. The roadmap Service has a preStop `sleep` of 10 s, because uvicorn closes its socket before the drain (#6058). |
| RL4 | A release or a ConfigMap edit stops no work in flight. A unit reads the ConfigMap at its start, so an edit reaches the next unit. A Job does not count an eviction as a failure (`podFailurePolicy` with `Ignore` on `DisruptionTarget`). A step exits 75 to get a retry. Do not hold releases back to hide a fault of a rollout: fix the workload. | Owner, 2026-11-13: keep a high release cadence, and make the jobs survive rollouts (#4559). [ADR 0021](adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md), section 2. [Agentic jobs guideline](guidelines/agentic-jobs.md#the-job-model), Retries. [Pod failure policy](https://kubernetes.io/docs/tasks/job/pod-failure-policy/). | `tests/roadmap/stage/test_roadmap_stage_job_entry.py`: `test_a_provider_timeout_exits_75_and_keeps_the_check_out`, `test_a_clone_failure_exits_75`. |

## 4. Jobs and workflows
Expand Down
5 changes: 3 additions & 2 deletions docs/TELEMETRY.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ trace or a log line and splits no metric stream.
The standard `OTEL_RESOURCE_ATTRIBUTES` sets `service.instance.id`, and the metric
Resource keeps the value. Without that variable, `service.instance.id` is the host
name, which every command on the host shares. roadmap-service sets
`service.instance.id=roadmap-service`, so on the OTLP path a new pod continues the
series of the pod before it. Both CronJob templates set
`service.instance.id` to its pod name from the downward API (#6058): during the surge
release of #6107 the old and the new pod send at the same time, so each pod sends its
own stream, and a new pod starts a new series. Both CronJob templates set
`service.instance.id=devops-cli-job`, so the Job pods of the workload share one stream
and the series of `devops-cli-job` continues across them. Job pods that run at the
same time send into that one stream, so the collector drops a delta whose start time is
Expand Down
2 changes: 1 addition & 1 deletion k8s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ SLO 2 counts only the runner Jobs that end. kube-state-metrics shows a Job only

- Git does not hold the Secrets ([Cluster Secrets](#cluster-secrets)) or ConfigMap `devops-cli-config` ([Homelab Values at Deploy Time](#homelab-values-at-deploy-time)).
- The sweep and its Valkey keep state on `local-path` volumes, which stop with their node ([ADR 0021](../docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md)). The off-node backup of owned state limits the loss.
- The roadmap Service runs one pod with `Recreate` ([Roadmap service](../docs/CLUSTER.md#roadmap-service)).
- The roadmap Service runs one replica with `Recreate` until #6107 switches it to a surge release, and with no PodDisruptionBudget, so a release and a drain of its node still stop the webhooks for a time ([Roadmap service](../docs/CLUSTER.md#roadmap-service), #4575).

**Runbooks for the whole system:** the [stop switch](../docs/CLUSTER.md#stop-switch), the [planned maintenance](#planned-maintenance), the [recovery of Argo CD](#recovery) and the [failure recovery matrix](../docs/ROUTINE_TASKS.md#4-failure-recovery--troubleshooting-matrix).

Expand Down
28 changes: 21 additions & 7 deletions k8s/devops/roadmap-service/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ spec:
# in service.repos. Argo CD self-heals this value, so a scale by hand does not stay. To stop
# the Service, do the stop switch in docs/CLUSTER.md, "Roadmap service".
replicas: 1
# Recreate until the release that carries the Lease code runs (#6058). Only the pod that holds
# the Lease roadmap-service-rows runs the rows, but the pod before that release has no Lease
# code, so this release must stop it before the new pod starts. #6107 then switches to
# RollingUpdate with maxSurge 1 and maxUnavailable 0 (docs/CLUSTER.md, "Roadmap service").
strategy:
type: Recreate
selector:
Expand All @@ -25,9 +29,9 @@ spec:
prometheus.io/scrape: "true"
prometheus.io/port: "8000"
spec:
# CONST_SERVICE_STOP_GRACE_SECONDS: the drain wait (600 s) and the cut wait (30 s) of the
# stop of the Service, and 30 s for the exit (#4485). uvicorn starts the drain on SIGTERM,
# so the pod has no preStop hook: one would use the same grace period first.
# CONST_SERVICE_STOP_GRACE_SECONDS: the preStop sleep (10 s), the drain wait (600 s) and the
# cut wait (30 s) of the stop of the Service (#4485), the call that gives back the Lease
# (5 s), and 15 s for the exit (#6058).
terminationGracePeriodSeconds: 660
# local-path binds the volume on the node where the pod first runs, and the root disk of the
# control-plane node has the least free space (#1634; k8s/README.md, Local-Path Volume Placement).
Expand Down Expand Up @@ -121,11 +125,15 @@ spec:
value: /home/devops/.data
- name: OTEL_SERVICE_NAME
value: roadmap-service
# Prometheus names the series by service.instance.id (`instance`). It defaults to
# the host name, which is the pod name and changes at each restart. One replica
# and the Recreate strategy mean one pod sends at a time, so all pods share one id.
# The pod name: the holder identity of the Lease roadmap-service-rows, and the
# service.instance.id (`instance`) of the metrics. During the surge release of #6107
# two pods send at the same time, so each pod sends its own metric stream (#6058).
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: OTEL_RESOURCE_ATTRIBUTES
value: service.instance.id=roadmap-service
value: service.instance.id=$(POD_NAME)
# The spans and the log records name the cluster (`k8s.cluster.name`) and the
# namespace (`k8s.namespace.name`) from these two values. The cluster name is the
# name in k8s/monitoring/k8s-monitoring-values.yaml; without it, they name minikube.
Expand Down Expand Up @@ -154,6 +162,12 @@ spec:
- name: kube-api-access
mountPath: /var/run/secrets/kubernetes.io/serviceaccount
readOnly: true
# uvicorn closes its socket on SIGTERM, before the drain. The sleep keeps the socket open
# while the endpoint of the pod leaves the Service, so no webhook meets a closed port.
lifecycle:
preStop:
sleep:
seconds: 10
livenessProbe:
httpGet:
path: /healthz
Expand Down
13 changes: 12 additions & 1 deletion k8s/devops/roadmap-service/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# `roadmap-service-job-deletes` admits the delete of a stage Job and of a suspended fix-checks
# Job, and of no other Job. A Job can take Secret `devops-cli`, which the Service pod holds
# already, so the Role gives no secret that the Service does not have. It reads no Secret and
# creates nothing but Jobs.
# creates nothing but Jobs and the Lease of the rows.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
Expand Down Expand Up @@ -41,6 +41,17 @@ rules:
- apiGroups: [""]
resources: ["pods/log"]
verbs: ["get"]
# The pod that holds the Lease roadmap-service-rows runs the rows (#6058). It reads and renews
# this one Lease, and gives it back with an update.
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
resourceNames: ["roadmap-service-rows"]
verbs: ["get", "update"]
# The first pod creates the Lease. RBAC cannot limit `create` to a name, because the API server
# checks a create before the object has a name, so this rule names no Lease.
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
verbs: ["create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-17
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Design

## Decisions
- Expand/contract: this change keeps `Recreate`, because the pod before the release that carries the Lease code has no Lease code, and a surge would run the rows on both pods. #6107 then sets `maxSurge: 1` and `maxUnavailable: 0`, with one replica. Two pods then run only during a release. The PV of the home volume binds to one node, so the scheduler puts the new pod on that node, and both pods mount the ReadWriteOnce volume.
- The Lease `roadmap-service-rows` guards the rows. A pod takes it when it does not exist, has no holder, or was not renewed for its `leaseDurationSeconds`. Each write sends the `resourceVersion` of the last read, so the API server refuses one of two writes at the same time. The times are the defaults of client-go: a call ends after 5 s, the holder stops at a renew deadline of 10 s, the Lease lasts 15 s, and a pod tries again each 2 s.
- Readiness does not wait for the Lease. If it did, the new pod would never be ready, and with `maxUnavailable: 0` the old pod would never stop.
- A pod that waits keeps each delivery in the queue of its lanes. The workers and the poll start when it takes the Lease, after it reads the budget window, the halt, the ledger of failed rounds, and removes the retired lane state.
- The drain waits for the workers in a thread, so the event loop renews the Lease until the rounds end. Then the pod gives the Lease back, and the next pod takes it within 2 s. When a round is still in flight after the cut wait, the pod keeps the Lease, which ends 15 s after its last renewal.
- A holder that cannot renew for 10 s stops its workers and its poll, and cuts the budget, so a round in flight ends at its next GitHub request. `/healthz` then fails, and the kubelet starts the container again.
- The pod name from the downward API is the holder identity and `service.instance.id`. A restarted container of the same pod holds the same identity, so it takes its own Lease at once.
- The timeouts nest: preStop 10 s + drain 600 s + cut 30 s + release call 5 s = 645 s, inside the grace period of 660 s.
- RBAC: `get` and `update` with `resourceNames: [roadmap-service-rows]`, and `create` with no name, because the API server checks a create before the object has a name.

## Rejected alternatives
- Two replicas and a PodDisruptionBudget now: the PodDisruptionBudget would stop each drain of the node of the volume, and a delivery to the pod with no Lease would wait for a poll. #4575 does this with a stateless router.
- The surge strategy in the same change as the Lease code: Argo CD applies the manifest at the merge, but Image Updater brings the Lease code only with the next release, so two rollouts would run the rows on two pods for one drain each.
- Readiness that waits for the Lease: the rollout stops.
- The leader election of the `kubernetes` client: version 36.0.3 has no Lease lock, and version 37 changes each model of the client. Neither loop stops or gives the Lease back.
- A fixed `service.instance.id`: two pods of a surge release would send deltas into one stream, and the collector drops the points of the older stream.
- A test that reads the manifest: the owner rule of 2026-11-16 (#6060). `kubectl kustomize` with kubeconform checks the manifest, and the live check reads the hook deliveries and the holder of the Lease.
Loading