Skip to content

refactor(k8s): run the stage Job as three containers #6814

Open

Description

@dan-petty

Problem

CronJob roadmap-stage runs stage in one container that holds the App key and the model key. #6705 gives the stage agent a real shell, so the agent must run in a container with no App key, as the runner Job does since #3700.

Change

  • CronJob roadmap-stage gets the init containers prepare and agent and the container publish, with the volumes and keys of the runner template: only prepare and publish read the App key, and only agent reads the model key.
  • The admission policy roadmap-service-jobs admits a stage Job with the three containers and pins the same rules for it as for the runner Job. The one-container stage shape stays allowed only on UPDATE.
  • Merge only after a release holds refactor(roadmap): stage runs its three phases on one run folder #6813, and the stage CronJob runs that release's image.

Acceptance criteria

  • The k8s gate checks admit the three-container stage Job and refuse a stage Job with the App key on agent.
  • One live stage Job passes on the three containers.

Dependencies

Source

Source: #6705

Alternatives check of 2026-11-23: not-applicable.
Class: refactor, no search.
Tool: none found.

Proposed design

Problem statement

CronJob roadmap-stage runs the stage job in one container that holds the App key and the model key. #6705 gives the stage agent a real shell, so the agent must run with no App key, as the runner Job does since #3700. The change runs stage as the init containers prepare and agent and the container publish, with the volumes and key split of the runner template, and pins the same rules in the admission policy roadmap-service-jobs.

Acceptance criteria

Requirement: stage-cronjob-three-containers

CronJob roadmap-stage SHALL run the init containers prepare and agent and the container publish.

Scenario: three containers rendered

  • WHEN uv run devops ci --check --only k8s runs the k8s gate on the rendered manifests
  • THEN the gate shows CronJob roadmap-stage with the init containers prepare and agent and the container publish, and reports no violation

Requirement: stage-state-volume-off-agent

The stage Job SHALL mount the state volume in prepare and publish only, as the runner template does.

Scenario: state volume and the agent container

  • WHEN uv run devops ci --check --only k8s runs the k8s gate on the rendered manifests
  • THEN the gate shows the state volume in prepare and publish, and no state volume in agent

Requirement: stage-keys-split

The stage Job SHALL mount the App key in prepare and publish only and the model key in agent only.

Scenario: keys on the three containers

  • WHEN uv run devops ci --check --only k8s runs the k8s gate on the rendered manifests
  • THEN the gate shows the App key in prepare and publish, the model key in agent, no App key in agent, and no model key in prepare or publish

Requirement: stage-app-key-not-on-agent

The admission policy roadmap-service-jobs MUST refuse a stage Job that mounts the App key in the agent container.

Scenario: App key on the agent container

  • WHEN uv run devops ci --check --only k8s runs the admission policy check on a stage Job whose agent container mounts the App key
  • THEN the check shows the Job refused, and the violation names the agent container

Requirement: stage-model-key-not-on-prepare-or-publish

The admission policy roadmap-service-jobs MUST refuse a stage Job that mounts the model key in the prepare or the publish container.

Scenario: model key on the publish container

  • WHEN uv run devops ci --check --only k8s runs the admission policy check on a stage Job whose publish container mounts the model key
  • THEN the check shows the Job refused, and the violation names the publish container

Requirement: stage-one-container-on-update-only

The admission policy roadmap-service-jobs SHALL admit a one-container stage Job on UPDATE only.

Scenario: one-container stage Job on CREATE and on UPDATE

  • WHEN uv run devops ci --check --only k8s runs the admission policy check on a one-container stage Job as CREATE and as UPDATE
  • THEN the check shows the CREATE refused and the UPDATE admitted

Requirement: stage-submit-reads-the-container-that-ended

The stage submit step MUST read the log of the stage container that ended.

Scenario: agent ends at the deadline

  • WHEN a unit test runs the stage submit step on a Job whose agent container ended at the deadline and whose publish container never started
  • THEN the step classes the result timeout and reads the log of agent

Requirement: stage-pod-failure-policy-matches-each-container

The pod failure policy of CronJob roadmap-stage MUST fail the Job on an exit code other than 75 of prepare, agent or publish, and MUST run the pod again on exit 75.

Scenario: pod failure rules for the three containers

  • WHEN uv run devops ci --check --only k8s runs the k8s gate on the rendered manifests
  • THEN the gate shows a FailJob rule with operator NotIn and value 75 for each of prepare, agent and publish, and a rule with operator In and value 75 for each that does not fail the Job

Requirement: stage-one-request-budget

The stage prepare and publish phases MUST keep their GitHub requests in one budget record on the state volume.

Scenario: prepare spends the budget

  • WHEN a unit test runs prepare until the budget is spent, then runs publish on the same run folder
  • THEN publish waits for the window that prepare wrote, and the two phases send no more than roadmap.stage.github_requests_per_hour in the hour

Requirement: stage-live-job-passes

One live stage Job MUST pass on the three containers.

Scenario: live stage Job

  • WHEN the live check runs uv run devops k8s run-job --template stage --repo <owner/name> --item <n> -- roadmap stage --repo <owner/name> --job-item <n> --confirm
  • THEN the Job ends Complete and the containers prepare, agent and publish each exit with code 0

Existing Tool Considered

The alternatives check of 2026-11-23 in the issue body records not-applicable and names no tool. The open, maintained tools that cover the need are the Kubernetes batch/v1 CronJob and Job with init containers and the admissionregistration.k8s.io/v1 ValidatingAdmissionPolicy, which the runner Job already uses (k8s/devops/cronjob-runner.yaml, k8s/devops/roadmap-service/admissionpolicy.yaml). They lack a GitHub request budget that two containers of one pod share; the project's RequestBudget covers that with a record on the state volume (src/devops_cli/server/service.py:219). The change adds no new component beyond that record and the stage phases, so its cost is the edit of the CronJob, the policy and the stage code.

Key questions

  • Which container holds the App key, and which holds the model key, in the stage pod?: prepare and publish hold the App key. Only agent holds the model key. The stage pod copies the key split of the runner template. (best practice) [sources: k8s/devops/cronjob-runner.yaml, docs/adr/0030-roadmap-steps-run-their-agent-apart-from-the-app-key.md, k8s/devops/roadmap-service/admissionpolicy.yaml]
  • Does the one-container stage shape stay allowed?: Yes, on UPDATE only. The policy admits the one-container stage shape on UPDATE and refuses it on CREATE. (best practice) [sources: k8s/devops/roadmap-service/admissionpolicy.yaml, tests/gate/k8s_checks/job_admission_policy.py, src/devops_cli/k8s/cluster_job.py:74]
    • Chosen: Admit the one-container shape on UPDATE only. A one-container Job that runs during the rollout keeps its deadline patch, and a new Job must use the three containers.
    • Rejected: Refuse the one-container shape on CREATE and on UPDATE. It refuses the deadline patch of a stage Job that is already running.
    • Rejected: Admit the one-container shape on CREATE and on UPDATE. It keeps the App key beside the agent for new Jobs.
  • Which container log does the stage submit step read, and how does the pod failure policy match the three containers?: The stage submit step reads the log of the container that ended: publish when it ran, else agent, else prepare. The pod failure policy names prepare, agent and publish. (best practice) [sources: src/devops_cli/roadmap/stage/stage_submit.py, src/devops_cli/k8s/cluster_job.py:74, k8s/devops/cronjob-stage.yaml]
    • Chosen: Read the log of the container that ran, and match each container in the policy. A deadline during agent leaves publish unstarted, and an exit 1 of prepare must fail the Job.
    • Rejected: Read only the log of publish, and name only publish in the policy. A deadline during agent leaves no publish log, and an exit 1 of prepare would not fail the Job.
    • Rejected: Keep the container name stage. No container is named stage after the change, so the log is empty and the policy matches no container.
  • How do the stage prepare and publish phases keep one GitHub request budget?: prepare and publish pass one record file on the state volume to RequestBudget, so the pod spends roadmap.stage.github_requests_per_hour once an hour. agent mounts no state volume. (best practice) [sources: src/devops_cli/server/service.py:219, src/devops_cli/roadmap/stage/stage_job.py, src/devops_cli/roadmap/stage/stage_job_phases.py]
    • Chosen: One budget record on the state volume. RequestBudget keeps a record across processes, and only prepare and publish mount the state volume.
    • Rejected: A full budget in each of prepare and publish. The pod would spend twice roadmap.stage.github_requests_per_hour.
    • Rejected: A separate budget volume. It adds a volume that the runner template does not have.
  • When can this change merge, and when does the live stage Job run?: The change merges after a devops-cli release holds refactor(roadmap): stage runs its three phases on one run folder #6813. The stage CronJob runs that release's runner image, and the live check runs on that release. (best practice) [sources: k8s/devops/cronjob-stage.yaml, k8s/devops/cronjob-runner.yaml, docs/CLUSTER.md]

Fit

Fits in one pull request.

Suspected block

A devops-cli release that holds #6813.

Dependencies

#6813

Activity

  1. added
    type/refactor
    scope/k8s
    source/agent
    status/new
    value/medium
    on Nov 23, 2026
  2. dan-petty commented on Nov 23, 2026

    @dan-petty
    OwnerAuthor
    • Related: refactor(roadmap): stage runs on the phases #6704, which asks for a different change. Both split stage into prepare, agent and publish, but #6704 delivers the code running on those phases while the candidate delivers the k8s container split with per-container secret isolation.
  3. added
    effort/medium
    priority/p2-medium
    on Nov 23, 2026
  4. dan-petty commented on Nov 23, 2026

    @dan-petty
    OwnerAuthor

    This item also depends on #6831. With no credential in the agent container, the planner loses its GitHub reads, and #6831 has prepare hand it that data. Merge this item only after a release holds #6813 and #6831.

    The review of #6822 (2026-11-23) ran the three phases as separate processes. It found these points that this item must handle:

    • Container names: stage_submit.py (about line 212) reads the log of container stage, and the podFailurePolicy names container stage. Without a change, a deadline end is classed ci_infra and not timeout, and a failed end is classed with no log.
    • State volume: state/ must be a volume that agent cannot reach, as in the runner Job. state.target.replace_pull selects the pull request that publish updates, and type_ and slug select the branch.
    • Publish source: never give publish --source <work clone>. The agent can write the git config and hooks of that clone.
    • Publish clone size: publish makes a full clone at the tip of the default branch. The devops-cli tree is about 143 MB, and the runner template gives publish-home 256Mi.
    • Request budget: prepare and publish each install github_requests_per_hour, so one pod can spend twice the budget.
    • Time budget: the budget of the agent starts when the agent starts, not when the Job starts. The deadline still caps it.
    • Check-in: a SIGTERM or crash in the agent writes no check-in, so the Service checks in for the Job.
    • Private repositories: with no credential, lazy blob fetches in the agent fail. That loses the kept plan on a re-stage and git_show of history. devops-cli is public.
  5. dan-petty commented on Nov 23, 2026

    @dan-petty
    OwnerAuthor

    The dependency changes: #6813 is closed as not planned, and #6705 now builds the phases of stage together with the Coder agent. Merge this item only after a release holds #6705 and #6831.

  6. dan-petty commented on Nov 23, 2026

    @dan-petty
    OwnerAuthor

    The stage agent of #6705 runs devops openspec check as one of its three checks (plan pull request #6841), and publish runs it again. That check regenerates the OpenSpec skills in a scratch copy with openspec update --force (src/devops_cli/openspec/skills.py:22), and CONTRIBUTING.md:60 says that the regeneration needs access to github.com. So the agent container and the publish container of this item need egress to github.com. The agent container must reach it with no credential.

  7. added a commit that references this issue on Nov 23, 2026
  8. dan-petty commented on Nov 23, 2026

    @dan-petty
    OwnerAuthor

    A correction of my comment above. devops openspec check needs github.com only when the committed skills differ from a regeneration. On 2026-11-23 it passed in 57 s on main with the proxies at a closed port and GIT_ALLOW_PROTOCOL=file. So the agent and publish containers need no egress to github.com for that check.

  9. devops-cli-service commented on Nov 23, 2026

    @devops-cli-service
    Contributor

    Owner question: See the first point of Open questions and Watched files 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

  10. devops-cli-service commented on Nov 23, 2026

    @devops-cli-service
    Contributor

    Owner question: See Suspected block and Watched files 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

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

    @devops-cli-service
    Contributor

    Owner question: See Suspected block 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

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/k8ssource/agentstatus/newtype/refactorvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions