Skip to content

fix(k8s): the Job policy resources rule passes CEL type checks #5548

Open

Description

@dan-petty

Problem Description

The ValidatingAdmissionPolicy roadmap-service-jobs (k8s/devops/roadmap-service/admissionpolicy.yaml) has a type-check warning on its resources rule. On 2026-11-13, after the sync of 28db551f6, the policy status shows typeChecking.expressionWarnings on spec.validations[18].expression with "undefined field 'requests'" and "undefined field 'limits'" at each c.resources.requests and c.resources.limits access. Before the sync, the same rule was at index 16 with the same warning.

The rule still works at run time. It applies to every Job that the Service account makes, with failurePolicy: Fail. A run-time error would refuse every runner Job, and the runner Job of 18:20Z was admitted. But the type checker cannot see the rule, so a later edit with a wrong field name would get no warning before it reaches the cluster.

Cause (to confirm)

The CEL type checker of the API server types containers[].resources from the Job OpenAPI schema. It does not find requests and limits as typed fields there, so it reports each access. The other rules of the policy type-check clean.

Proposed Fix

  • Write the rule so that the type checker accepts it. For example, test the keys with 'requests' in c.resources and 'cpu' in c.resources.requests in place of field access, or use the form of the CEL examples in the Kubernetes documentation for resource maps.
  • Keep the same allowed values and the same message.
  • Add a check that fails when the live policy, or a server dry run of the manifest, reports typeChecking.expressionWarnings.

Acceptance Criteria

  • After the sync, kubectl get validatingadmissionpolicy roadmap-service-jobs -o jsonpath='{.status.typeChecking}' is empty.
  • The existing policy tests (tests/gate/k8s_checks/job_admission_policy.py) pass with the same allowed and refused Job cases.
  • A test or check refuses a policy manifest whose status has expression warnings.

Alternatives check of 2026-11-23: none.
Tool: none found.
Reason: Searches for a CEL type checker or a ValidatingAdmissionPolicy status checker found only schema validators such as kubeconform, which validates OpenAPI schemas and leaves CEL type checks to the API server, so nothing covers the rewrite or the status guard.

Lacks:

  • No CEL type check against the Job OpenAPI schema
  • No check of status.typeChecking.expressionWarnings
  • No rewrite of the resources rule; an in-repo edit
  • Offline manifest checks leave server-side validation to kubectl dry-run

Proposed design

Problem statement

The roadmap-service-jobs ValidatingAdmissionPolicy reports CEL type-check warnings on its resource rule. The rule works at run time, but the API server cannot warn about a wrong resource field before the Job reaches the cluster. The change rewrites the rule with map membership checks and adds a live check that fails on status.typeChecking.expressionWarnings.

Acceptance criteria

Requirement: Resources rule type-checks clean

The roadmap-service-jobs policy SHALL report no CEL type-check warnings after the change.

Scenario: Live policy has no expression warnings

  • WHEN After the sync, run kubectl get validatingadmissionpolicy roadmap-service-jobs -o jsonpath='{.status.typeChecking.expressionWarnings}'.
  • THEN The command prints an empty string.

Requirement: Job admission behavior is unchanged

The policy MUST accept and refuse the same Job cases with the same messages as before the change.

Scenario: Existing gate test passes

  • WHEN Run uv run pytest tests/gate/k8s_checks/job_admission_policy.py.
  • THEN The command exits 0.

Requirement: Check fails on expression warnings

The admission policy check MUST exit non-zero when the policy status holds a non-empty typeChecking.expressionWarnings.

Scenario: Warning list makes the check fail

  • WHEN Run uv run pytest tests/commands/k8s/test_k8s_admission_policy_check.py with a mocked non-empty warning list.
  • THEN The test passes and the check exits non-zero.

Requirement: Check passes on a clean policy

The admission policy check MUST exit zero when the policy status holds no expression warnings.

Scenario: Empty warning list makes the check pass

  • WHEN Run uv run pytest tests/commands/k8s/test_k8s_admission_policy_check.py with a mocked empty warning list.
  • THEN The test passes and the check exits zero.

Existing Tool Considered

The alternatives check of 2026-11-17 in the issue body gives verdict none and names no tool. No open, maintained tool covers this need. The change keeps the in-repo CEL gate test and adds a small live check. Written cost: about 20k tokens to build, about 3k tokens per later policy change to keep and fix, and about 1 day elapsed.

Key questions

  • Which CEL form makes the resources rule pass the API server type check?: Use the Kubernetes CEL map form. Test each map key with in, such as 'requests' in c.resources and 'cpu' in c.resources.requests. Keep the value comparisons and the message. (best practice) [sources: k8s/devops/roadmap-service/admissionpolicy.yaml]
    • Chosen: Map membership with in. Kubernetes CEL uses in for map keys, and it avoids the has() field check that the type checker reports.
    • Rejected: Keep has() on map entries. The live policy reports undefined field 'requests' and undefined field 'limits' on this form.
    • Rejected: Bracket access only. It does not remove the need to test map keys and is less readable.
  • Where should the new check that fails on expression warnings live?: Add a live check command uv run devops k8s admission-policy-check and unit tests for it. The command reads the policy status with kubectl and exits non-zero on a non-empty status.typeChecking.expressionWarnings. (best practice) [sources: tests/commands/k8s/test_k8s_searxng_check.py, tests/gate/k8s_checks/job_admission_policy.py]
    • Chosen: Live check command devops k8s admission-policy-check. It matches the existing devops k8s *-check live checks and can run where a cluster is available.
    • Rejected: Extend the offline gate test. The gate test has no cluster and cannot read the live policy status.
    • Rejected: Manual kubectl get only. It does not fail an automated check.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

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

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 13, 2026
  4. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor

    Runtime check on 2026-11-13 at 21:00 UTC, after the sync of #5545 (v0.132.0): the warning of spec.validations[18] (undefined field 'requests' and 'limits') is in status.typeChecking of roadmap-service-jobs. The rule had the same has(c.resources.requests) form before #5545, so the stage branch did not cause it.

    The API server still evaluates the rule at runtime. A server dry-run as the Service (kubectl --as=system:serviceaccount:devops:roadmap-service -n devops create --dry-run=server) of a stage Job that build_job makes from the live CronJob roadmap-stage was admitted. The same Job with the args config show, and with an extra plain variable DEVOPS_CLI_AI_BASE_URL, was refused by the policy.

  5. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: Searches found only general manifest validators such as kubectl-validate and policy engines such as Kyverno; neither type-checks ValidatingAdmissionPolicy CEL against the Job schema nor fails a check on status.typeChecking expression warnings.

    Tool: none found

    Lacks:

    • Type-check of the policy CEL against the Job OpenAPI schema
    • Failure when status.typeChecking holds expressionWarnings
    • Same allowed and refused Job cases as the existing gate test
    Searches (10)

    Tools considered:

    Searches run:

    • tool validate ValidatingAdmissionPolicy CEL expression type check locally CI, results: 5
    • Kubernetes ValidatingAdmissionPolicy CEL type checking expressionWarnings undefined field requests limits, results: 5
    • cel-policy-tools kubernetes validating admission policy lint cel expression, results: 5
    • kubectl-validate validating admission policy CEL expressions locally, results: 5
    • kubectl-validate github kubernetes-sigs, results: 5
    • CEL expression resources requests limits quantity Kubernetes admission policy example, results: 5
    • kubeconform validate Kubernetes manifests offline, results: 5
    • kubernetes cel-go validation library type checking expressions, results: 5
    • kyverno, results: 5
    • kubectl-validate, results: 5

    Sources:

    A person decides what this check of 2026-11-17 means for the item.

  6. added
    status/ready
    and removed
    status/new
    on Nov 18, 2026
  7. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 86358b6 (see proposed design in issue 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/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions