Repository navigation
Description
Split from #5296.
Problem: no check in devops-cli asserts the prune value or the git source repository of an Argo CD Application today; the old test_k8s_argocd_apps.py assertions are gone, and the Applications of devops-cli name dan-petty/devops-cli with prune on. The homelab copy must name dan-petty/homelab in each git source, except Application devops (devops-cli k8s/devops on main) and the product ref of Application prometheus (devops-cli main), and its prune value changes at #5134 step 5a (plan step 13). Why deferred: the values describe the live homelab copy, and a pull request in devops-cli cannot read or change the private homelab tree. Acceptance criteria: the homelab workflow runs the Argo CD Applications check with dan-petty/homelab as the expected source repository and false as the prune value before #5134 step 5a and true after it; the check reports a mismatch of a source repository or of the prune value, and a matching tree passes.
Proposed design
Problem statement
devops-cli has no check that asserts the git source repository and the automated prune value of the Argo CD Applications in an environment tree; the old test_k8s_argocd_apps.py assertions are gone. The homelab environment tree needs the check to hold dan-petty/homelab as its source repository and its prune value, while the product sources of Applications devops and prometheus stay on dan-petty/devops-cli. This issue adds the reusable devops k8s argocd-apps-check command with the expected repository, the expected prune value and a per-Application allowlist as arguments. The homelab workflow wiring is deferred to a new issue because a pull request in devops-cli cannot read or change the private homelab tree.
Acceptance criteria
Requirement: Argo CD Applications check
The devops k8s argocd-apps-check command SHALL validate the git source repository and the automated prune value of each Argo CD Application in an environment tree.
Scenario: Matching tree passes
- WHEN A test runs
uv run devops k8s argocd-apps-check --k8s-dir <fixture> --expected-repo dan-petty/homelab --expected-prune falseon a fixture where every Application nameshttps://github.com/dan-petty/homelaband setsspec.syncPolicy.automated.prune: false. - THEN The command exits 0 and prints the number of Applications checked.
Requirement: Source repository mismatch
The check MUST exit non-zero and name the Application, the actual repository and the expected repository when a git source repository differs from the expected repository.
Scenario: Mismatched source repository fails
- WHEN A test runs the check on a fixture where Application
apinameshttps://github.com/dan-petty/otherand the expected repository isdan-petty/homelab. - THEN The command exits 1 and prints
api,dan-petty/otheranddan-petty/homelab.
Requirement: Prune value mismatch
The check MUST exit non-zero and name the Application, the actual prune value and the expected prune value when the automated prune value differs from the expected value.
Scenario: Mismatched prune value fails
- WHEN A test runs the check on a fixture where Application
apisetsspec.syncPolicy.automated.prune: trueand the expected prune value isfalse. - THEN The command exits 1 and prints
api,trueandfalse.
Requirement: Missing prune value
The check MUST treat an Application with no spec.syncPolicy.automated.prune as a prune value mismatch and name the Application.
Scenario: Missing prune value fails
- WHEN A test runs the check on a fixture where Application
apihas nospec.syncPolicy.automated.pruneand the expected prune value isfalse. - THEN The command exits 1 and prints
api,(absent)andfalse.
Requirement: All git sources
The check MUST validate every git source in spec.source and spec.sources of an Application and MUST ignore a source that names a chart.
Scenario: Second source mismatch fails
- WHEN A test runs the check on a fixture where an Application has a matching first git source, a mismatching second git source, and a chart source that names
https://prometheus-community.github.io/helm-charts. - THEN The command exits 1, names the Application and the mismatching second source, and reports no mismatch for the chart source.
Requirement: Product source allowlist
The check SHALL accept repeatable --allow-source <application>=<repository> entries that allow the named Application to name that repository in addition to the expected repository.
Scenario: Product exception passes
- WHEN A test runs the check with
--expected-repo dan-petty/homelab --expected-prune false --allow-source devops=dan-petty/devops-cli --allow-source prometheus=dan-petty/devops-clion a fixture where those Applications namehttps://github.com/dan-petty/devops-cliand every other git source nameshttps://github.com/dan-petty/homelab. - THEN The command exits 0 and reports no source repository mismatch for
devopsandprometheus.
Requirement: Empty tree
The check MUST exit non-zero and report that it found no Applications when the environment tree holds no Argo CD Application.
Scenario: Empty tree fails
- WHEN A test runs the check with
--expected-repo dan-petty/homelab --expected-prune falseon a fixture environment tree with nokind: Applicationdocument. - THEN The command exits 1 and prints
no Applications found.
Existing Tool Considered
No alternatives check has run. Conftest (Open Policy Agent, CNCF) is an open, maintained policy engine that asserts YAML fields with Rego rules; ADR 0011 records that a 20-line Rego rule enforced the Argo CD placeholder rule in scratch and keeps the Argo CD checks in Python because a Rego copy duplicates argocd_overrides._host_fields (docs/adr/0011-releases-come-from-trunk-towncrier-uv-and-semver-tags-instead-of-a-bespoke-cut.md:78). The Kyverno CLI that devops k8s validate-policy wraps (src/devops_cli/config/commands.py:331) is the same class of tool. They lack environment-tree resolution, per-run expected values and the per-Application allowlist without a generated policy. The proposal adds a small Python module and command over discover_argocd_applications (src/devops_cli/k8s/argocd_gate.py:55) and application_sources (src/devops_cli/k8s/app_sources.py:145). The written cost is about 200 lines of Python and tests, about 2M agent tokens to build, 0.2M a quarter to keep, and 1-2 days.
Key questions
- Which command and interface deliver the Argo CD Application invariant check?: Add
devops k8s argocd-apps-checkwith--k8s-dir, required--expected-repo, required--expected-prune true|falseand repeatable--allow-source. (best practice) [sources: src/devops_cli/commands/k8s/init.py:88, src/devops_cli/commands/k8s/image_pins.py:43, src/devops_cli/k8s/argocd_gate.py:257, docs/adr/0011-releases-come-from-trunk-towncrier-uv-and-semver-tags-instead-of-a-bespoke-cut.md:78]- Chosen: New
devops k8s argocd-apps-checksubcommand. It follows the k8s subcommand pattern (image-pins,searxng-check) and takes--k8s-dirlikeimage-pins, so the homelab workflow can run it on its own tree. - Rejected: Extend
check_argocd_gate.check_argocd_gateis a build-gate function with no command (src/devops_cli/k8s/argocd_gate.py:257); extending it would run the environment invariant indevops ci, which cannot read the private homelab tree, and would mix the build gate with the tree invariant. - Rejected: Conftest policy. ADR 0011 records that a Rego copy duplicates the Python rule and leaves a move to Rego as a follow-up (
docs/adr/0011-releases-come-from-trunk-towncrier-uv-and-semver-tags-instead-of-a-bespoke-cut.md:78); the policy also cannot resolve the environment tree or take the per-run expected values and allowlist without a generated policy.
- Chosen: New
- How does the check handle the product sources for
devopsandprometheus?: Use repeatable--allow-source <application>=<repository>entries that allow the named Application to name that repository in addition to the expected repository. The homelab workflow passesdevops=dan-petty/devops-cliandprometheus=dan-petty/devops-cli. (best practice) [sources: k8s/argocd/apps/devops.yaml:18, k8s/argocd/apps/prometheus.yaml:18, docs/HOMELAB_REPO_SWITCH.md:162]- Chosen: Additive allowlist. It keeps the expected repository as the rule for every other git source of the Application, so only the named product repository is excused.
- Rejected: Override the expected repository for the named Application. It would excuse a wrong homelab source on
prometheusordevops, because the whole Application would leave the expected repository. - Rejected: Hardcode the homelab names in devops-cli. It couples the check to one environment tree.
- Rejected: Use a separate config file. It adds a file format for two entries.
- Does the check validate a chart source's
repoURL?: No. A source with achartnames a Helm repository, not a git repository; only a source with nochartis a git source and is validated. (best practice) [sources: k8s/argocd/apps/prometheus.yaml:11, src/devops_cli/k8s/app_sources.py:145]- Chosen: Skip chart sources. A source with a
chartnames a Helm repository (k8s/argocd/apps/prometheus.yaml:11), so itsrepoURLis not a git source. - Rejected: Check every
repoURL. It would fail every Helm Application whose chart repository is not the environment repository. - Rejected: Check only
spec.source. It would miss the second source of a multi-source Application, such as the product ref ofprometheus(k8s/argocd/apps/prometheus.yaml:18).
- Chosen: Skip chart sources. A source with a
- How does the check treat an Application with no
spec.syncPolicy.automated.prune?: A missing value is a mismatch: the check reads the explicit field and fails the Application with(absent)as the actual value. The homelab runbook sets the field in all 34 Applications, so the invariant is the explicit value, not Argo CD's default. (best practice) [sources: docs/HOMELAB_REPO_SWITCH.md:170, k8s/argocd/apps/devops.yaml:27]- Chosen: Absent is a mismatch. The runbook sets the field in all 34 Applications, so the invariant is the explicit value and a missing field is a mistake.
- Rejected: Absent means false. It hides a missing setting and would pass before the field is written.
- Rejected: Ignore an Application with no automated sync. It weakens the invariant for the Applications that the runbook names.
- Does the check depend on feat(argocd): read the environment from the homelab repo #5134 step 5a?: No. The expected prune value is a command argument, so the check needs no code change when the homelab prune value changes. The runbook has prune off in all 34 Applications after step 11 and turns it on in step 13, so the homelab workflow passes
falsebefore feat(argocd): read the environment from the homelab repo #5134 step 5a andtrueafter it. (best practice) [sources: docs/HOMELAB_REPO_SWITCH.md:170, docs/HOMELAB_REPO_SWITCH.md:197]- Chosen: Parameterize the expected prune value. The check needs no code change when the homelab prune value changes at feat(argocd): read the environment from the homelab repo #5134 step 5a.
- Rejected: Hardcode
falseand change the code at feat(argocd): read the environment from the homelab repo #5134 step 5a. It adds a later devops-cli code change for an environment value.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
devops-cli-service commentedon Nov 17, 2026
homelab, and .github/labels.yml declares no scope/homelab label. Add the label to the file to give the scope to this item.Both target homelab CI checks; #5296 is the umbrella for all environment checks, while this item adds only the Argo CD source-repo and prune-value assertion.devops-cli-service commentedon Nov 18, 2026
Waiting for the alternatives check to run. The next refine round looks at the item again after the check records a verdict.
dan-petty commentedon Nov 26, 2026
Closed: dan-petty/homelab already holds this invariant.
Its workflow runs
make k8s-parity(scripts/k8s-checks.py), which fails when a git source of the owner names the wrong repository or revision, and when an Application does not setprune: truewithPrune=confirm. A newdevops k8s argocd-apps-checkcommand would be a second check of the same rule.