← Back to Pull requests

DRA template policy #817

Closed
unknown closed this pull request without merging on Oct 02, 2026 09:04 UTC
View on GitHub
unknown unknown commented on Sep 24, 2026 13:54 UTC
Author

DRA template policy

The first policy that allocates claims

Fourth PR of the DRA series, on top of #806. Until now every backend answered
AllocateClaim with policy.ErrNoDRAClaims. Here the template policy gets a
real implementation, so a claim can be prepared end to end on a cluster for the
first time. Template is the file people copy when they write a policy, so every
choice below is the simplest one that still works.

Four commits, in order: the policy, its DeviceClass and docs, feature
gate support
in the e2e harness, and an e2e test that runs the whole path.

One device, consumable capacity

Template publishes one device, cpus, with allowMultipleAllocations and a
dra.cpu/cpu capacity equal to the number of CPUs it is allowed to hand out
(KEP-5075). The allowed CPUs are availableResources.cpu if that is a cpuset,
else all online CPUs, minus reservedResources.cpu if that is a cpuset. The
published value is the device's total: the scheduler subtracts each claim's
ConsumedCapacity itself, so the slice never changes while the plugin runs.

The device is pushed through PublishDRADevices (#803) once, from Start. A
CPU configuration DRA cannot use, available CPUs given as a quantity for
instance, only logs a warning and publishes no devices: failing Start would
also stop template for everyone running it with DRA off, and with no devices
there are no claims to fail on it.

The request policy is Default: 1 with ValidRange{Min: 1, Step: 1}. A claim
naming no amount therefore takes one CPU, not the whole device (the upstream
default), and requests are rounded to whole CPUs.

Reconfigure refuses any change to the available or reserved CPUs, whether or
not claims exist. Template ignored those fields until now, so nothing is lost,
and it means the published device never has to be republished.

Allocation

Per result, AllocateClaim takes as many CPUs as the result consumed, lowest ID
first, from the allowed CPUs no other claim holds. A real policy would pick by
topology; the code says so. The state is one cpuset per claim UID, kept in the
policy's own cache entry. Free CPUs are computed from it on demand, so release
is a delete and there is no second set to keep in sync.

  • A claim already known returns the same edits, because the kubelet prepares a

  • claim again for every pod that uses it.
  • A missing, zero or fractional amount is rejected. That one check also rejects

  • a result for somebody else's device, which carries no dra.cpu/cpu entry.
  • The grant is DRA_CPUSET_<claim UID>=<cpuset>, one variable per claim with

  • all of its CPUs. Every result's edit sets the same value, so it does not
    matter that CDI keeps only one of them.

    Template manages no cpusets, so it neither pins a claim's containers to their
    CPUs nor keeps other containers off them. The code and the docs say so. A policy
    that does manage cpusets has to exclude claimed CPUs from what it hands out.

    Names and the DeviceClass

    The capacity name dra.cpu/cpu is fully qualified, so a result carries
    exactly that string and the lookup is one map key. A QualifiedName without a domain would not
    match its qualified form as a map key (see kubernetes/kubernetes#142202).

    The chart gains a template.nri.io DeviceClass under config.dra.enabled.

    Claims survive a plugin restart

    The claims are kept in the policy's claims cache entry and read back in
    Start, so a restarted plugin still knows which CPUs are taken. Since #818,
    resmgr clears policy data only when the policy changes, and each policy resets
    its own entries in Setup. Template is the first policy that does not: it
    rebuilds nothing from running containers, and a claim may have no container at
    all yet, so what it saved is all it has.

    An entry a policy keeps across restarts has to stay readable: GetPolicyEntry
    treats an entry it cannot decode as fatal. The claims are a
    map[string]cpuset.CPUSet, so changing that type means a new cache key.

    Both the unit tests and the e2e test check this, and both fail with the reset
    put back in Setup.

    e2e: feature gates and a template suite

    The harness learns k8s_feature_gates="Gate1=true,Gate2=false". provision.yaml
    turns it into a kubeadm config that sets the gates on the API server, the
    scheduler and the kubelet. Unset keeps today's plain kubeadm init. vm_name
    can now be set by the caller, so a gated and an ungated VM do not share a
    directory.

    policies.test-suite/template/n4c16/test01-dra runs with available CPUs
    cpuset:4-7, so two 2-CPU claims use up the device. It checks that:

  • one device is published, with a capacity of 4;

  • the first two pods get CPUs 4-5 and 6-7, as seen in their environment;

  • a third pod stays unscheduled until one of them is deleted, then gets 4-5;

  • after a plugin restart, deleting the pod with 6-7 gives a fourth pod 6-7,

  • not the 4-5 the third pod still holds.

    The test skips when allowMultipleAllocations is missing from the published
    device, which is what the API server does without DRAConsumableCapacity.
    Running template in the harness also needed a deploy playbook and a template
    entry in the per-plugin cases of helm-launch, config-resource and
    plugin-daemonset.

    e2e does not run in CI. To run it:

    cd test/e2e
    k8s_feature_gates="DRAConsumableCapacity=true" \
        ./run_tests.sh policies.test-suite/template/n4c16/test01-dra
    

    Testing

  • go test ./... passes, and golangci-lint finds no issues.

  • The policy tests cover publishing for a configured and a default cpuset, a

  • partial claim, disjoint claims, exhaustion, several results in one claim, an
    idempotent re-prepare, a missing, zero or fractional amount, a capacity name
    other than dra.cpu/cpu, release of known and unknown claims, restore of
    saved claims, and the reconfigure refusal.
  • helm template and helm lint pass with DRA enabled and disabled.

  • The e2e test ran on Kubernetes 1.37.1, on the stack rebased onto #818 and the

  • device push of #803: PASS with DRAConsumableCapacity=true, SKIP with
    DRAConsumableCapacity=false. An earlier revision also passed with no gates
    set, since DRAConsumableCapacity is on by default there. The restart check
    came after these runs: it passes gated, and fails with the reset put back
    in Setup. After the switch to the dra.cpu/cpu and DRA_CPUSET_ names
    it passed again gated.
  • The gated VM had the gate on the API server, the scheduler and the kubelet;

  • the ungated one provisioned with the plain kubeadm init.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: klihub Review duration: 11229m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #817"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%