Skip to content

feat(infra): apply a merged infra PR in a step job #5130

Done

Description

@dan-petty

Problem or Motivation

After #5129, a pull request of an infra repo gets a plan, but a merged pull request still waits for a person or an agent to run devops infra apply on a workstation. The cluster is GitOps (Argo CD applies a merged manifest); the hosts under it are not.

Proposed Solution & Architectural Design

Phase 3 of tracker #5120 (design section 8). A step job infra-apply runs when a pull request of an infra repo merges, for a repo at level safe or full. It plans the merge commit, applies it with all guards of #5125, and posts the result and the audit record as a comment on the merged pull request. A cluster Job never drains or reboots its own node or the control-plane node: the job stops before that host and says that the host needs a workstation run. A failure stops the run, leaves the node cordoned and opens or updates one issue in the infra repo.

Target Subsystem

Kubernetes & Minikube Automation

Existing Tool Considered

The webhook router and step jobs of ADR 0021, and devops infra apply. Cost: about 4M tokens to build, 0.5M a quarter to keep, 6 hours.

Acceptance Criteria

  • Tests: the job refuses a repo below safe; it skips its own node and the control-plane node with a clear message; it posts one comment per merge.
  • Live: a small, non-disruptive dan-petty/homelab pull request merges and the job applies it; the comment holds the audit record.

Dependencies

#5125, #5129.

Proposed design

Problem statement

A merged pull request of an infra repo still needs a person or an agent to run devops infra apply on a workstation. Argo CD applies the merged manifests, but it does not apply the hosts under them. This change adds a step job. The job plans the merge commit and applies the plan with the existing guards. It posts one comment with the result and the audit record. It stops before a host that the job must not drain.

Acceptance criteria

Requirement: Level gate for infra apply

The infra-apply step job SHALL refuse an infra repo whose agent access level is below safe.

Scenario: Refuse plan level

  • WHEN a merged pull request of an infra repo at level none or plan starts the step job
  • THEN the job writes no plan, makes no apply, and reports that the level is too low.

Requirement: Plan before apply

The infra-apply step job SHALL save an infra plan for the merge commit before it applies that plan.

Scenario: Plan the merge commit

  • WHEN the step job starts for a merged pull request at level safe or full
  • THEN the job saves the plan for the merge commit and calls devops infra apply only with that plan.

Requirement: Apply only an ok plan

The infra-apply step job SHALL apply only an infra plan that ended ok.

Scenario: Failed plan

  • WHEN the plan for the merge commit ended failed
  • THEN the job makes no apply and reports the failed plan.

Requirement: Apply guards

The infra-apply step job SHALL apply the saved plan through the devops infra apply path that enforces the guards of #5125.

Scenario: Use the existing apply path

  • WHEN the step job applies the saved plan
  • THEN it calls the same apply function as devops infra apply, including the drain check, fresh check, health checks and audit record.

Requirement: Stop before own node and control-plane node

The infra-apply step job SHALL stop before a disruptive host that is its pod node or the control-plane node and report a workstation run.

Scenario: Own node in the plan

  • WHEN the plan has a disruptive host that is the node of the step job pod or the control-plane node
  • THEN the job stops before that host, uncordons no node, and posts a message that names the host and the workstation run.

Requirement: One comment per merge

The infra-apply step job SHALL post exactly one comment on the merged pull request for each merge commit.

Scenario: Second run posts no second comment

  • WHEN the step job runs again for the same merged pull request
  • THEN it finds the hidden marker and posts no second comment.

Requirement: Audit record in comment

The infra-apply step job SHALL post the infra.apply audit record in the comment on the merged pull request.

Scenario: Comment holds audit record

  • WHEN the step job ends an apply
  • THEN the comment holds the result and the infra.apply audit record.

Requirement: Failure issue and cordon

The infra-apply step job SHALL stop on an apply failure, leave the node cordoned, and open or update exactly one issue in the infra repo.

Scenario: Apply failure on a disruptive host

  • WHEN the apply fails on a disruptive host
  • THEN the job stops, calls no uncordon for that node, and opens or updates one issue in the infra repo with the failure.

Existing Tool Considered

