Post

Reading the server PodList during n8n checkpoint cleanup

Reading the server PodList during n8n checkpoint cleanup

I tightened the checkpoint cleanup step so it no longer trusts a formatted kubectl output and instead reads the raw server PodList, which carries the resource version and pagination metadata the gate needs to be sure the namespace is empty.

How the cleanup now reads the server PodList

I replaced the old kubectl get pods -l ... -o json call with a kubectl get --raw request against the /api/v1/namespaces/automation/pods endpoint, passing the owner label as a URL-encoded selector. The raw response preserves the server PodList kind, its resourceVersion, and any continue token, which lets the gate detect partial results or missing versions instead of silently treating an empty list as proof of absence. The shell helper now builds the exact path with the encoded selector and pipes the raw JSON into the check.

What the updated test proves

The Python test grew to cover the actual API path and its metadata. It now asserts the request URL starts with the expected limit=500&labelSelector= prefix and that the owner label value is appended exactly. It injects several server responses: one with a valid resource version, one with an empty version, one with a pagination token, and one that raises a partial error. The test also distinguishes between a PodList and the generic List kind that kubectl would print, making sure the cleanup client handles both. When a lingering pod record exists, the test returns a single item; otherwise an empty list, and the exit code signals failure only for the partial-error case.

Where this design transfers to the platform team

I documented the new gate in the operations guide, stating that before any reader policy is removed the cleanup step must observe a complete, empty Kubernetes PodList with a server resource version. This turns a runtime heuristic into a repeatable check that any namespace-scoped cleanup can adopt. A platform team running similar paired deployments can copy the raw-API pattern and the test matrix to enforce the same guarantee without depending on a specific CLI output format.

This post is licensed under CC BY 4.0 by the author.