Skip to content

feat(k8s): run the stage job as a WorkflowTemplate #6594

Open

Description

@dan-petty

Problem

The refine split of #4566 on 2026-11-14 gives this part its own item. Today the stage job runs as a Kubernetes Job from a CronJob template. The approved pipeline split (tracker #5482) runs each job of an item under one item mutex. #4566 measures two facts on the live controller: does a mutex with a parameter name work, and does a mutex wait survive a controller restart.

Scope

  • Move the stage CronJob template to WorkflowTemplate roadmap-stage in devops.
  • Use the item mutex item-<repo>-<n>. If the measurement of feat(k8s): let Argo Workflows run roadmap pods in devops #4566 shows that a mutex with a parameter name fails, use the Valkey lease for each item that its result names.
  • Use the semaphores of roadmap-limits.
  • Add a retryStrategy for exit 75: limit 2, backoff 30 s, factor 2.
  • Add a template-level activeDeadlineSeconds.
  • Use the unit names and labels of ADR 0022.

Acceptance criteria

Each as a live check, not a live pytest:

  • A pod of roadmap-stage that exits 75 is retried. A pod that exits 1 is not.
  • Two stage Workflows of one item do not run at the same time.
  • kubectl get workflows -n devops -l roadmap.devops-cli/repo=<name> lists the stage Workflows of that repository.

Dependencies

Source

Source: #4517

Alternatives check of 2026-11-27: 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-27, maintained.
Reason: Searches found the Argo Workflows engine, which the issue itself names as already in use, and no other tool: it provides WorkflowTemplate, synchronization mutexes and semaphores, retryStrategy expressions and template deadlines that this scope needs.

Covers:

  • WorkflowTemplate referenced by a Workflow for one item
  • Synchronization mutex and semaphore keys from a ConfigMap
  • retryStrategy expression, limit, backoff and factor
  • Template activeDeadlineSeconds and pod metadata labels

Lacks:

Proposed design

Problem statement

The stage job runs as a Kubernetes Job from the template of CronJob roadmap-stage. The approved pipeline split puts each job of an item under one item lock. This change moves the stage job to WorkflowTemplate roadmap-stage in namespace devops. The template takes the item lock and the semaphores of ConfigMap roadmap-limits. It retries exit 75 only, sets a deadline, and carries the ADR 0022 unit name and labels. The Service creates one Workflow for one item, and the stage CronJob is removed.

Acceptance criteria

Requirement: Stage job runs from a WorkflowTemplate

The stage job MUST run as an Argo Workflow from WorkflowTemplate roadmap-stage in namespace devops, and the stage CronJob MUST be absent.

Scenario: The k8s row checks the stage template

  • WHEN I run uv run devops ci --check --only k8s.
  • THEN It passes, and the stage check of the row reports WorkflowTemplate roadmap-stage in namespace devops and no CronJob roadmap-stage.

Requirement: Retry only exit 75

The roadmap-stage template MUST retry a pod that exits 75 with limit 2, backoff 30 s and factor 2, and MUST NOT retry a pod that exits 1.

Scenario: The k8s row checks the retry strategy

  • WHEN I run uv run devops ci --check --only k8s.
  • THEN It passes, and the stage check reports a retryStrategy with limit 2, backoff 30 s, factor 2 and the expression asInt(lastRetry.exitCode) == 75.

Requirement: One stage Workflow for each item

The roadmap-stage template MUST serialize the stage Workflows of one item under the item lock that #4566 selects.

Scenario: A second stage Workflow of one item waits

  • WHEN A stage Workflow of an item runs and I submit a second stage Workflow of the same item.
  • THEN kubectl get pods -n devops -l workflows.argoproj.io/workflow=<second> lists no pod until the first Workflow ends.

Requirement: Semaphore of roadmap-limits

The roadmap-stage template MUST take a semaphore of ConfigMap roadmap-limits in its synchronization block.

Scenario: The k8s row checks the semaphore key

  • WHEN I run uv run devops ci --check --only k8s.
  • THEN It passes, and the stage check reports that each semaphore key of roadmap-stage exists in ConfigMap roadmap-limits.

Requirement: Template deadline

The roadmap-stage template MUST set activeDeadlineSeconds to the value of CONST_ROADMAP_STAGE_JOB_DEADLINE_SECONDS.

Scenario: The k8s row checks the deadline

  • WHEN I run uv run devops ci --check --only k8s.
  • THEN It passes, and the stage check reports that the activeDeadlineSeconds of roadmap-stage equals CONST_ROADMAP_STAGE_JOB_DEADLINE_SECONDS.

Requirement: Stage Workflows carry the ADR 0022 name and labels

Each stage Workflow MUST use the ADR 0022 unit name and MUST carry the ADR 0022 labels in metadata.labels and spec.podMetadata.labels, with the repository annotation.

Scenario: List the stage Workflows of a repository

  • WHEN I run kubectl get workflows -n devops -l roadmap.devops-cli/repo=<name> -o json.
  • THEN It lists each stage Workflow of that repository and no Workflow of another repository, and each listed Workflow has the ADR 0022 unit name, the ADR 0022 labels in both places and the annotation roadmap.devops-cli/repository.

Requirement: Pending a person after the merge

ValidatingAdmissionPolicy roadmap-service-jobs MUST apply its stage rules to the pods that roadmap-stage makes.

Scenario: The live proof of the stage policy

  • WHEN After the merge, a person submits a stage Workflow for an item, and a stage Workflow whose pod template sets hostNetwork: true.
  • THEN The first Workflow makes its pod, and the second Workflow makes no pod and reports an error that names roadmap-service-jobs.

Requirement: The Service submits a stage Workflow

The Service MUST create a Workflow from WorkflowTemplate roadmap-stage for one item, with the item parameters and the ADR 0022 labels, and MUST NOT create a Job from CronJob roadmap-stage.

Scenario: The stage submission builds a Workflow

  • WHEN I run uv run pytest tests/roadmap/stage -q.
  • THEN It passes, and a test asserts that a stage submission builds a Workflow with workflowTemplateRef.name roadmap-stage, the item parameters and the ADR 0022 labels.

Existing Tool Considered

The alternatives check of 2026-11-27 in the issue body gives Argo Workflows (argoproj/argo-workflows, Apache-2.0, maintained) the verdict in-use, because the repository already uses it. That check records what the tool covers and what it lacks. The proposal fills the gaps that the check lists: it extends ValidatingAdmissionPolicy roadmap-service-jobs to the Argo controller's service account, adds the Service RBAC and the submission code for workflows.argoproj.io, and writes the ADR 0022 unit names as project code. The #4566 measurement selects the item lock before the build starts.

Key questions

  • How does the roadmap-stage template retry a pod that exits 75, and not a pod that exits 1?: The template sets retryStrategy with limit: 2, backoff: {duration: 30s, factor: 2} and expression: asInt(lastRetry.exitCode) == 75. Argo retries only the exit codes that the expression names, so a pod that exits 1 ends the Workflow. (best practice) [sources: docs/guidelines/agentic-jobs.md]
    • Chosen: retryStrategy expression on lastRetry.exitCode. The guideline records the field, and Argo retries only the exit codes that the expression names.
    • Rejected: retryStrategy with a limit and no expression. It retries every failed pod, and a pod that exits 1 must not run again.
    • Rejected: podFailurePolicy on the exit code. The field belongs to a Kubernetes Job, and a Workflow template has no such field.
  • Which activeDeadlineSeconds does the roadmap-stage template set?: The template sets activeDeadlineSeconds to CONST_ROADMAP_STAGE_JOB_DEADLINE_SECONDS, the value that the stage Job uses today. The stage time budget does not change. (best practice) [sources: src/devops_cli/config/constants.py:4500, k8s/devops/cronjob-stage.yaml, tests/gate/k8s_checks/stage_job.py, docs/guidelines/agentic-jobs.md]
    • Chosen: CONST_ROADMAP_STAGE_JOB_DEADLINE_SECONDS. It keeps the stage time budget and the check that holds the constant.
    • Rejected: A new stage deadline. It changes the stage time budget with no measurement.
    • Rejected: No deadline. The guideline asks for a deadline and a retry rule on each unit.
  • Which lock keeps two stage Workflows of one item apart?: The template takes the item mutex item-<repo>-<n>. When the measurement of feat(k8s): let Argo Workflows run roadmap pods in devops #4566 shows that a mutex with a parameter name fails, the template takes the Valkey lease for the item instead. feat(k8s): let Argo Workflows run roadmap pods in devops #4566 is a dependency, so the answer is known before the build. (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/roadmap/stage/stage_submit.py]
  • Which semaphore of ConfigMap roadmap-limits does the roadmap-stage template take?: The template takes the semaphore key that the ConfigMap gives to the work that calls a model, because the stage row calls a model. The k8s row asserts that each semaphore key of the template exists in the ConfigMap, so a key that the ConfigMap does not define fails the check. (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]
    • Chosen: The model-work key of the ConfigMap. The stage row calls a model, and the ConfigMap owns the limit of that work.
    • Rejected: No semaphore. The scope and ADR 0021 ask for the semaphores of the ConfigMap.
    • Rejected: A new key in the template. A key that the ConfigMap does not define takes no slot, and the limit is lost.
  • How does the stage pod keep the admission rules that the stage Job has today?: ValidatingAdmissionPolicy roadmap-service-jobs also matches the pods of roadmap-stage, with the stage rules. Its matchConstraints add pods, and its match condition names the Argo Workflow controller's service account as well as system:serviceaccount:devops:roadmap-service. The policy that guards a Job delete also guards a stage Workflow. (best practice) [sources: k8s/devops/roadmap-service/admissionpolicy.yaml, tests/gate/k8s_checks/job_admission_policy.py, docs/CLUSTER.md]
    • Chosen: Extend the policy to the stage pod. The stage pod keeps the no-token, image and volume rules that the Job has today.
    • Rejected: Keep the stage CronJob. The scope moves the stage job to a WorkflowTemplate.
    • Rejected: Drop the rules for the stage pod. The pod loses the guard that the Job has today, and rule AW-T6 forbids a weaker control.
  • Which code starts the stage Workflow, and what happens to CronJob roadmap-stage?: src/devops_cli/roadmap/stage/stage_submit.py creates a Workflow from roadmap-stage for the item, through the job builder in src/devops_cli/k8s/cluster_job.py. The new file k8s/devops/workflowtemplate-stage.yaml follows k8s/devops/workflowtemplate-rag-ingest.yaml, and k8s/devops/cronjob-stage.yaml is deleted. The Service Role gains create, get, list, patch and delete on workflows.argoproj.io. The stage assertions in tests/gate/k8s_checks/stage_job.py move from the CronJob to the WorkflowTemplate. (best practice) [sources: src/devops_cli/roadmap/stage/stage_submit.py, src/devops_cli/k8s/cluster_job.py, k8s/devops/cronjob-stage.yaml, k8s/devops/workflowtemplate-rag-ingest.yaml, tests/gate/k8s_checks/stage_job.py, docs/CLUSTER.md]
    • Chosen: Create a Workflow from the template. The Service starts one stage job for one item, and a Workflow takes the item as a parameter.
    • Rejected: Keep the CronJob and add the template. Two paths start the stage job.
    • Rejected: A CronWorkflow. A schedule starts the stage job, but the Service starts it for one item.
  • Does ADR 0022 define the unit name and the labels that a stage Workflow takes?: Yes. ADR 0022 section 2 gives the unit name devops-cli-stage-<slug(name)>-<n>-<h10(key, n, input key)> of 63 characters or fewer. Section 3 gives the labels for metadata.labels and spec.podMetadata.labels: app.kubernetes.io/name: devops-cli-job, app.kubernetes.io/component: roadmap-stage, app.kubernetes.io/part-of: devops-cli-stack, app.kubernetes.io/managed-by: roadmap-service, roadmap.devops-cli/owner, roadmap.devops-cli/repo and roadmap.devops-cli/item, with the annotation roadmap.devops-cli/repository. [sources: docs/adr/0022-one-repository-reference-names-the-objects-labels-and-keys-of-each-repository.md]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#4566, #6592

Activity

  1. added
    type/feature
    scope/k8s
    source/agent
    on Nov 21, 2026
  2. added
    status/new
    on Nov 21, 2026
  3. dan-petty commented on Nov 21, 2026

    @dan-petty
    OwnerAuthor
  4. added
    value/medium
    effort/medium
    priority/p2-medium
    on Nov 21, 2026
  5. devops-cli-service commented on Nov 21, 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)

    Tools considered:

    Searches run:

    • Argo Workflows retryStrategy expression exit code 75 backoff, results: 5
    • Argo Workflows mutex semaphore WorkflowTemplate synchronization, results: 5
    • argo-workflows docs retryStrategy exitCodes expression example, results: 5
    • argo-workflows synchronization mutex semaphore documentation, results: 5
    • argoproj argo-workflows WorkflowTemplate activeDeadlineSeconds retry backoff factor, results: 5
    • "argo workflows" retryStrategy "exitCodes" 75, results: 5
    • kubernetes argo workflows mutex workflowtemplate documentation readthedocs, results: 5
    • argo-workflows retry strategy exit codes documentation site, results: 5
    • site:argo-workflows.readthedocs.io retryStrategy, results: 5
    • argo workflows exit 75 retry semaphore mutex item lock, results: 5

    Sources:

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

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.

  7. devops-cli-service commented on Dec 1, 2026

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.

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/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions