Skip to content

feat(infra): run drift in the cluster and plan infra PRs #5129

Done

Description

@dan-petty

Problem or Motivation

devops infra drift (#5127) and devops infra plan (#5124) run on a workstation. Nobody runs them on a schedule, and a pull request of an infra repo shows no plan before review. ADR 0021 moves Service work to cluster Jobs and Argo Workflows that an event or a CronWorkflow starts.

Proposed Solution & Architectural Design

Phase 3 of tracker #5120 (design section 8).

  1. A WorkflowTemplate infra-drift and a CronWorkflow (daily) in namespace devops run devops infra drift <repo> for each repo in infra.repos whose level is plan or higher. The runner image gets the pinned [python.ansible] tool environment.
  2. A step job infra-plan runs on each push to an open pull request of an infra repo (the webhook router creates the unit, ADR 0021) and posts the plan table as one PR comment with a marker, updated on the next push.
  3. The Ansible SSH key reaches the pod as a key of a Secret. The owner writes the Secret (devops k8s push-secrets from the keyring); the pod mounts it read-only and passes it as ansible_ssh_private_key_file.
  4. A NetworkPolicy admits egress from these pods on TCP 22 to the node addresses only.
  5. The pods count as agent callers: the access level of each repo applies.

Target Subsystem

Kubernetes & Minikube Automation

Existing Tool Considered

Argo Workflows (CronWorkflow, WorkflowTemplate) and the webhook router of ADR 0021; ansible-runner transmit | worker | process is available if the run must stream from another pod. Cost: about 4M tokens to build, 0.5M a quarter to keep, 6 hours.

Acceptance Criteria

  • Tests: the WorkflowTemplate and the CronWorkflow render, run with the devops-cli-job label, mount the Secret read-only, and pass no other credential.
  • A test: the NetworkPolicy admits TCP 22 to the configured node addresses and nothing else beyond the existing egress.
  • Live: the CronWorkflow runs once on demand for dan-petty/homelab and sets devops_cli_infra_drift_hosts; a test PR of dan-petty/homelab gets 1 plan comment, and a second push updates it.

Dependencies

#5127; owner: the SSH key Secret.

Alternatives check of 2026-11-19: in-use.
The repository already uses this tool.
Tool: argoproj/argo-workflows (https://github.com/argoproj/argo-workflows), Apache-2.0, last activity 2026-11-19, maintained.
Reason: Search found Argo Workflows, the project's cluster workflow engine, which covers scheduled CronWorkflow runs and templated pod steps but lacks the drift loop, the PR plan comment and the SSH key/egress glue the issue needs.

Covers:

  • Daily schedules through a CronWorkflow
  • Reusable WorkflowTemplate step definitions
  • Kubernetes-native pod execution for cluster jobs

Lacks:

  • Drift loop over infra.repos access levels
  • Marked plan comment updated on an infra PR
  • Keyring-to-Secret mount and TCP 22 egress policy

Proposed design

Problem statement

devops infra drift (#5127) and devops infra plan (#5124) run only on a workstation. No schedule runs drift, and an infra pull request shows no plan before review. This change runs drift from a daily Argo CronWorkflow in namespace devops. It starts one infra-plan Job on each push to an infra pull request. It posts one marked plan comment that the next push edits.

Acceptance criteria

Requirement: Drift covers plan repos

The devops infra drift --all command SHALL run the drift of each repo in infra.repos whose agent access level is plan or higher, and SHALL run no drift for a repo at none.

Scenario: Plan repo drifts and none repo does not

  • WHEN uv run pytest tests/infra/test_infra_drift_all.py -q runs with a settings fixture that holds one repo at plan and one at none
  • THEN the command runs the drift once for the plan repo and no time for the none repo

Requirement: Drift CronWorkflow is daily

The infra-drift CronWorkflow SHALL run the infra-drift WorkflowTemplate once a day.

Scenario: Daily CronWorkflow passes the Kubernetes check

  • WHEN uv run devops ci --check --only k8s runs
  • THEN the command prints k8s: <N> cases, 0 failed

Requirement: Drift pod is a job pod with the key Secret

The infra-drift pod template SHALL carry the app.kubernetes.io/name: devops-cli-job label, SHALL run the runner image, and SHALL mount the SSH key Secret read-only as its only SSH credential.

Scenario: Rendered drift pod passes the Kubernetes check

  • WHEN uv run devops ci --check --only k8s runs
  • THEN the command prints k8s: <N> cases, 0 failed

Requirement: Runner image holds the Ansible runner

The runner image SHALL hold ansible-runner, and RUNNER_TOOLS SHALL name it with a job: reason.

Scenario: Runner tools name the Ansible runner

  • WHEN uv run pytest tests/roadmap/test_roadmap_runner_tools.py -q runs
  • THEN ansible-runner is in RUNNER_TOOLS with a job: reason

Requirement: Drift egress is SSH to node CIDRs only

The infra-ssh-egress NetworkPolicy SHALL admit TCP 22 egress from the drift and plan pods only to the configured node CIDRs.

Scenario: Rendered policy passes the Kubernetes check

  • WHEN uv run devops ci --check --only k8s runs
  • THEN the command prints k8s: <N> cases, 0 failed

Requirement: One plan job per pull request head

A pull_request synchronize delivery for an open infra pull request SHALL create exactly one infra-plan Job for that head.

Scenario: Two deliveries for one head create one Job

  • WHEN uv run pytest tests/server/test_server_infra_plan.py -q runs with two synchronize deliveries for the same pull request head
  • THEN the launcher creates one infra-plan Job with the repository, the pull request number and the head, and the second delivery gets the existing unit

Requirement: Plan comment is one and updates

The infra-plan step SHALL post one plan comment with the marker &lt;!-- devops roadmap infra-plan --> and SHALL edit that comment on the next push.

Scenario: Second run edits the first comment

  • WHEN uv run pytest tests/roadmap/steps/test_roadmap_step_infra_plan.py -q runs the step twice with a fake GitHub client
  • THEN the first run creates one comment with the marker, and the second run edits that comment and creates no other

Requirement: Access level gates the plan step

The infra-plan step SHALL run only when the agent access level of the infra repo is plan or higher.

Scenario: Repo at none gets no plan

  • WHEN uv run pytest tests/roadmap/steps/test_roadmap_step_infra_plan.py -q runs with an infra repo at level none
  • THEN the step exits 0, posts no plan comment, and records that infra.repos[].agent_access refused the run

Existing Tool Considered

The alternatives check in the issue body gives the verdict in-use for argoproj/argo-workflows (https://github.com/argoproj/argo-workflows). The repository already uses this tool, so no person decides it. The check block holds what the tool covers and what it lacks. The proposal adds the parts that the tool lacks. devops infra drift --all loops over infra.repos and selects each repo at plan or higher. The infra-plan step posts one comment with the marker &lt;!-- devops roadmap infra-plan --> and edits it on the next push. A read-only Secret volume carries the Ansible SSH key, and the infra-ssh-egress NetworkPolicy admits TCP 22 to the node CIDRs only. That glue costs about 4M tokens to build, 0.5M tokens a quarter to keep, and 6 hours.

Key questions

  • Should the scheduled drift run use Argo Workflows or a Kubernetes CronJob?: Use an Argo WorkflowTemplate infra-drift and a daily CronWorkflow in namespace devops. (best practice) [sources: docs/adr/0008-argo-workflows-run-the-roadmap-jobs-after-a-measured-go.md, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md, k8s/devops/workflowtemplate-rag-ingest.yaml, k8s/devops/cronworkflow-rag-ingest.yaml]
    • Chosen: Argo Workflows. ADR 0008 makes Argo Workflows the engine, and ADR 0021 puts a WorkflowTemplate and a CronWorkflow on each job.
    • Rejected: Kubernetes CronJob. It duplicates the Argo scheduling and templating that the project already runs.
    • Rejected: GitHub Actions. The SSH key and the node access live in the cluster, not in GitHub Actions.
  • Which infra repos get a drift run?: Each repo in infra.repos at plan, safe or full gets a drift run. A repo at none gets none. [sources: SECURITY.md, src/devops_cli/infra/access.py, tests/config/test_infra_repos_setting.py]
  • How does one CronWorkflow cover every repo in infra.repos?: The CronWorkflow holds one static step, devops infra drift --all. That command reads infra.repos and loops over the repos at plan or higher. A static Argo manifest cannot hold a list that the ConfigMap changes. (best practice) [sources: src/devops_cli/config/settings.py:2341, tests/config/test_infra_repos_setting.py, k8s/devops/cronworkflow-rag-ingest.yaml, k8s/devops/kustomization.yaml]
    • Chosen: devops infra drift --all. One static step, and the selection reads the same settings as every other devops infra command.
    • Rejected: One CronWorkflow step per repo, rendered from infra.repos. No renderer exists for a workflow from settings, and Argo CD syncs the static manifests of k8s/devops.
    • Rejected: A shell loop over devops config get infra.repos. It parses the settings in shell and duplicates the command's own read.
  • Which component creates the infra-plan step job on a pull request push?: The Service webhook router takes the pull_request synchronize delivery for a repo in infra.repos and starts one infra-plan Job from the runner template through job_launcher.launch. The sweep is the fallback. The change adds pull_request to the consumer, the typed payload and CONST_ROADMAP_WEBHOOK_EVENTS. (best practice) [sources: docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md, src/devops_cli/server/routes/webhooks.py, src/devops_cli/models/webhooks.py, src/devops_cli/config/constants.py:4040, src/devops_cli/roadmap/job_launcher.py, docs/CLUSTER.md]
    • Chosen: The webhook router creates the Job. ADR 0021 makes the router a creator of units, and the Job launcher is the existing seam for a step Job.
    • Rejected: The sweep only. It delays the plan by the sweep interval, and the issue names the router as the creator.
    • Rejected: GitHub Actions. It needs the cluster credentials and duplicates the unit of work.
    • Rejected: A new controller. It duplicates the router that ADR 0021 defines.
  • How does the Ansible SSH key reach the pod?: Mount the key as a read-only Secret volume and pass its file path as ansible_ssh_private_key_file. (best practice) [sources: openspec/specs/infra-plan/spec.md, src/devops_cli/infra/plan.py, k8s/devops/workflowtemplate-rag-ingest.yaml]
    • Chosen: Read-only Secret volume. Ansible reads a key file, and a volume keeps the key out of the process arguments and the environment.
    • Rejected: Environment variable. The key would appear in the process environment, and Ansible still needs a file.
    • Rejected: Inline extra variable. The key would appear in the process arguments and the logs.
  • How does the step keep one plan comment per pull request?: Post one comment with the stable marker &lt;!-- devops roadmap infra-plan --> through the existing comment step. The next push finds the marker and edits that comment. The marker holds no head SHA, so a new head edits the same comment. (best practice) [sources: src/devops_cli/roadmap/steps/comment.py, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md, docs/CLUSTER.md]
    • Chosen: Stable marker and edit. It finds the same comment on each push and leaves a person's comment alone.
    • Rejected: A marker with the head SHA. A new head would not match the old marker and would create a second comment.
    • Rejected: Post a new comment on each push. It adds one comment for each push and hides the current plan.
    • Rejected: Edit the last comment. A person's comment can be last, so the step would overwrite it.
  • How does the NetworkPolicy name the node addresses?: Name them as ipBlock CIDRs with a prefix shorter than 32 (the node subnet ranges) in a committed manifest under k8s/devops. Select the drift and plan pods by app.kubernetes.io/component: infra. A /32 private address cannot be committed, and a policy rendered outside Git would not reach an Argo CD cluster. (best practice) [sources: k8s/devops/networkpolicy.yaml, tests/invariants/test_committed_addresses.py, tests/gate/k8s_checks/network_policies.py, k8s/overlays/homelab/devops/kustomization.yaml]
    • Chosen: ipBlock node CIDRs in k8s/devops. A CIDR range names no machine, so the committed-address invariant allows it, and both deploy-stack and Argo CD apply it.
    • Rejected: A policy rendered from the infra inventory. It would not be in Git, so Argo CD would not sync it, and the deploy-stack and Argo CD network-policy check would fail.
    • Rejected: 0.0.0.0/0 except the metadata address. It admits every public address and every private range on TCP 22, not the nodes.
  • Which Ansible tool does the runner image need?: ansible-runner on ansible-core. RUNNER_TOOLS names ansible-runner with a job: reason. The devtools image gives its version, so the table compares no version. (best practice) [sources: src/devops_cli/roadmap/runner_tools.py:119, tests/roadmap/test_roadmap_runner_tools.py]
    • Chosen: ansible-core with ansible-runner. The drift and plan steps run ansible-runner, and the core package holds the runner.
    • Rejected: The community ansible package. It adds the community collections that the drift and plan steps do not use.
  • Which access level applies to the drift and plan pods?: A cluster Job is an agent caller, so the agent_access of the infra repo applies. A repo at none is refused before any Ansible process starts. [sources: src/devops_cli/infra/access.py, src/devops_cli/config/settings.py:2445, SECURITY.md]
  • Who writes the Ansible SSH key Secret that the drift and plan pods mount?: The owner writes the Secret in namespace devops from the keyring with devops k8s push-secrets. No agent writes it. The drift and plan pods wait on that Secret. (a person decides)

Open questions

  • Who writes the Ansible SSH key Secret that the drift and plan pods mount? (a person decides)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#5124, #5127

Activity

  1. added
    source/agent
    type/feature
    scope/infra
    status/new
    value/medium
    effort/medium
    on Nov 12, 2026
  2. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 12, 2026
  4. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at c58b592 while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.

  5. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    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 (7)

    Tools considered:

    Searches run:

    • open source tool posts plan output as pull request comment, results: 5
    • Ansible infrastructure drift detection scheduled cluster job, results: 5
    • Argo Workflows CronWorkflow WorkflowTemplate scheduled workflow, results: 5
    • atlantis terraform plan pull request comment automation, results: 5
    • argoproj/argo-workflows GitHub, results: 5
    • Argo Workflows run Ansible playbook job template Kubernetes, results: 5
    • Argo Workflows CronWorkflow documentation argo-workflows.readthedocs.io, results: 5

    Sources:

  6. devops-cli-service commented on Nov 24, 2026

    @devops-cli-service
    Contributor

    Owner question: See the first point of Open questions in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  7. added
    owner/agent
    status/in-progress
    and removed
    status/new
    on Nov 24, 2026
  8. added
    status/in-review
    and removed
    status/in-progress
    on Nov 24, 2026
  9. removed
    status/in-review
    owner/agent
    on Nov 24, 2026
  10. devops-cli-service commented on Nov 24, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-24 13:45 UTC

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/mediumpriority/p2-mediumscope/infrasource/agenttype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions