Repository navigation
Description
Problem Description
devops k8s catalog --check renders the Argo CD applications in a pool of 8 threads (_WORKERS in src/devops_cli/k8s/catalog.py), also in a container with a limit of 1 CPU. A kustomize render that fetches a remote base then can pass the default limit of 27 s that kustomize puts on its git commands, and the command fails. In an implement Job no change of the item can fix this, so the step spends all its repair rounds.
On 2026-12-01 the build of dan-petty/homelab#377 stopped this way after 6 repair rounds, 5.5 million tokens and 65 minutes. Failing command: uv run devops k8s catalog --check --k8s-dir k8s. Error: Kustomize build failed ... k8s/monitoring/dashboards in git checkout FETCH_HEAD of the remote base devops-cli//k8s/devops/dashboards?ref=v0.265.4. The live agent container had a limit of 1 CPU.
Reproduction Steps
- Render a kustomization that names the remote base
https://github.com/dan-petty/devops-cli//k8s/devops/dashboards?ref=v0.265.4once on 1 CPU. - Render it 8 times in parallel on 1 CPU.
Expected vs Actual Behavior
Expected: the number of renders that run at the same time follows the CPUs that the process can use, so the command passes in the runner.
Actual: one render takes 5.5 s. Each of 8 parallel renders takes 25.3 s to 26.8 s, at the limit of 27 s, on a devcontainer that is faster than the node.
os.process_cpu_count() does not read a cgroup CPU quota. Python 3.13 and later reads PYTHON_CPU_COUNT, which the pod template can set from limits.cpu with the downward API. The timeout query parameter of a kustomize remote base also raises the limit in the environment repository.
Environment Diagnostics
Service v0.266.0, runner v0.265.4, devcontainer with kubectl kustomize.
Pre-Submission Checklist
- I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
- I have checked existing issues and pull requests to ensure this is not a duplicate.
Source
Alternatives check of 2026-12-01: none.
Tool: none found.
Reason: Searches found no maintained Python library that reads cgroup v2 cpu.max or the cgroup v1 quota files. psutil and joblib give CPU count or affinity only, so the small render_worker_count helper stays necessary.
Lacks:
- Read of cgroup v2 cpu.max quota
- Read of cgroup v1 cpu.cfs_quota_us and cpu.cfs_period_us
- Quota-aware worker count for the render pools
- Bounds of 1 through 8 on the worker count
Proposed design
Problem statement
The catalog check renders Argo CD applications in a fixed pool of 8 threads. In a 1 CPU container, eight kustomize renders run at the same time and overload the CPU. A remote base fetch can exceed the 27 s git timeout of kustomize. The command fails, and an implement job spends all repair rounds. The fix adds a shared helper that reads the cgroup CPU quota and sets the worker count.
Acceptance criteria
Requirement: Shared helper module
The project MUST provide render_worker_count(cgroup_root=...) in src/devops_cli/k8s/workers.py.
Scenario: Helper import and call
- WHEN The test imports
render_worker_countfromdevops_cli.k8s.workersand calls it withcgroup_root=tmp_path. - THEN The call returns an integer from 1 through 8.
Requirement: Cgroup v2 quota sets workers
The render_worker_count() helper MUST return the ceiling of the cgroup v2 cpu.max quota divided by its period, bounded to 1 through 8.
Scenario: A 1 CPU cgroup v2 quota
- WHEN The test writes
100000 100000tocpu.maxunder a temporary cgroup root and callsrender_worker_count(cgroup_root=tmp_path). - THEN The call returns 1.
Requirement: Cgroup v2 unlimited quota falls back
The render_worker_count() helper MUST use the process CPU count when the cgroup v2 cpu.max file holds max.
Scenario: A cgroup v2 quota of max
- WHEN The test writes
max 100000tocpu.maxunder a temporary cgroup root, patchesos.process_cpu_countto return 3, and callsrender_worker_count(cgroup_root=tmp_path). - THEN The call returns 3.
Requirement: Cgroup v1 quota sets workers
The render_worker_count() helper MUST return the ceiling of the cgroup v1 quota divided by its period, bounded to 1 through 8.
Scenario: A 1 CPU cgroup v1 quota
- WHEN The test writes
100000tocpu/cpu.cfs_quota_usand100000tocpu/cpu.cfs_period_usunder a temporary cgroup root and callsrender_worker_count(cgroup_root=tmp_path). - THEN The call returns 1.
Requirement: Cgroup v1 unlimited quota falls back
The render_worker_count() helper MUST use the process CPU count when the cgroup v1 quota is -1.
Scenario: A cgroup v1 quota of -1
- WHEN The test writes
-1tocpu/cpu.cfs_quota_usand100000tocpu/cpu.cfs_period_usunder a temporary cgroup root, patchesos.process_cpu_countto return 3, and callsrender_worker_count(cgroup_root=tmp_path). - THEN The call returns 3.
Requirement: Process CPU count fallback
The render_worker_count() helper MUST use os.process_cpu_count() when no cgroup CPU quota is set.
Scenario: No cgroup quota
- WHEN The test uses a temporary cgroup root with no
cpu.maxfile and nocpu/cpu.cfs_quota_usfile, patchesos.process_cpu_countto return 3, and callsrender_worker_count(cgroup_root=tmp_path). - THEN The call returns 3.
Requirement: Process CPU count None fallback
The render_worker_count() helper MUST return 1 when os.process_cpu_count() returns None and no cgroup CPU quota is set.
Scenario: No process CPU count
- WHEN The test uses a temporary cgroup root with no quota file, patches
os.process_cpu_countto returnNone, and callsrender_worker_count(cgroup_root=tmp_path). - THEN The call returns 1.
Requirement: Worker count bounds
The render_worker_count() helper MUST keep the worker count between 1 and 8.
Scenario: High and zero CPU counts
- WHEN The test patches
os.process_cpu_countto return 64, then to return 0, and callsrender_worker_count(cgroup_root=tmp_path)for each value with no quota file. - THEN The first call returns 8 and the second call returns 1.
Requirement: Catalog uses the worker count
The catalog build MUST use render_worker_count() as the max_workers value of its thread pool.
Scenario: Catalog pool size
- WHEN The test patches
devops_cli.k8s.catalog.render_worker_countto return 2, patchesThreadPoolExecutorin the same module, and runsbuild_catalogwith a fake environment that has one application. - THEN The fake
ThreadPoolExecutorrecordsmax_workers=2.
Requirement: Other render pools use the worker count
The app render and image pin pools MUST use render_worker_count() as their max_workers value.
Scenario: Shared worker count
- WHEN The test patches
devops_cli.k8s.app_render.render_worker_countanddevops_cli.k8s.image_pins.render_worker_countto return 2, patchesThreadPoolExecutorin both modules, and runs the code that creates each pool. - THEN Each fake
ThreadPoolExecutorrecordsmax_workers=2.
Requirement: Fixed worker constant removed
The catalog, app render, and image pin modules MUST NOT define a fixed _WORKERS constant.
Scenario: Fixed worker constant removed
- WHEN The test imports
devops_cli.k8s.catalog,devops_cli.k8s.app_render, anddevops_cli.k8s.image_pins. - THEN The test asserts that no module has an attribute named
_WORKERS.
Existing Tool Considered
No open, maintained tool or library covers the need. The alternatives check of 2026-12-01 in the issue body records verdict none and names no tool. Its Lacks: list holds the cgroup reads and the bounded worker count. The change builds src/devops_cli/k8s/workers.py with render_worker_count(). Cost: about 60 lines, 3,000 tokens to build, 1,000 tokens to keep and fix, and 30 minutes.
Key questions
- Where should the shared worker count helper live?: Put
render_worker_count()insrc/devops_cli/k8s/workers.py. The function takes acgroup_rootargument with the default/sys/fs/cgroup. (best practice) [sources: src/devops_cli/k8s/catalog.py:58, src/devops_cli/k8s/app_render.py:43, src/devops_cli/k8s/image_pins.py:88]- Chosen: New module
src/devops_cli/k8s/workers.py. Three modules need the same function. A separate module avoids an import cycle and gives one test target. - Rejected: Keep the helper in
catalog.py.app_render.pyandimage_pins.pywould import the catalog module. That creates a cycle and mixes concerns. - Rejected: Copy the helper into each module. Three copies drift and need three sets of tests.
- Chosen: New module
- How should the helper count the CPUs that the process can use?: Read cgroup v2
cpu.maxfirst. Then read cgroup v1cpu.cfs_quota_usandcpu.cfs_period_us. Useos.process_cpu_count()when no quota is set. Return the ceiling of quota divided by period, bounded to 1 through 8. Return 1 whenos.process_cpu_count()returnsNone. (best practice) [sources: src/devops_cli/k8s/catalog.py:58, src/devops_cli/k8s/app_render.py:43, src/devops_cli/k8s/image_pins.py:88]- Chosen: Read cgroup quota and fall back to process count. It gives 1 worker for a 1 CPU limit and still works outside a container.
- Rejected: Keep the fixed pool of 8. It causes the timeout in a 1 CPU container.
- Rejected: Use only
os.process_cpu_count(). The issue states that it does not read a cgroup CPU quota.
- Should the same worker count apply to the app render and image pin pools?: Yes. Replace the fixed
_WORKERSvalue incatalog.py,app_render.py, andimage_pins.pywithrender_worker_count(). (best practice) [sources: src/devops_cli/k8s/catalog.py:58, src/devops_cli/k8s/app_render.py:43, src/devops_cli/k8s/image_pins.py:88]- Chosen: Use the shared function in all three pools. One source of truth fixes the same fan-out risk in each render command.
- Rejected: Change only the catalog pool. The same timeout risk stays in the other render commands.
- Should the runner pod template set
PYTHON_CPU_COUNTfromlimits.cpu?: No. The helper reads the cgroup quota directly. The pod template needs no environment variable. This keeps the fix testable offline and avoids a manifest change. (best practice) [sources: k8s/devops/roadmap-service/kustomization.yaml, src/devops_cli/k8s/catalog.py:58]- Chosen: Read the cgroup quota in code. It works in any container and a unit test can prove it.
- Rejected: Set
PYTHON_CPU_COUNTin the pod template. It needs a manifest change and a live check, and it duplicates the cgroup value.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Dec 1, 2026
The build of dan-petty/homelab#377 failed after 6 repair rounds because of this, which is a CI failure.Both fix k8s subcommands that time out from parallelism, but the candidate fixes catalog --check worker count while #7900 fixes k8s lint exceeding its 300 s limit.devops-cli-service commentedon Dec 1, 2026
Next step: the alternatives check records a verdict. See the section Proposed design of the body.
devops-cli-service commentedon Dec 1, 2026
The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.
Searches (10)
Tools considered:
Searches run:
Sources:
devops-cli-service commentedon Dec 1, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
devops-cli-service commentedon Dec 1, 2026
Plan state: branch
fix/8002-the-catalog-check-times-out-in, draft pull request #8017. The pull request plans the item and closes no issue. The stage job and the step fix-plan edit this comment, and a comment of each run tells what the run did.The task groups, with the tokens of the inputs of each step, for a budget of 64000 tokens:
18 remaining items
fix(k8s): the catalog check times out in a 1 CPU container (#8002)
docs(spec): archive the change (#8002)
fix(k8s): count the render workers with loky (#8002)
docs(spec): add the catalog check times to the proposal (#8002)
fix(k8s): the catalog check times out in a 1 CPU container (#8002)
docs(spec): archive the change (#8002)
fix(k8s): count the render workers with loky (#8002)
docs(spec): add the catalog check times to the proposal (#8002)
test: keep the fixture order in the host CPU fake (#8002)
devops-cli-service commentedon Dec 1, 2026
Released in v0.270.1: https://github.com/dan-petty/devops-cli/releases/tag/v0.270.1
devops-cli-service commentedon Dec 1, 2026
Live since 2026-12-01 16:44 UTC