No alternatives check has run. The plan uses the project's own webhook router and step jobs of ADR 0021 and devops infra apply. It adds no external tool. The body gives the cost: about 4M tokens to build, 0.5M a quarter to keep, 6 hours.

Key questions

  • How does a merged pull request of an infra repo start the infra-apply step job?: The webhook router sets a due mark for the merged pull request. The sweep creates the infra-apply step job from that due mark. (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, CONTEXT.md]
    • Chosen: Webhook router and sweep. ADR 0021 makes the webhook router set a due mark and the sweep create the step job.
    • Rejected: GitHub Actions workflow in the infra repo. The workflow would need the cluster credentials and would bypass the router.
    • Rejected: Polling only. The sweep reconciles, but polling alone delays the job and ignores the webhook.
  • Which agent access levels allow the infra-apply step job to apply a merge commit?: Only safe and full allow an apply. The job refuses none and plan. (best practice) [sources: CONTEXT.md]
    • Chosen: safe and full. An apply changes hosts, and none and plan do not permit that change.
    • Rejected: plan and above. plan permits a plan only, so the job must not apply at that level.
    • Rejected: all levels. none permits no agent access, so an apply would break the level.
  • Which apply path does the infra-apply step job use?: The job saves an infra plan for the merge commit and calls devops infra apply on that plan. The existing apply path holds the drain check, fresh check, health checks and infra.apply audit record. (best practice) [sources: CONTEXT.md, tests/commands/test_infra_apply.py, tests/infra/test_plan.py]
    • Chosen: Call devops infra apply. The existing command holds the guards and writes the audit record.
    • Rejected: Reimplement apply in the step job. A second apply path would duplicate the guards and the audit record.
  • What does the job do when the plan has a disruptive host that is the node of its pod or the control-plane node?: The job stops before that host. It reports that the host needs a workstation run. (best practice) [sources: CONTEXT.md]
    • Chosen: Stop before the host. A cluster Job must not drain or reboot its own node or the control-plane node.
    • Rejected: Drain and reboot the host. The job pod would stop, and the control-plane node would lose the cluster.
    • Rejected: Skip the host and continue. The apply would not complete and the result would hide the skipped host.
  • How does the job keep one comment per merge and one issue per failure?: The job writes a hidden marker keyed by the merge commit SHA on the comment. It opens or updates one issue keyed by the infra repo and host. A second run changes no record. (best practice) [sources: CONTEXT.md]
    • Chosen: Hidden marker and keyed issue. GitHub state is the first marker, so a second run changes nothing.
    • Rejected: Search all comments on each run. A search can match a comment of another run and post a duplicate.
    • Rejected: New comment on each run. The merged pull request would get many comments for one merge.
  • What audit record does the job post in the comment?: The job posts the infra.apply audit record that devops infra apply writes. [sources: CONTEXT.md]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#5125, #5129

Alternatives check of 2026-11-19: none.
Tool: none found.
Reason: Searches surfaced only Terraform/OpenTofu PR automation (Atlantis) and generic GitOps pages; none covers the project's own devops infra apply, its level gate, #5125 guards, audit record, or the stop-before-own-node rule, so no external tool fits the internal step job.

Lacks:

  • No apply of a devops infra plan for a merge commit
  • No drain, fresh or health guards and infra.apply audit record
  • No agent level gate or stop-before-own/control-plane node rule
  • No webhook-router step job or one-comment-per-merge marker

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

    Searches run:

    • automatically apply infrastructure changes after pull request merge tool, results: 5
    • Atlantis Terraform apply on merge pull request, results: 5
    • Atlantis runatlantis.io infrastructure pull request automation, results: 5
    • Digger Terrateam apply infrastructure on merge open source, results: 5
    • Argo CD apply host changes after merge automation, results: 5
    • Ansible AWX Semaphore apply playbook on merge webhook, results: 5
    • runatlantis atlantis self-hosted terraform pull request automation, results: 5
    • GitOps host configuration apply on merge Argo CD not hosts, results: 5
    • kubernetes node drain reboot automation job guard, results: 5
    • apply Ansible playbook automatically on merge pull request, results: 5

    Sources:

  6. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/new
    status/in-progress
    on Nov 24, 2026
  7. removed
    status/in-review
    owner/agent
    on Nov 24, 2026
  8. 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