Skip to content

feat(k8s): services preempt batch Jobs with priority classes #5013

Open

Description

@dan-petty

Update 2026-11-26 (infra move): Most of the other workloads moved to dan-petty/homelab.

This item keeps the k8s/devops/ work of the design below: the three PriorityClass objects, the class on the roadmap Service, the Job templates and rag-ingest, and the admission policy. The class names on the platform and stack workloads are the homelab follow-up, which merges after this item. Where the design names the infra repo or #5120 for those workloads, read dan-petty/homelab.

Follow-up: dan-petty/homelab#291.


Problem or Motivation

Today a pending service pod cannot preempt a runner Job after a node loss. The headroom absorbs a node loss today (memory use 18 to 30 %, CPU requests 13 to 43 %). But the runner CPU rows of #4719 (8-CPU Jobs) and #3064 (several implement Jobs at once) raise the batch requests. This item is rank 23 of the cluster integration plan #4989.

Proposed Solution & Architectural Design

  1. Add three PriorityClasses in git:
    • platform: cloudflared, Traefik, Argo CD, and the CNPG and cert-manager webhooks;
    • service: roadmap-service, llm-gateway, the Postgres clusters and Valkey;
    • batch: runner Jobs and rag-ingest, below the default, with preemptionPolicy: Never.
  2. The CEL policy roadmap-service-jobs must admit the batch class.
  3. The runner template sets priorityClassName.

Target Subsystem

Kubernetes & Minikube Automation (k8s/).

Existing Tool Considered

Kubernetes PriorityClass. Nothing is built.

Acceptance Criteria

  • Each workload above has its priority class in git.
  • The CEL policy admits a runner Job with the batch class and refuses one with the service class.

Dependencies

#4719 (runner CPU rows) and #3064 (several implement Jobs at once).

Source: #4989

Alternatives check of 2026-11-27: in-use.
The repository already uses this tool.
Tool: kubernetes/kubernetes (https://github.com/kubernetes/kubernetes), Apache-2.0, last activity 2026-11-27, maintained.
Reason: Searches found no separate priority or preemption tool; the need is met by the built-in Kubernetes PriorityClass API, which the issue already names as the tool in use. The work is manifests plus policy changes, not new tooling.

Covers:

  • PriorityClass objects with ordered values
  • preemptionPolicy Never keeps batch Jobs from displacing pods
  • priorityClassName on pod templates and WorkflowTemplate pods
  • Preemption of lower-priority batch pods by service pods

Lacks:

  • Admission policy rule admitting only the batch class
  • Manifests for platform, service and batch classes in the repo
  • Gate check that a wrong class fails

Proposed design

Problem statement

The CEL policy roadmap-service-jobs refuses a priorityClassName on a Job that the roadmap Service makes. A pending service pod cannot preempt a runner Job after a node loss. This change adds three PriorityClass objects under k8s/devops/, admits the batch class, sets the class on the governed Job templates, Deployment roadmap-service and WorkflowTemplate rag-ingest, and adds the gate checks for the order, the Never policy and a wrong class. The classes of the platform and stack workloads are the homelab follow-up dan-petty/homelab#291.

Acceptance criteria

Requirement: Three priority classes in the product base

The repository SHALL hold PriorityClass manifests platform, service and batch under k8s/devops/, with values ordered platform > service > 0 > batch.

Scenario: The k8s row accepts the class order

  • WHEN uv run devops ci --check --only k8s runs the k8s manifest check.
  • THEN The command exits 0.

Requirement: Batch never preempts

The batch PriorityClass MUST set preemptionPolicy: Never, so a runner Job never displaces another pod.

Scenario: The k8s row accepts the batch preemption policy

  • WHEN uv run devops ci --check --only k8s runs the k8s manifest check.
  • THEN The command exits 0.

Requirement: The policy admits the batch class

The CEL policy roadmap-service-jobs SHALL accept a Job whose pod template sets priorityClassName: batch.

Scenario: A runner Job with the batch class passes the admission check

  • WHEN uv run devops ci --check --only k8s runs the admission-policy check against the Job that CronJob devops-cli-runner makes.
  • THEN The command exits 0.

Requirement: The policy refuses every other class

The CEL policy roadmap-service-jobs MUST require priorityClassName: batch on each governed Job and refuse a Job that sets another class.

Scenario: A runner Job with the service class fails the admission check

  • WHEN uv run devops ci --check --only k8s runs the admission-policy check against a Job whose pod template sets priorityClassName: service.
  • THEN The command exits 0 and the check reports that the policy refused the Job.

Requirement: The governed Job templates set the batch class

Each governed CronJob in k8s/devops/ (devops-cli-runner, roadmap-stage and devops-cli-planner-run) MUST set priorityClassName: batch on its Job pod template.

Scenario: The k8s row accepts the three governed templates

  • WHEN uv run devops ci --check --only k8s runs the admission-policy check against the Jobs of the three governed CronJobs.
  • THEN The command exits 0.

Requirement: The roadmap Service takes the service class

Deployment roadmap-service under k8s/devops/ SHALL set priorityClassName: service on its pod template.

Scenario: The k8s row accepts the service class on the deployment

  • WHEN uv run devops ci --check --only k8s runs the k8s manifest check.
  • THEN The command exits 0.

Requirement: The rag-ingest Workflow takes the batch class

WorkflowTemplate rag-ingest in k8s/devops/ SHALL set the batch priority class on the pods that it makes.

Scenario: The k8s row accepts the batch class on the workflow template

  • WHEN uv run devops ci --check --only k8s runs the k8s manifest check.
  • THEN The command exits 0.

Existing Tool Considered

The alternatives check of 2026-11-27 records the verdict in-use for kubernetes/kubernetes (Apache-2.0, maintained), the built-in PriorityClass API. The check block in the issue body lists what the tool covers and lacks. This change adds what the block lacks: the three PriorityClass manifests under k8s/devops/, the batch admission in the CEL policy, priorityClassName: batch on the three governed Job templates and on WorkflowTemplate rag-ingest, priorityClassName: service on Deployment roadmap-service, and the gate check for a wrong class.

Key questions

  • Does the CEL policy roadmap-service-jobs admit a priorityClassName on a Job today?: No. The policy admits no priorityClassName on a governed Job. The change must add the batch class to its rule. [sources: k8s/devops/roadmap-service/admissionpolicy.yaml, docs/CLUSTER.md]
  • What runs the policy expressions before a merge?: The gate check tests/gate/k8s_checks/job_admission_policy.py runs them against the Jobs that the CronJobs of k8s/devops/ make. The k8s row of devops ci runs this check. [sources: tests/gate/k8s_checks/job_admission_policy.py, docs/CLUSTER.md]
  • Which Jobs does the policy roadmap-service-jobs govern, and which CronJobs of k8s/devops/ make them?: The policy governs the Jobs of CronJob devops-cli-runner, CronJob roadmap-stage and CronJob devops-cli-planner-run. Each of their pod templates must set priorityClassName: batch. [sources: k8s/devops/roadmap-service/admissionpolicy.yaml, k8s/devops/cronjob-runner.yaml, k8s/devops/cronjob-stage.yaml, k8s/devops/roadmap-service/cronjob-planner-run.yaml]
  • Which names and values do the three priority classes use?: Use platform at 1000000, service at 100000, and batch at -10. Set preemptionPolicy: Never on batch. Values above 1000000000 are reserved for Kubernetes system components. (best practice) [sources: docs/guidelines/kubernetes.md]
    • Chosen: platform 1000000, service 100000, batch -10. The order gives platform pods the first claim, service pods the second, and batch below the default priority 0.
    • Rejected: Three positive values with batch at 0. At 0 a runner Job is not below the default priority.
    • Rejected: Reuse system-cluster-critical and system-node-critical. Those values are reserved for Kubernetes system components and preempt every workload.
  • Must the policy require the batch class on a governed Job, or only permit it?: Require priorityClassName: batch on each Job that the policy governs. A Job with no class keeps the default priority 0, above batch. (best practice) [sources: k8s/devops/roadmap-service/admissionpolicy.yaml, tests/gate/k8s_checks/job_admission_policy.py]
    • Chosen: Require batch on each governed Job template. Every roadmap Job then carries one class. The gate check fails when a template loses the field.
    • Rejected: Permit batch and permit no class. A Job that loses the field keeps priority 0. It can displace a batch Job of another repository.
    • Rejected: Permit any class. A Job with the service or platform class can displace a service pod.
  • Where do the three PriorityClass manifests live?: Under k8s/devops/ in this repository, beside the admission policy that must admit the batch class. (best practice) [sources: docs/CLUSTER.md, k8s/README.md]
    • Chosen: k8s/devops/ in this repository. The policy that the classes must satisfy ships from this repository. The delivery is one pull request here.
    • Rejected: The environment tree of dan-petty/homelab. The environment tree holds no admission policy of this Service. A change there would need a second pull request in a second repository.
  • Should the classes of the platform and stack workloads ship in this item or in the homelab follow-up?: Ship them in the homelab follow-up dan-petty/homelab#291. This repository holds only the product base k8s/devops/. (best practice) [sources: docs/CLUSTER.md, CONTEXT.md]
    • Chosen: Defer to dan-petty/homelab#291. The environment tree is not in this repository, and the body names the homelab follow-up.
    • Rejected: Include every workload now. The change would touch two repositories.
  • Which check proves the class order, the Never policy and the wrong class?: The k8s row of devops ci runs the gate checks of tests/gate/k8s_checks/. The change extends job_admission_policy.py with a case for a Job that sets a class other than batch, and adds a check of the class order and of preemptionPolicy: Never. (best practice) [sources: tests/gate/k8s_checks/job_admission_policy.py, docs/CLUSTER.md]
    • Chosen: Extend the gate checks of tests/gate/k8s_checks/. The k8s row already runs these checks, so one row proves the manifests and the policy.
    • Rejected: A live check with kubectl after the apply. A live check needs a cluster. It proves nothing before the merge.
  • Which documents change with the policy?: docs/CLUSTER.md and the roadmap-implement-runner spec delta of the change. Both state the rule that the change replaces. (best practice) [sources: docs/CLUSTER.md, openspec/specs/roadmap-implement-runner/spec.md]
    • Chosen: docs/CLUSTER.md and the spec delta. Both state the rule that the change replaces. The merged tree keeps no stale rule.
    • Rejected: The spec delta only. docs/CLUSTER.md keeps the old rule and misleads the next reader.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#4719, #3064

Activity

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

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

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 7e1f8a8 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.

    The next refine round also looks at the item again when a commit on the default branch changes one of these files: k8s/devops/roadmap-service/admissionpolicy.yaml.

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

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 9cc974b 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.

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

    Tools considered:

    Searches run:

    • Kubernetes PriorityClass preemptionPolicy Never pod priority preemption, results: 5
    • pod priority and preemption priorityClass kubernetes docs, results: 5
    • kubernetes.io docs concepts scheduling-eviction pod-priority-preemption priorityClassName, results: 5

    Sources:

  8. devops-cli-service commented on Nov 26, 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.

  9. added
    status/ready
    and removed
    status/new
    on Dec 1, 2026
  10. devops-cli-service commented on Dec 1, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See 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/lowpriority/p2-mediumscope/k8ssource/agentstatus/readytype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions