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-21: 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-21, maintained.
Reason: Argo Workflows, the engine the project already runs, supplies WorkflowTemplate, exit-code retryStrategy with backoff and factor, template deadlines and mutex/semaphore synchronization; searches returned only weak pages, so parameterised mutex names stay unverified.

Covers:

  • WorkflowTemplate holds the stage job spec in devops
  • retryStrategy for exit 75, limit 2, backoff 30 s, factor 2
  • Template-level activeDeadlineSeconds plus mutex and semaphore synchronization

Lacks:

Proposed design

Problem statement

The stage job runs as a Kubernetes Job from a CronJob template. The approved pipeline split runs each job of an item under one item mutex. This item moves the stage job to WorkflowTemplate roadmap-stage in devops, with the item mutex, the semaphores of roadmap-limits, a retry for exit 75, a template deadline, and the unit names and labels of ADR 0022.

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 removed.

Scenario: A stage submission creates a Workflow

  • WHEN The Service submits a stage job for an item of a repository.
  • THEN kubectl get workflow -n devops -l roadmap.devops-cli/repo=<name> -o jsonpath='{.items[*].spec.workflowTemplateRef.name}' prints roadmap-stage, and kubectl get cronjob -n devops roadmap-stage returns NotFound.

Requirement: Retry only exit 75

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

Scenario: The k8s gate check reads the retry strategy

  • WHEN I run uv run devops ci --check --only k8s.
  • THEN It passes, and the k8s row asserts a retryStrategy on roadmap-stage with limit 2, backoff 30 s, factor 2 and an expression that matches exit code 75 only.

Requirement: One stage Workflow for each item

The roadmap-stage template MUST hold the mutex item-<repo>-<n> of the item of the Workflow.

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 template names a limits key

  • WHEN I run uv run devops ci --check --only k8s.
  • THEN It passes, and the k8s row asserts that each semaphore of roadmap-stage names a key of ConfigMap roadmap-limits.

Requirement: Template deadline

The roadmap-stage template MUST set activeDeadlineSeconds to CONST_ROADMAP_STAGE_JOB_DEADLINE_SECONDS.

Scenario: The deadline keeps the stage limit

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

Requirement: Stage Workflows carry the unit name and labels

Each stage Workflow MUST use the ADR 0022 unit name devops-cli-stage-<slug(name)>-<n>-<h10(key, n, input key)> and MUST carry, in metadata.labels and spec.podMetadata.labels, the 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.

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 the stage Workflows of that repository and no Workflow of another repository, and each listed Workflow has the ADR 0022 unit name and labels.

Requirement: Admission policy covers the stage pod

ValidatingAdmissionPolicy roadmap-service-jobs MUST apply its stage rules to the pod that roadmap-stage makes, as it applies them to a stage Job today.

Scenario: The gate check runs the policy against the stage pod

  • WHEN I run uv run devops ci --check --only k8s.
  • THEN It passes, and the k8s row shows that a pod of roadmap-stage with hostNetwork or a second container is refused.

Existing Tool Considered

Argo Workflows (argoproj/argo-workflows, Apache-2.0, maintained), already in use: the alternatives check of 2026-11-21 returns in-use, and the check's block names what the tool lacks.

Key questions

  • How does the roadmap-stage template retry only exit 75?: The template sets retryStrategy with limit 2, backoff 30 s and factor 2. Its expression matches lastRetry.exitCode 75 only, so a pod that exits 1 ends the Workflow. The limit of 2 keeps the backoffLimit: 2 of the stage Job. (best practice) [sources: docs/guidelines/agentic-jobs.md:52, docs/adr/0023-the-project-brain-is-a-derived-index-in-two-cache-tiers-and-two-scheduled-runs-keep-it.md:81, docs/CLUSTER.md:85]
    • Chosen: retryStrategy expression on lastRetry.exitCode. Argo retries only the exit codes that the expression names, and the guideline records the field.
    • Rejected: podFailurePolicy on the exit code. The field belongs to a Kubernetes Job. The template has no such field.
    • Rejected: Retry every failed pod. It retries exit 1, which is a non-retryable failure of the item.
  • Which activeDeadlineSeconds does the template set?: The template sets activeDeadlineSeconds to CONST_ROADMAP_STAGE_JOB_DEADLINE_SECONDS, the 10800 s of the stage Job today. The stage time budget does not change. (best practice) [sources: docs/CLUSTER.md:85, src/devops_cli/config/constants.py:4129]
    • Chosen: 10800 s, CONST_ROADMAP_STAGE_JOB_DEADLINE_SECONDS. It keeps the stage time budget and the gate check that holds the constant.
    • Rejected: 7200 s, the runner CronJob value. It cuts the stage budget by one hour.
    • Rejected: No deadline. ADR 0021 asks for a deadline on each template.
  • Which lock keeps two stage Workflows of one item apart?: The template takes the item mutex item-<repo>-<n>. ADR 0021 requires a mutex for each item. When feat(k8s): let Argo Workflows run roadmap pods in devops #4566 shows that a parameterised mutex name fails, the template takes the Valkey lease for the item instead. This item waits on feat(k8s): let Argo Workflows run roadmap pods in devops #4566, so the result is known at build time. (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:63, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md:67]
    • Chosen: Item mutex with a parameterised name. ADR 0021 puts a mutex on each item, and the mutex needs no new code.
    • Rejected: One mutex for each repository. Two stage Workflows of one item still run together.
    • Rejected: Valkey lease for each item. It is the fallback that feat(k8s): let Argo Workflows run roadmap pods in devops #4566 names, and it adds code.
  • Which semaphore of ConfigMap roadmap-limits does the stage Workflow take?: It takes semaphore agent, one of the three semaphores that ADR 0021 puts in ConfigMap roadmap-limits. The stage row calls a model, and agent admits the pods that do model work. (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:67, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md:97]
    • Chosen: agent. The stage row calls a model, so it takes the semaphore for model work.
    • Rejected: No semaphore. ADR 0021 asks for the semaphores of the ConfigMap.
    • Rejected: A new key. ADR 0021 names the three keys of the ConfigMap.
  • How does the stage pod keep the admission rules that the Job policy gives it?: 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 user instead of only system:serviceaccount:devops:roadmap-service; the gate check evaluates the stage pod rules. (best practice) [sources: docs/CLUSTER.md:71, k8s/devops/roadmap-service/admissionpolicy.yaml:39, tests/gate/k8s_checks/job_admission_policy.py]
    • Chosen: Extend the policy to the stage pod. The stage pod keeps the no-token, image and volume rules.
    • 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.
  • 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 stage template in src/devops_cli/k8s/cluster_job.py, and k8s/devops/cronjob-stage.yaml is deleted. The new template follows k8s/devops/workflowtemplate-rag-ingest.yaml. The Service's Role roadmap-service-jobs gains create, get, list, patch and delete on workflows.argoproj.io and drops get on CronJob roadmap-stage; the delete policy in k8s/devops/roadmap-service/admissionpolicy.yaml gains the same guard for a stage Workflow that roadmap-service-job-deletes has for a stage Job. (best practice) [sources: src/devops_cli/roadmap/stage/stage_submit.py, src/devops_cli/k8s/cluster_job.py:74, k8s/devops/cronjob-stage.yaml, k8s/devops/workflowtemplate-rag-ingest.yaml, k8s/devops/roadmap-service/role.yaml:21, k8s/devops/roadmap-service/admissionpolicy.yaml:316]
    • 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, and the Service starts it for one item.
  • Does ADR 0022 define the unit names and labels that the 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 that each Workflow carries in 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 and the environment variable OTEL_SERVICE_NAME: roadmap-stage. [sources: docs/adr/0022-one-repository-reference-names-the-objects-labels-and-keys-of-each-repository.md:57, docs/adr/0022-one-repository-reference-names-the-objects-labels-and-keys-of-each-repository.md:69, docs/adr/0022-one-repository-reference-names-the-objects-labels-and-keys-of-each-repository.md:71]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#4566, #6521, #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.

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