Skip to content

feat(service): Run the Service rows under a Kubernetes Lease - #6099

Merged
dan-petty merged 5 commits into
mainfrom
feat/6058-service-surge-release
Nov 17, 2026
Merged

dan-petty merged 5 commits into
mainfrom
feat/6058-service-surge-release

Conversation

@dan-petty

@dan-petty dan-petty commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Only the pod that holds the Kubernetes Lease roadmap-service-rows now reads the state files and runs the rows of the roadmap Service; a pod that waits keeps its deliveries in its lane queues, and a pod gives the Lease back after its drain. A preStop sleep of 10 s keeps the socket open while the endpoint leaves, and the pod name is service.instance.id. The Deployment keeps Recreate (expand/contract): the release with the Lease code stops the old pod before the new one starts. #6107 then switches to RollingUpdate with maxSurge 1 and maxUnavailable 0.

Live check: after the release with this code, kubectl -n devops get lease roadmap-service-rows -o jsonpath='{.spec.holderIdentity}' names the running pod.

Closes #6058

Change: openspec/changes/archive/2026-11-17-6058-service-surge-release/

@dan-petty dan-petty added type/feature Type feature: a new function scope/service The long-running devops Service and its lanes labels Nov 17, 2026
@dan-petty

dan-petty commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner Author

Details of step 1 of #6058

Tool

The Lease API coordination.k8s.io/v1, through the CustomObjectsApi of the official kubernetes client 36.0.3 that the project uses (k8s/api.py, the same seam as the Jobs of the Service).

  • Client 36.0.3: kubernetes.leaderelection has a ConfigMap lock only, a thread loop that does not stop, and no release.
  • Client 37.0.2 (2026-10-24): adds LeaseLock and an asyncio loop, but it moves each model of the client to pydantic, which is a migration of the whole k8s seam. Its loop also has no stop and no release.

So src/devops_cli/k8s/lease.py (about 300 lines with its docstrings) applies the rules of the leader election of client-go: expiry on the observed time of the follower, the resourceVersion of the last read on each write, a renew deadline, and ReleaseOnCancel. Cost: about 150,000 model tokens and 4 hours. #4575 removes it.

RBAC (Role roadmap-service-jobs)

- apiGroups: ["coordination.k8s.io"]
  resources: ["leases"]
  resourceNames: ["roadmap-service-rows"]
  verbs: ["get", "update"]
- apiGroups: ["coordination.k8s.io"]
  resources: ["leases"]
  verbs: ["create"]

RBAC cannot limit create to a name: the API server authorizes a create before the object has a name. The Role gets no patch, list, watch or delete on Leases, and no other new permission. The gate checks in tests/gate/k8s_checks/runner.py hold these rules.

Timeout nesting

  • Lease: API call 5 s < renew deadline 10 s < leaseDurationSeconds 15 s. Retry period 2 s (the defaults of client-go).
  • Stop: preStop sleep 10 s + drain 600 s + cut 30 s + release call 5 s at most = 645 s < terminationGracePeriodSeconds 660 s.
  • The drain waits for the workers in a thread, so the event loop renews the Lease during the drain.

Manifest check

kubectl kustomize k8s/devops/roadmap-service | kubeconform -strict -summary -verbose -ignore-missing-schemas -kubernetes-version 1.37.0 (the cluster runs k3s v1.37.2, which has the native preStop sleep action):

render - ServiceAccount roadmap-service is valid
render - Role roadmap-service-jobs is valid
render - Service roadmap-service is valid
render - RoleBinding roadmap-service-jobs is valid
render - PersistentVolumeClaim roadmap-service-home is valid
render - ValidatingAdmissionPolicy roadmap-service-job-deletes is valid
render - ValidatingAdmissionPolicy roadmap-service-jobs is valid
render - ValidatingAdmissionPolicyBinding roadmap-service-jobs is valid
render - ValidatingAdmissionPolicyBinding roadmap-service-job-deletes is valid
render - NetworkPolicy devops-cli-planner-run is valid
render - NetworkPolicy roadmap-service-egress is valid
render - NetworkPolicy roadmap-service-ingress is valid
render - roadmap-service-rate-limit Middleware skipped
render - Ingress roadmap-service is valid
render - CronJob devops-cli-planner-run is valid
render - Deployment roadmap-service is valid
Summary: 16 resources found in 1 file - Valid: 15, Invalid: 0, Errors: 0, Skipped: 1

kube-linter on the same render gives the same 4 findings as on origin/main (latest-tag 2 times, non-existent-service-account, job-ttl-seconds-after-finished). The change adds none.

Tests

  • tests/k8s/test_lease.py: the handover, a killed holder (the other pod takes the Lease at 16 s, not before 15 s), failed renewals (the holder stops at 10 s), a create race, a release that meets a 409.
  • tests/server/test_service_rows_lease.py: a waiting pod is ready and healthy, queues a delivery, and reads the state only when it takes the Lease; a lost Lease stops the rows and fails /healthz; an unreadable record fails /healthz; SIGTERM through the exit handler of a real uvicorn server fails /readyz, keeps renewing during the drain, and gives the Lease back.
  • tests/k8s/test_kubernetes_contract.py: Lease read, create and replace, with the 404 and the two 409s, over the fake and over the real client on recorded answers.
  • Removed: the asserts of Recreate, of no lifecycle hook, and of one fixed instance id in tests/server/routes/test_k8s_roadmap_service.py (owner rule of 2026-11-16, test(k8s): Drop the tests that repeat third-party version pins #6060). config_reads.toml goes from 7 to 5.

Live safety

  • No setting is added or removed, and no credential is added. Argo CD applies the manifest and the Role from main.
  • Expand/contract. This pull request keeps strategy: Recreate. Argo CD applies the manifest at the merge, but Image Updater brings the Lease code only with the next release. With Recreate, the merge rolls the current image with one pod at a time, and the release that carries the Lease code stops the old pod, which has no Lease code, before the new pod starts. So two pods never run the rows at the same time. feat(service): Roll the Service with a surge release #6107 switches to RollingUpdate with maxSurge: 1 and maxUnavailable: 0 once the Lease code runs.
  • The webhook gap of a release stays until feat(service): Roll the Service with a surge release #6107.
  • Live check after the release with this code: kubectl -n devops get lease roadmap-service-rows -o jsonpath='{.spec.holderIdentity}' names the running pod. That is also the premise check of feat(service): Roll the Service with a surge release #6107. After feat(service): Roll the Service with a surge release #6107: zero 5xx in the hook deliveries of a release, and one holder, which changes only after the drain of the old pod ends.

@dan-petty

Copy link
Copy Markdown
Owner Author

Checks on head a6de793: Static Analysis and Semantic PR title pass. The only failing test is tests/roadmap/stage/test_roadmap_stage_window.py::test_a_first_request_of_code_with_the_context_and_the_body_at_their_caps_offers_the_tools (shard 2 of Tests & Coverage, shard 1 of Service Image Tests). It fails the same way on main since 2b4ae1f (#6091), and #6101 holds it. Because shard 2 fails, CI skips the changed-line coverage step; a local diff-cover run gives 97% for the changed lines of the tracked files, and src/devops_cli/k8s/lease.py has its error branches under test.

This pull request stays a draft until #6101 is fixed on main. Then a rebase runs the checks again.

@dan-petty
dan-petty force-pushed the feat/6058-service-surge-release branch from 8f5a9bf to 6265f70 Compare November 17, 2026 02:57
@dan-petty dan-petty changed the title feat(service): Roll each Service release with no webhook gap feat(service): Run the Service rows under a Kubernetes Lease Nov 17, 2026
@dan-petty
dan-petty marked this pull request as ready for review November 17, 2026 03:22
@dan-petty
dan-petty merged commit 894fbdd into main Nov 17, 2026
36 checks passed
@dan-petty
dan-petty deleted the feat/6058-service-surge-release branch November 17, 2026 07:36
dan-petty-release Bot added a commit that referenced this pull request Nov 17, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.170.0](v0.169.4...v0.170.0)
(2026-11-17)


### Features

* **service:** Run the Service rows under a Kubernetes Lease
([#6099](#6099))
([894fbdd](894fbdd))


### Bug Fixes

* **roadmap:** fix-checks repairs failures its plan causes
([#6121](#6121))
([78544b3](78544b3))
* **roadmap:** mark a draft ready only when draft readiness allows it
([#6132](#6132))
([e0c0cdb](e0c0cdb))
* **roadmap:** Stop the false strength failure and log the volume use
([#6111](#6111))
([3d2b4e2](3d2b4e2))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/service The long-running devops Service and its lanes type/feature Type feature: a new function

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(service): Roll each Service release with no webhook gap

1 participant