Skip to content

feat(roadmap): label Service Jobs by repository and item #4558

Closed

Description

@dan-petty

Problem or Motivation

The runner Job of implement carries the label implement-repo with a hash value and the name app.kubernetes.io/name: devops-cli-job. A person cannot list the Jobs of one repository or one item with kubectl. The pods carry no repository annotation, so Loki cannot label the logs of a Job pod by repository.

The stage Job and the Workflows of the move need the same labels from the start, so that no later rename is needed. A rename of the selector key has no safe rollout: Image Updater rolls the Service about 15 times a day, runner Jobs run about 6 times a day, and a new Service that lists by a new key does not see a running Job for up to the 4-hour deadline. It could then start a second implement Job for the same repository.

Proposed Solution & Architectural Design

Use the rules of the naming ADR and the builders of RepoRef:

  • src/devops_cli/k8s/cluster_job.py: build_job adds the labels roadmap.devops-cli/owner, roadmap.devops-cli/repo, roadmap.devops-cli/item, app.kubernetes.io/component: roadmap-<row>, app.kubernetes.io/part-of: devops-cli-stack, app.kubernetes.io/managed-by, and the annotation roadmap.devops-cli/repository (the casefolded key) on the Job and on the pod template. repository_label and job_name move into RepoRef (no shim).
  • The runner Job gets the ad hoc name devops-cli-implement-<slug>-<item>-<6 hex>. A unit Job gets the unit name.
  • The label implement-repo keeps its key and value. It goes away only when no code lists by it (with feat(roadmap): Run implement as Argo Workflow with per-group resubmit #3105).
  • app.kubernetes.io/name: devops-cli-job does not change, so the NetworkPolicies and the admission policy apply as before.
  • k8s/devops/cronjob-runner.yaml: OTEL_SERVICE_NAME=roadmap-implement. Change the two dashboard descriptions that name devops-cli-job.
  • Also change src/devops_cli/roadmap/implement/implement_submit.py and src/devops_cli/commands/k8s/cluster_jobs.py.
  • Coordinate with feat(roadmap): add the three-container runner Job, policy and log reads #3700 (two-container runner Job), which changes the same template.

Target Subsystem

Kubernetes & Minikube Automation (src/devops_cli/k8s/cluster_job.py, k8s/devops/).

Existing Tool Considered

Kubernetes labels and annotations and kube-state-metrics (it exports all pod labels). No build beyond the label code. Cost: about 250,000 tokens and 2.5 hours to build, about 5,000 tokens a month to keep, about 30,000 tokens to fix.

Acceptance Criteria

  • A new runner Job is named devops-cli-implement-<slug>-<item>-<6 hex>, with 63 characters or fewer.
  • kubectl -n devops get jobs -l roadmap.devops-cli/repo=<name>,roadmap.devops-cli/item=<n> lists it, and its pod carries the same labels and the annotation.
  • The Service still finds a running Job that an older image made: a test lists a Job with only the old labels.
  • The NetworkPolicy and admission policy tests pass.
  • --dry-run shows the Job name and makes no request.

Dependencies

  • "feat(roadmap): name each repository's resources from one RepoRef".

Source: #4517

Proposed design

Problem statement

A runner Job carries only the hashed label implement-repo and the generic name devops-cli-job. A person cannot list the Jobs of one repository or one item with kubectl. Loki cannot label the log stream of a Job pod by repository. The new labels must land before the Service and the Workflows rely on them, because a later rename of the selector key has no safe rollout.

Acceptance criteria

Requirement: Repository and item labels

build_job SHALL set roadmap.devops-cli/owner, roadmap.devops-cli/repo and roadmap.devops-cli/item on the Job metadata and on the pod template metadata.

Scenario: Labels on the Job and on its pod

  • WHEN build_job builds a runner Job for repository Dan-Petty/DevOps-CLI and item 4558
  • THEN both metadata blocks hold roadmap.devops-cli/owner: dan-petty, roadmap.devops-cli/repo: devops-cli and roadmap.devops-cli/item: 4558.

Requirement: Repository annotation on the pod

build_job SHALL set the annotation roadmap.devops-cli/repository to the casefolded owner/name on the Job and on the pod template.

Scenario: The annotation reaches the pod

  • WHEN build_job builds a Job for Dan-Petty/DevOps-CLI
  • THEN the Job metadata and the pod template metadata hold the annotation roadmap.devops-cli/repository: dan-petty/devops-cli.

Requirement: Component and ownership labels

build_job SHALL set app.kubernetes.io/component: roadmap-<row>, app.kubernetes.io/part-of: devops-cli-stack and app.kubernetes.io/managed-by: devops-cli on the Job and on the pod template.

Scenario: The component of the runner Job

  • WHEN the Service builds a runner Job for the implement row
  • THEN both metadata blocks hold app.kubernetes.io/component: roadmap-implement and app.kubernetes.io/part-of: devops-cli-stack.

Requirement: Runner Job name

The runner Job of the Service SHALL be named devops-cli-implement-<slug>-<item>-<6 hex> and MUST hold 63 characters or fewer.

Scenario: A long slug is cut

  • WHEN the slug and the item number make the name longer than 63 characters
  • THEN the name holds 63 characters, keeps the -<6 hex> suffix, and matches the DNS-1123 subdomain form.

Requirement: Old repository label stays

The runner Job MUST keep the label implement-repo with its digest value, and the Service MUST keep listing runner Jobs by it.

Scenario: A Job of an older image is found

  • WHEN the Service lists the Jobs of a repository and one carries only implement-repo: <digest>
  • THEN the round counts that Job as running for the repository and creates no second runner Job.

Requirement: Name label for the policies

Every Service Job MUST keep the label app.kubernetes.io/name: devops-cli-job on the Job and on the pod template.

Scenario: The policies still select the pod

  • WHEN the MCP NetworkPolicy tests and the admission policy tests run against a Job built for item 4558
  • THEN the tests pass and the pod label set holds app.kubernetes.io/name: devops-cli-job.

Requirement: Dry run shows the Job

devops k8s run-job --template runner --dry-run MUST show the Job name and the repository labels and MUST send no request.

Scenario: The dry run of a runner Job

  • WHEN a person runs the command with --repo dan-petty/devops-cli -- true
  • THEN the printed plan holds the Job name placeholder and the roadmap.devops-cli/* labels, and no kubectl command runs.

Requirement: Runner telemetry service name

The runner CronJob MUST set OTEL_SERVICE_NAME to roadmap-implement, and the two dashboards that name devops-cli-job MUST name roadmap-implement.

Scenario: The runner reports under its own service name

  • WHEN the runner CronJob is read from k8s/devops/cronjob-runner.yaml
  • THEN its runner container holds OTEL_SERVICE_NAME with the value roadmap-implement.

Existing Tool Considered

No alternatives check has run. Kubernetes labels and annotations, with kube-state-metrics, cover the need: kube-state-metrics exports every Job and pod label, so the change needs no exporter of its own. The code to build is the label code in build_job only. The written cost is about 250,000 tokens and 2.5 hours to build, about 5,000 tokens a month to keep, and about 30,000 tokens to fix.

Key questions

  • Which value does the label roadmap.devops-cli/repo hold?: The casefolded repository name, as devops-cli. The annotation roadmap.devops-cli/repository holds the casefolded full key, as dan-petty/devops-cli. (best practice) [sources: src/devops_cli/k8s/cluster_job.py]
    • Rejected: the full owner/name key. A Kubernetes label value cannot hold /, so the API refuses the Job.
    • Chosen: the casefolded repository name. It is a valid label value, a person can read it, and the annotation holds the full key.
    • Rejected: the 16-hex digest. A person cannot read the repository from it, which is the problem this item solves.
  • Do the new labels and the new annotation go on the pod template as well as on the Job?: Yes. _labelled already copies the labels to the Job and to the pod template, and the change gives the pod template the annotation too. (best practice) [sources: src/devops_cli/k8s/cluster_job.py, k8s/devops/mcp-server/networkpolicy-client.yaml]
    • Rejected: Job metadata only. Loki cannot label the log stream of the pod by repository, which is the need.
    • Chosen: Job and pod template. The pod carries the labels and the annotation, so kubectl and Loki both read them.
  • Which value does app.kubernetes.io/managed-by hold?: devops-cli. The tool that creates the Job is the manager, and the value names the tool. (best practice) [sources: k8s/devops/cronjob-runner.yaml]
    • Chosen: devops-cli. The recommended label names the tool that manages the object, and devops-cli creates the Job.
    • Rejected: the roadmap row. The row names the component, and the component label already holds it.
  • How does the Service find a running Job while the runner image rolls out?: The Service keeps the label implement-repo with its key and value, and lists by it. The new labels are additive. The old label goes away with feat(roadmap): Run implement as Argo Workflow with per-group resubmit #3105, in one step. (best practice) [sources: src/devops_cli/roadmap/implement/implement_submit.py, src/devops_cli/commands/k8s/cluster_jobs.py]
  • Where do repository_label and job_name live after this change?: They stay in src/devops_cli/k8s/cluster_job.py at this commit, and one label builder calls them. The repository holds no RepoRef now, so the move into RepoRef happens in the issue feat(roadmap): name each repository's resources from one RepoRef, with no shim and no second copy. (best practice) [sources: src/devops_cli/k8s/cluster_job.py, src/devops_cli/roadmap/implement/implement_submit.py]
    • Rejected: move the two builders into RepoRef now. RepoRef does not exist at this commit, so the change would carry a partial class and a second copy.
    • Chosen: keep the two builders and call them from the new label builder. It changes one place, and the RepoRef issue moves the two functions without a shim.
  • What name does a Job get that is not a runner Job?: A Job of the devops-cli template keeps <cronjob>-<yyyymmdd-hhmmss>-<4 hex>. No repository item identifies such a Job, so it takes no item name. The RepoRef issue gives the unit name. (best practice) [sources: src/devops_cli/k8s/cluster_job.py, src/devops_cli/commands/k8s/cluster_jobs.py]
    • Chosen: keep the template name and the timestamp. No item and no repository identify such a Job, and no selector lists it.
    • Rejected: give every Job the item name. A Job of the devops-cli template serves no repository item.
  • How does a name longer than 63 characters keep a valid form?: The builder cuts the slug and keeps the -<item>-<6 hex> tail. The result holds 63 characters or fewer and stays a DNS-1123 subdomain. (best practice) [sources: src/devops_cli/k8s/cluster_job.py]
    • Chosen: cut the slug and keep the hex suffix. The tail names the item, and the hex suffix keeps the name unique.
    • Rejected: let the API refuse a long name. The Service would create no Job for a repository with a long name.
  • Which callers and tests must change with build_job?: The callers are src/devops_cli/commands/k8s/cluster_jobs.py, src/devops_cli/k8s/cluster_job_api.py and src/devops_cli/roadmap/implement/implement_submit.py. The tests are tests/commands/k8s/test_k8s_run_job.py, tests/gate/k8s_checks/job_admission_policy.py, tests/invariants/test_k8s_mcp_server_policies.py, tests/commands/test_ci.py and tests/invariants/test_architectural_invariants.py. [sources: src/devops_cli/commands/k8s/cluster_jobs.py, src/devops_cli/k8s/cluster_job_api.py, src/devops_cli/roadmap/implement/implement_submit.py, tests/commands/k8s/test_k8s_run_job.py, tests/gate/k8s_checks/job_admission_policy.py, tests/invariants/test_k8s_mcp_server_policies.py, tests/commands/test_ci.py, tests/invariants/test_architectural_invariants.py]
  • Which policies select a Job pod by its labels?: The MCP NetworkPolicies select the pods with app.kubernetes.io/name: devops-cli-job. The admission policy roadmap-service-jobs refuses valueFrom in a Job of the Service. The label app.kubernetes.io/name: devops-cli-job does not change. [sources: k8s/devops/mcp-server/networkpolicy.yaml, k8s/devops/mcp-server/networkpolicy-client.yaml, k8s/devops/cronjob-runner.yaml]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-12: none.
Tool: none found.

Owner decision 2026-11-13

The approved pipeline split (tracker #5482) moves this item to Phase 0, because the stall rule (#5495) finds the running units of an item by these labels. Its scope does not change.

  • Live proof: after the merge and the release, kubectl get jobs -l with the repository and item labels lists the Jobs of one live item that the App started. A comment gives the command and the Job names.

Activity

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

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. It improves operational visibility but blocks no workflow and has no security impact.
    • Value: Medium. A person can list and filter Jobs by repository and item, which aids debugging and log correlation.
    • Effort: Medium. It changes build_job, RepoRef, the cronjob manifest, two other source files, and requires coordination with issue #3700.
    • Related: fix(k8s): MCP server policies miss the Service runner Jobs #4355, which asks for a different change. Both touch the pod labels in cluster_job.py and the devops-cli-job label, but #4355 fixes NetworkPolicy selection while the candidate adds repository and item labels for kubectl listing.
  4. added
    priority/p2-medium
    on Nov 11, 2026
  5. added
    status/ready
    and removed
    status/new
    on Nov 11, 2026
  6. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 5f75d25 (see proposed design in issue body).

  7. devops-cli-service commented on Nov 12, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: The searches found only tools that read or copy labels that must already exist: kube-state-metrics generates metrics from Kubernetes objects "without modification", Kyverno mutates labels/annotations only from data a Job or pod already carries, and python-slugify only makes the slug fragment of a name. None of them builds the roadmap.devops-cli/* labels and annotation on the Job and its pod template, the 63-character runner Job name, or the --dry-run output, so the change stays in the project's own build_job code, whose naming rules ADR 0022 already fixes.

    Tool: none found

    Tools considered:

    Searches run:

    • OpenTelemetry Collector k8sattributes processor pod labels Loki log labels, results: 5
    • kube-state-metrics export Kubernetes Job and pod labels for querying, results: 5
    • Kyverno mutating policy add labels and annotations to Jobs and pods from existing fields, results: 5
    • kube-state-metrics github repository kubernetes metrics, results: 5
    • kyverno mutate rule add label to pod from annotation, results: 5
    • kubernetes labels annotations naming convention library python slugify resource name 63 characters, results: 5
    • "kube-state-metrics", results: 5
    • "python-slugify" pypi slug generation, results: 5
    • kubernetes controller copies pod annotations to labels automatically, results: 5
    • kube_job_labels kube_pod_labels exposed metrics, results: 5

    Sources:

    Checked on 2026-11-12. A person decides what this means for the item. The check changes no label and closes no issue.

  8. added
    owner/agent
    status/in-progress
    and removed
    status/ready
    on Nov 14, 2026
  9. added a commit that references this issue on Nov 14, 2026
    cdd043a
  10. added
    status/in-review
    and removed
    status/in-progress
    on Nov 14, 2026
  11. removed
    status/in-review
    owner/agent
    on Nov 14, 2026
  12. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-14 22:29 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/roadmapsource/agenttype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions