Skip to content

feat(homelab): set the Argo CD invariants of the environment copy #6176

Not planned

Description

@devops-cli-service

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 false on a fixture where every Application names https://github.com/dan-petty/homelab and sets spec.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 api names https://github.com/dan-petty/other and the expected repository is dan-petty/homelab.
  • THEN The command exits 1 and prints api, dan-petty/other and dan-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 api sets spec.syncPolicy.automated.prune: true and the expected prune value is false.
  • THEN The command exits 1 and prints api, true and false.

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 api has no spec.syncPolicy.automated.prune and the expected prune value is false.
  • THEN The command exits 1 and prints api, (absent) and false.

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-cli on a fixture where those Applications name https://github.com/dan-petty/devops-cli and every other git source names https://github.com/dan-petty/homelab.
  • THEN The command exits 0 and reports no source repository mismatch for devops and prometheus.

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 false on a fixture environment tree with no kind: Application document.
  • 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-check with --k8s-dir, required --expected-repo, required --expected-prune true|false and 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-check subcommand. It follows the k8s subcommand pattern (image-pins, searxng-check) and takes --k8s-dir like image-pins, so the homelab workflow can run it on its own tree.
    • Rejected: Extend check_argocd_gate. check_argocd_gate is a build-gate function with no command (src/devops_cli/k8s/argocd_gate.py:257); extending it would run the environment invariant in devops 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.
  • How does the check handle the product sources for devops and prometheus?: 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 passes devops=dan-petty/devops-cli and prometheus=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 prometheus or devops, 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 a chart names a Helm repository, not a git repository; only a source with no chart is 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 chart names a Helm repository (k8s/argocd/apps/prometheus.yaml:11), so its repoURL is 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 of prometheus (k8s/argocd/apps/prometheus.yaml:18).
  • 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 false before feat(argocd): read the environment from the homelab repo #5134 step 5a and true after it. (best practice) [sources: docs/HOMELAB_REPO_SWITCH.md:170, docs/HOMELAB_REPO_SWITCH.md:197]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/feature
    source/agent
    status/new
    value/medium
    effort/low
    on Nov 17, 2026
  2. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    ContributorAuthor
    • Scope: none. The title has the scope homelab, and .github/labels.yml declares no scope/homelab label. Add the label to the file to give the scope to this item.
    • Related: feat(k8s): run the environment checks in homelab CI #5296, which asks for a different change. 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.
  3. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    ContributorAuthor

    Waiting for the alternatives check to run. The next refine round looks at the item again after the check records a verdict.

  4. dan-petty commented on Nov 26, 2026

    @dan-petty
    Owner

    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 set prune: true with Prune=confirm. A new devops k8s argocd-apps-check command would be a second check of the same rule.

  5. removed
    status/new
    on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumsource/agenttype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions